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