1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-*
3 * Copyright (c) 2009 Apple Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
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
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.
22 * @APPLE_LICENSE_HEADER_END@
25 #ifndef __RESOLVER_H__
26 #define __RESOLVER_H__
29 #include <sys/types.h>
32 #include <sys/sysctl.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>
42 #include <mach-o/dyld.h>
45 #include <unordered_set>
49 #include "SymbolTable.h"
58 class Resolver
: public ld::File::AtomHandler
61 Resolver(const Options
& opts
, InputFiles
& inputs
, ld::Internal
& state
)
62 : _options(opts
), _inputFiles(inputs
), _internal(state
),
63 _symbolTable(opts
, state
.indirectBindingTable
),
65 _completedInitialObjectFiles(false),
66 _ltoCodeGenFinished(false) {}
69 virtual void doAtom(const ld::Atom
&);
70 virtual void doFile(const class File
&);
76 struct WhyLiveBackChain
78 WhyLiveBackChain
* previous
;
79 const ld::Atom
* referer
;
82 void initializeState();
84 void addInitialUndefines();
85 void deadStripOptimize(bool force
=false);
86 void resolveUndefines();
87 void checkUndefines(bool force
=false);
88 void checkDylibSymbolCollisions();
89 void tentativeOverrideOfDylib(ld::Atom
&);
90 void fillInInternalState();
91 void fillInHelpersInInternalState();
92 void removeCoalescedAwayAtoms();
93 void fillInEntryPoint();
94 void linkTimeOptimize();
95 void convertReferencesToIndirect(const ld::Atom
& atom
);
96 const ld::Atom
* entryPoint(bool searchArchives
);
97 void markLive(const ld::Atom
& atom
, WhyLiveBackChain
* previous
);
98 bool isDtraceProbe(ld::Fixup::Kind kind
);
99 void liveUndefines(std::vector
<const char*>&);
100 void remainingUndefines(std::vector
<const char*>&);
101 bool printReferencedBy(const char* name
, SymbolTable::IndirectBindingSlot slot
);
102 void tweakWeakness();
103 void doLinkerOption(const std::vector
<const char*>& linkerOption
, const char* fileName
);
106 typedef std::unordered_set
<const char*, CStringHash
, CStringEquals
> StringSet
;
110 bool operator()(const ld::Atom
* atom
) const {
111 return ! (atom
->live() || atom
->dontDeadStrip());
115 class AtomCoalescedAway
{
117 bool operator()(const ld::Atom
* atom
) const {
118 return atom
->coalescedAway();
122 const Options
& _options
;
123 InputFiles
& _inputFiles
;
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 std::vector
<const class AliasAtom
*> _aliasesFromCmdLine
;
129 SymbolTable _symbolTable
;
131 bool _completedInitialObjectFiles
;
132 bool _ltoCodeGenFinished
;
136 class DeadStripResolver
150 #endif // __RESOLVER_H__