]> git.saurik.com Git - apple/ld64.git/blame - src/ld/InputFiles.h
ld64-128.2.tar.gz
[apple/ld64.git] / src / ld / InputFiles.h
CommitLineData
a645023d
A
1/* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-*
2 *
afe874b1 3 * Copyright (c) 2009-2011 Apple Inc. All rights reserved.
a645023d
A
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
12 * file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25#ifndef __INPUT_FILES_H__
26#define __INPUT_FILES_H__
27
28#include <stdlib.h>
29#include <sys/types.h>
30#include <sys/stat.h>
31#include <sys/mman.h>
32#include <sys/sysctl.h>
33#include <fcntl.h>
34#include <errno.h>
35#include <limits.h>
36#include <unistd.h>
37#include <mach/mach_time.h>
38#include <mach/vm_statistics.h>
39#include <mach/mach_init.h>
40#include <mach/mach_host.h>
41#include <dlfcn.h>
42#include <mach-o/dyld.h>
43
44#include <vector>
45
46#include "Options.h"
47#include "ld.hpp"
48
49namespace ld {
50namespace tool {
51
52class InputFiles : public ld::dylib::File::DylibHandler
53{
54public:
55 InputFiles(Options& opts, const char** archName);
56
57 // implementation from ld::dylib::File::DylibHandler
58 virtual ld::dylib::File* findDylib(const char* installPath, const char* fromPath);
59
60 // iterates all atoms in initial files
61 bool forEachInitialAtom(ld::File::AtomHandler&) const;
62 // searches libraries for name
afe874b1
A
63 bool searchLibraries(const char* name, bool searchDylibs, bool searchArchives,
64 bool dataSymbolOnly, ld::File::AtomHandler&) const;
a645023d
A
65 // see if any linked dylibs export a weak def of symbol
66 bool searchWeakDefInDylib(const char* name) const;
67 // copy dylibs to link with in command line order
68 void dylibs(ld::Internal& state);
69
70 bool inferredArch() const { return _inferredArch; }
71
72 uint32_t nextInputOrdinal() const { return _nextInputOrdinal++; }
73
74 // for -print_statistics
75 uint64_t _totalObjectSize;
76 uint64_t _totalArchiveSize;
77 uint32_t _totalObjectLoaded;
78 uint32_t _totalArchivesLoaded;
79 uint32_t _totalDylibsLoaded;
80
81
82private:
83 void inferArchitecture(Options& opts, const char** archName);
84 const char* fileArch(const uint8_t* p, unsigned len);
afe874b1 85 ld::File* makeFile(const Options::FileInfo& info, bool indirectDylib);
a645023d
A
86 ld::File* addDylib(ld::dylib::File* f, const Options::FileInfo& info, uint64_t mappedLen);
87 ld::File* addObject(ld::relocatable::File* f, const Options::FileInfo& info, uint64_t mappedLen);
88 ld::File* addArchive(ld::File* f, const Options::FileInfo& info, uint64_t mappedLen);
89 void logTraceInfo (const char* format, ...) const;
90 void logDylib(ld::File*, bool indirect);
91 void logArchive(ld::File*) const;
92 void createIndirectDylibs();
93 void checkDylibClientRestrictions(ld::dylib::File*);
94 void createOpaqueFileSections();
95
96 class CStringEquals {
97 public:
98 bool operator()(const char* left, const char* right) const { return (strcmp(left, right) == 0); }
99 };
100 typedef __gnu_cxx::hash_map<const char*, ld::dylib::File*, __gnu_cxx::hash<const char*>, CStringEquals> InstallNameToDylib;
101
102 const Options& _options;
103 std::vector<ld::File*> _inputFiles;
104 mutable std::set<class ld::File*> _archiveFilesLogged;
105 InstallNameToDylib _installPathToDylibs;
106 std::set<ld::dylib::File*> _allDylibs;
107 ld::dylib::File* _bundleLoader;
108 mutable uint32_t _nextInputOrdinal;
109 bool _allDirectDylibsLoaded;
110 bool _inferredArch;
111};
112
113} // namespace tool
114} // namespace ld
115
116#endif // __INPUT_FILES_H__