]>
Commit | Line | Data |
---|---|---|
a645023d A |
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 __RESOLVER_H__ | |
26 | #define __RESOLVER_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 | #include "SymbolTable.h" | |
49 | ||
50 | ||
51 | namespace ld { | |
52 | namespace tool { | |
53 | ||
54 | ||
55 | ||
56 | ||
57 | class Resolver : public ld::File::AtomHandler | |
58 | { | |
59 | public: | |
ebf6f434 | 60 | Resolver(const Options& opts, InputFiles& inputs, ld::Internal& state) |
a645023d A |
61 | : _options(opts), _inputFiles(inputs), _internal(state), |
62 | _symbolTable(opts, state.indirectBindingTable), | |
ebf6f434 | 63 | _haveLLVMObjs(false), |
a645023d A |
64 | _completedInitialObjectFiles(false) {} |
65 | ||
66 | ||
67 | virtual void doAtom(const ld::Atom&); | |
68 | virtual void doFile(const class File&); | |
69 | ||
70 | void resolve(); | |
71 | ||
72 | ||
73 | private: | |
74 | struct WhyLiveBackChain | |
75 | { | |
76 | WhyLiveBackChain* previous; | |
77 | const ld::Atom* referer; | |
78 | }; | |
79 | ||
80 | void initializeState(); | |
81 | void buildAtomList(); | |
82 | void addInitialUndefines(); | |
b1f7435d | 83 | void deadStripOptimize(bool force=false); |
a645023d A |
84 | void resolveUndefines(); |
85 | void checkUndefines(bool force=false); | |
86 | void checkDylibSymbolCollisions(); | |
87 | void tentativeOverrideOfDylib(ld::Atom&); | |
88 | void fillInInternalState(); | |
89 | void fillInHelpersInInternalState(); | |
90 | void removeCoalescedAwayAtoms(); | |
b1f7435d | 91 | void fillInEntryPoint(); |
a645023d A |
92 | void linkTimeOptimize(); |
93 | void convertReferencesToIndirect(const ld::Atom& atom); | |
94 | const ld::Atom* entryPoint(bool searchArchives); | |
95 | void markLive(const ld::Atom& atom, WhyLiveBackChain* previous); | |
96 | bool isDtraceProbe(ld::Fixup::Kind kind); | |
97 | void liveUndefines(std::vector<const char*>&); | |
ebf6f434 | 98 | void remainingUndefines(std::vector<const char*>&); |
a645023d | 99 | bool printReferencedBy(const char* name, SymbolTable::IndirectBindingSlot slot); |
ebf6f434 | 100 | void tweakWeakness(); |
a645023d A |
101 | |
102 | class CStringEquals { | |
103 | public: | |
104 | bool operator()(const char* left, const char* right) const { return (strcmp(left, right) == 0); } | |
105 | }; | |
106 | typedef __gnu_cxx::hash_set<const char*, __gnu_cxx::hash<const char*>, CStringEquals> StringSet; | |
107 | ||
108 | class NotLive { | |
109 | public: | |
110 | bool operator()(const ld::Atom* atom) const { | |
111 | return ! (atom->live() || atom->dontDeadStrip()); | |
112 | } | |
113 | }; | |
114 | ||
115 | class AtomCoalescedAway { | |
116 | public: | |
117 | bool operator()(const ld::Atom* atom) const { | |
118 | return atom->coalescedAway(); | |
119 | } | |
120 | }; | |
121 | ||
122 | const Options& _options; | |
ebf6f434 | 123 | InputFiles& _inputFiles; |
a645023d A |
124 | ld::Internal& _internal; |
125 | std::vector<const ld::Atom*> _atoms; | |
126 | std::set<const ld::Atom*> _deadStripRoots; | |
127 | std::vector<const ld::Atom*> _atomsWithUnresolvedReferences; | |
128 | SymbolTable _symbolTable; | |
129 | bool _haveLLVMObjs; | |
a645023d A |
130 | bool _completedInitialObjectFiles; |
131 | }; | |
132 | ||
133 | ||
134 | class DeadStripResolver | |
135 | { | |
136 | public: | |
137 | ||
138 | ||
139 | private: | |
140 | ||
141 | }; | |
142 | ||
143 | } // namespace tool | |
144 | } // namespace ld | |
145 | ||
146 | ||
147 | ||
148 | #endif // __RESOLVER_H__ |