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