comparison lld/MachO/Config.h @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 5f17cb93ff66
children 1f2b6ac9f198
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
10 #define LLD_MACHO_CONFIG_H 10 #define LLD_MACHO_CONFIG_H
11 11
12 #include "llvm/ADT/CachedHashString.h" 12 #include "llvm/ADT/CachedHashString.h"
13 #include "llvm/ADT/DenseMap.h" 13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/DenseSet.h" 14 #include "llvm/ADT/DenseSet.h"
15 #include "llvm/ADT/MapVector.h"
16 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringRef.h" 17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/StringSet.h"
16 #include "llvm/BinaryFormat/MachO.h" 19 #include "llvm/BinaryFormat/MachO.h"
17 #include "llvm/Support/CachePruning.h" 20 #include "llvm/Support/CachePruning.h"
18 #include "llvm/Support/GlobPattern.h" 21 #include "llvm/Support/GlobPattern.h"
19 #include "llvm/Support/VersionTuple.h" 22 #include "llvm/Support/VersionTuple.h"
20 #include "llvm/TextAPI/Architecture.h" 23 #include "llvm/TextAPI/Architecture.h"
24 #include <vector> 27 #include <vector>
25 28
26 namespace lld { 29 namespace lld {
27 namespace macho { 30 namespace macho {
28 31
32 class InputSection;
29 class Symbol; 33 class Symbol;
30 struct SymbolPriorityEntry;
31 34
32 using NamePair = std::pair<llvm::StringRef, llvm::StringRef>; 35 using NamePair = std::pair<llvm::StringRef, llvm::StringRef>;
33 using SectionRenameMap = llvm::DenseMap<NamePair, NamePair>; 36 using SectionRenameMap = llvm::DenseMap<NamePair, NamePair>;
34 using SegmentRenameMap = llvm::DenseMap<llvm::StringRef, llvm::StringRef>; 37 using SegmentRenameMap = llvm::DenseMap<llvm::StringRef, llvm::StringRef>;
35 38
39 llvm::VersionTuple sdk; 42 llvm::VersionTuple sdk;
40 }; 43 };
41 44
42 inline uint32_t encodeVersion(const llvm::VersionTuple &version) { 45 inline uint32_t encodeVersion(const llvm::VersionTuple &version) {
43 return ((version.getMajor() << 020) | 46 return ((version.getMajor() << 020) |
44 (version.getMinor().getValueOr(0) << 010) | 47 (version.getMinor().value_or(0) << 010) |
45 version.getSubminor().getValueOr(0)); 48 version.getSubminor().value_or(0));
46 } 49 }
47 50
48 enum class NamespaceKind { 51 enum class NamespaceKind {
49 twolevel, 52 twolevel,
50 flat, 53 flat,
63 none, 66 none,
64 safe, 67 safe,
65 all, 68 all,
66 }; 69 };
67 70
71 enum class ObjCStubsMode {
72 fast,
73 small,
74 };
75
68 struct SectionAlign { 76 struct SectionAlign {
69 llvm::StringRef segName; 77 llvm::StringRef segName;
70 llvm::StringRef sectName; 78 llvm::StringRef sectName;
71 uint32_t align; 79 uint32_t align;
72 }; 80 };
88 void clear(); 96 void clear();
89 void insert(llvm::StringRef symbolName); 97 void insert(llvm::StringRef symbolName);
90 bool matchLiteral(llvm::StringRef symbolName) const; 98 bool matchLiteral(llvm::StringRef symbolName) const;
91 bool matchGlob(llvm::StringRef symbolName) const; 99 bool matchGlob(llvm::StringRef symbolName) const;
92 bool match(llvm::StringRef symbolName) const; 100 bool match(llvm::StringRef symbolName) const;
101 };
102
103 enum class SymtabPresence {
104 All,
105 None,
106 SelectivelyIncluded,
107 SelectivelyExcluded,
93 }; 108 };
94 109
95 struct Configuration { 110 struct Configuration {
96 Symbol *entry = nullptr; 111 Symbol *entry = nullptr;
97 bool hasReexports = false; 112 bool hasReexports = false;
98 bool allLoad = false; 113 bool allLoad = false;
99 bool applicationExtension = false; 114 bool applicationExtension = false;
100 bool archMultiple = false; 115 bool archMultiple = false;
101 bool exportDynamic = false; 116 bool exportDynamic = false;
102 bool forceLoadObjC = false; 117 bool forceLoadObjC = false;
103 bool forceLoadSwift = false; 118 bool forceLoadSwift = false; // Only applies to LC_LINKER_OPTIONs.
104 bool staticLink = false; 119 bool staticLink = false;
105 bool implicitDylibs = false; 120 bool implicitDylibs = false;
106 bool isPic = false; 121 bool isPic = false;
107 bool headerPadMaxInstallNames = false; 122 bool headerPadMaxInstallNames = false;
108 bool ltoNewPassManager = LLVM_ENABLE_NEW_PASS_MANAGER;
109 bool markDeadStrippableDylib = false; 123 bool markDeadStrippableDylib = false;
110 bool printDylibSearch = false; 124 bool printDylibSearch = false;
111 bool printEachFile = false; 125 bool printEachFile = false;
112 bool printWhyLoad = false; 126 bool printWhyLoad = false;
113 bool searchDylibsFirst = false; 127 bool searchDylibsFirst = false;
115 bool adhocCodesign = false; 129 bool adhocCodesign = false;
116 bool emitFunctionStarts = false; 130 bool emitFunctionStarts = false;
117 bool emitBitcodeBundle = false; 131 bool emitBitcodeBundle = false;
118 bool emitDataInCodeInfo = false; 132 bool emitDataInCodeInfo = false;
119 bool emitEncryptionInfo = false; 133 bool emitEncryptionInfo = false;
134 bool emitInitOffsets = false;
135 bool emitChainedFixups = false;
120 bool timeTraceEnabled = false; 136 bool timeTraceEnabled = false;
121 bool dataConst = false; 137 bool dataConst = false;
122 bool dedupLiterals = true; 138 bool dedupLiterals = true;
139 bool deadStripDuplicates = false;
140 bool omitDebugInfo = false;
141 bool warnDylibInstallName = false;
142 bool ignoreOptimizationHints = false;
143 bool forceExactCpuSubtypeMatch = false;
123 uint32_t headerPad; 144 uint32_t headerPad;
124 uint32_t dylibCompatibilityVersion = 0; 145 uint32_t dylibCompatibilityVersion = 0;
125 uint32_t dylibCurrentVersion = 0; 146 uint32_t dylibCurrentVersion = 0;
126 uint32_t timeTraceGranularity = 500; 147 uint32_t timeTraceGranularity = 500;
127 unsigned optimize; 148 unsigned optimize;
144 llvm::CachePruningPolicy thinLTOCachePolicy; 165 llvm::CachePruningPolicy thinLTOCachePolicy;
145 llvm::StringRef thinLTOCacheDir; 166 llvm::StringRef thinLTOCacheDir;
146 bool deadStripDylibs = false; 167 bool deadStripDylibs = false;
147 bool demangle = false; 168 bool demangle = false;
148 bool deadStrip = false; 169 bool deadStrip = false;
170 bool errorForArchMismatch = false;
171 bool ignoreAutoLink = false;
172 // ld64 allows invalid auto link options as long as the link succeeds. LLD
173 // does not, but there are cases in the wild where the invalid linker options
174 // exist. This allows users to ignore the specific invalid options in the case
175 // they can't easily fix them.
176 llvm::StringSet<> ignoreAutoLinkOptions;
149 PlatformInfo platformInfo; 177 PlatformInfo platformInfo;
178 llvm::Optional<PlatformInfo> secondaryPlatformInfo;
150 NamespaceKind namespaceKind = NamespaceKind::twolevel; 179 NamespaceKind namespaceKind = NamespaceKind::twolevel;
151 UndefinedSymbolTreatment undefinedSymbolTreatment = 180 UndefinedSymbolTreatment undefinedSymbolTreatment =
152 UndefinedSymbolTreatment::error; 181 UndefinedSymbolTreatment::error;
153 ICFLevel icfLevel = ICFLevel::none; 182 ICFLevel icfLevel = ICFLevel::none;
183 ObjCStubsMode objcStubsMode = ObjCStubsMode::fast;
154 llvm::MachO::HeaderFileType outputType; 184 llvm::MachO::HeaderFileType outputType;
155 std::vector<llvm::StringRef> systemLibraryRoots; 185 std::vector<llvm::StringRef> systemLibraryRoots;
156 std::vector<llvm::StringRef> librarySearchPaths; 186 std::vector<llvm::StringRef> librarySearchPaths;
157 std::vector<llvm::StringRef> frameworkSearchPaths; 187 std::vector<llvm::StringRef> frameworkSearchPaths;
158 std::vector<llvm::StringRef> runtimePaths; 188 llvm::SmallVector<llvm::StringRef, 0> runtimePaths;
159 std::vector<std::string> astPaths; 189 std::vector<std::string> astPaths;
160 std::vector<Symbol *> explicitUndefineds; 190 std::vector<Symbol *> explicitUndefineds;
191 llvm::StringSet<> explicitDynamicLookups;
161 // There are typically few custom sectionAlignments or segmentProtections, 192 // There are typically few custom sectionAlignments or segmentProtections,
162 // so use a vector instead of a map. 193 // so use a vector instead of a map.
163 std::vector<SectionAlign> sectionAlignments; 194 std::vector<SectionAlign> sectionAlignments;
164 std::vector<SegmentProtection> segmentProtections; 195 std::vector<SegmentProtection> segmentProtections;
165 196
166 llvm::DenseMap<llvm::StringRef, SymbolPriorityEntry> priorities; 197 bool callGraphProfileSort = false;
198 llvm::StringRef printSymbolOrder;
199
167 SectionRenameMap sectionRenameMap; 200 SectionRenameMap sectionRenameMap;
168 SegmentRenameMap segmentRenameMap; 201 SegmentRenameMap segmentRenameMap;
169 202
203 bool hasExplicitExports = false;
170 SymbolPatterns exportedSymbols; 204 SymbolPatterns exportedSymbols;
171 SymbolPatterns unexportedSymbols; 205 SymbolPatterns unexportedSymbols;
172 206 SymbolPatterns whyLive;
173 bool zeroModTime = false; 207
208 std::vector<std::pair<llvm::StringRef, llvm::StringRef>> aliasedSymbols;
209
210 SymtabPresence localSymbolsPresence = SymtabPresence::All;
211 SymbolPatterns localSymbolPatterns;
212
213 bool zeroModTime = true;
214
215 llvm::StringRef osoPrefix;
216
217 std::vector<llvm::StringRef> dyldEnvs;
174 218
175 llvm::MachO::Architecture arch() const { return platformInfo.target.Arch; } 219 llvm::MachO::Architecture arch() const { return platformInfo.target.Arch; }
176 220
177 llvm::MachO::PlatformKind platform() const { 221 llvm::MachO::PlatformType platform() const {
178 return platformInfo.target.Platform; 222 return platformInfo.target.Platform;
179 } 223 }
180 }; 224 };
181 225
182 // The symbol with the highest priority should be ordered first in the output 226 extern std::unique_ptr<Configuration> config;
183 // section (modulo input section contiguity constraints). Using priority
184 // (highest first) instead of order (lowest first) has the convenient property
185 // that the default-constructed zero priority -- for symbols/sections without a
186 // user-defined order -- naturally ends up putting them at the end of the
187 // output.
188 struct SymbolPriorityEntry {
189 // The priority given to a matching symbol, regardless of which object file
190 // it originated from.
191 size_t anyObjectFile = 0;
192 // The priority given to a matching symbol from a particular object file.
193 llvm::DenseMap<llvm::StringRef, size_t> objectFiles;
194 };
195
196 extern Configuration *config;
197 227
198 } // namespace macho 228 } // namespace macho
199 } // namespace lld 229 } // namespace lld
200 230
201 #endif 231 #endif