]>
Commit | Line | Data |
---|---|---|
1 | /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-* | |
2 | * | |
3 | * Copyright (c) 2009 Apple Inc. All rights reserved. | |
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 | ||
49 | namespace ld { | |
50 | namespace tool { | |
51 | ||
52 | class InputFiles : public ld::dylib::File::DylibHandler | |
53 | { | |
54 | public: | |
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 | |
63 | bool searchLibraries(const char* name, bool searchDylibs, bool searchArchives, ld::File::AtomHandler&) const; | |
64 | // see if any linked dylibs export a weak def of symbol | |
65 | bool searchWeakDefInDylib(const char* name) const; | |
66 | // copy dylibs to link with in command line order | |
67 | void dylibs(ld::Internal& state); | |
68 | ||
69 | bool inferredArch() const { return _inferredArch; } | |
70 | ||
71 | uint32_t nextInputOrdinal() const { return _nextInputOrdinal++; } | |
72 | ||
73 | // for -print_statistics | |
74 | uint64_t _totalObjectSize; | |
75 | uint64_t _totalArchiveSize; | |
76 | uint32_t _totalObjectLoaded; | |
77 | uint32_t _totalArchivesLoaded; | |
78 | uint32_t _totalDylibsLoaded; | |
79 | ||
80 | ||
81 | private: | |
82 | void inferArchitecture(Options& opts, const char** archName); | |
83 | const char* fileArch(const uint8_t* p, unsigned len); | |
84 | ld::File* makeFile(const Options::FileInfo& info); | |
85 | ld::File* addDylib(ld::dylib::File* f, const Options::FileInfo& info, uint64_t mappedLen); | |
86 | ld::File* addObject(ld::relocatable::File* f, const Options::FileInfo& info, uint64_t mappedLen); | |
87 | ld::File* addArchive(ld::File* f, const Options::FileInfo& info, uint64_t mappedLen); | |
88 | void logTraceInfo (const char* format, ...) const; | |
89 | void logDylib(ld::File*, bool indirect); | |
90 | void logArchive(ld::File*) const; | |
91 | void createIndirectDylibs(); | |
92 | void checkDylibClientRestrictions(ld::dylib::File*); | |
93 | void createOpaqueFileSections(); | |
94 | ||
95 | class CStringEquals { | |
96 | public: | |
97 | bool operator()(const char* left, const char* right) const { return (strcmp(left, right) == 0); } | |
98 | }; | |
99 | typedef __gnu_cxx::hash_map<const char*, ld::dylib::File*, __gnu_cxx::hash<const char*>, CStringEquals> InstallNameToDylib; | |
100 | ||
101 | const Options& _options; | |
102 | std::vector<ld::File*> _inputFiles; | |
103 | mutable std::set<class ld::File*> _archiveFilesLogged; | |
104 | InstallNameToDylib _installPathToDylibs; | |
105 | std::set<ld::dylib::File*> _allDylibs; | |
106 | ld::dylib::File* _bundleLoader; | |
107 | mutable uint32_t _nextInputOrdinal; | |
108 | bool _allDirectDylibsLoaded; | |
109 | bool _inferredArch; | |
110 | }; | |
111 | ||
112 | } // namespace tool | |
113 | } // namespace ld | |
114 | ||
115 | #endif // __INPUT_FILES_H__ |