173
|
1 //===- Config.h -------------------------------------------------*- C++ -*-===//
|
|
2 //
|
|
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
4 // See https://llvm.org/LICENSE.txt for license information.
|
|
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
6 //
|
|
7 //===----------------------------------------------------------------------===//
|
|
8
|
|
9 #ifndef LLD_MACHO_CONFIG_H
|
|
10 #define LLD_MACHO_CONFIG_H
|
|
11
|
221
|
12 #include "llvm/ADT/CachedHashString.h"
|
173
|
13 #include "llvm/ADT/DenseMap.h"
|
221
|
14 #include "llvm/ADT/DenseSet.h"
|
236
|
15 #include "llvm/ADT/MapVector.h"
|
|
16 #include "llvm/ADT/SmallVector.h"
|
173
|
17 #include "llvm/ADT/StringRef.h"
|
236
|
18 #include "llvm/ADT/StringSet.h"
|
173
|
19 #include "llvm/BinaryFormat/MachO.h"
|
223
|
20 #include "llvm/Support/CachePruning.h"
|
221
|
21 #include "llvm/Support/GlobPattern.h"
|
|
22 #include "llvm/Support/VersionTuple.h"
|
|
23 #include "llvm/TextAPI/Architecture.h"
|
|
24 #include "llvm/TextAPI/Platform.h"
|
|
25 #include "llvm/TextAPI/Target.h"
|
173
|
26
|
|
27 #include <vector>
|
|
28
|
|
29 namespace lld {
|
|
30 namespace macho {
|
|
31
|
236
|
32 class InputSection;
|
173
|
33 class Symbol;
|
|
34
|
221
|
35 using NamePair = std::pair<llvm::StringRef, llvm::StringRef>;
|
|
36 using SectionRenameMap = llvm::DenseMap<NamePair, NamePair>;
|
|
37 using SegmentRenameMap = llvm::DenseMap<llvm::StringRef, llvm::StringRef>;
|
|
38
|
|
39 struct PlatformInfo {
|
|
40 llvm::MachO::Target target;
|
|
41 llvm::VersionTuple minimum;
|
|
42 llvm::VersionTuple sdk;
|
|
43 };
|
|
44
|
|
45 inline uint32_t encodeVersion(const llvm::VersionTuple &version) {
|
|
46 return ((version.getMajor() << 020) |
|
236
|
47 (version.getMinor().value_or(0) << 010) |
|
|
48 version.getSubminor().value_or(0));
|
221
|
49 }
|
|
50
|
|
51 enum class NamespaceKind {
|
|
52 twolevel,
|
|
53 flat,
|
|
54 };
|
|
55
|
|
56 enum class UndefinedSymbolTreatment {
|
|
57 unknown,
|
|
58 error,
|
|
59 warning,
|
|
60 suppress,
|
|
61 dynamic_lookup,
|
|
62 };
|
|
63
|
223
|
64 enum class ICFLevel {
|
|
65 unknown,
|
|
66 none,
|
|
67 safe,
|
|
68 all,
|
|
69 };
|
|
70
|
236
|
71 enum class ObjCStubsMode {
|
|
72 fast,
|
|
73 small,
|
|
74 };
|
|
75
|
221
|
76 struct SectionAlign {
|
|
77 llvm::StringRef segName;
|
|
78 llvm::StringRef sectName;
|
|
79 uint32_t align;
|
|
80 };
|
|
81
|
|
82 struct SegmentProtection {
|
|
83 llvm::StringRef name;
|
|
84 uint32_t maxProt;
|
|
85 uint32_t initProt;
|
|
86 };
|
|
87
|
|
88 class SymbolPatterns {
|
|
89 public:
|
|
90 // GlobPattern can also match literals,
|
|
91 // but we prefer the O(1) lookup of DenseSet.
|
|
92 llvm::DenseSet<llvm::CachedHashStringRef> literals;
|
|
93 std::vector<llvm::GlobPattern> globs;
|
|
94
|
|
95 bool empty() const { return literals.empty() && globs.empty(); }
|
|
96 void clear();
|
|
97 void insert(llvm::StringRef symbolName);
|
|
98 bool matchLiteral(llvm::StringRef symbolName) const;
|
|
99 bool matchGlob(llvm::StringRef symbolName) const;
|
|
100 bool match(llvm::StringRef symbolName) const;
|
|
101 };
|
|
102
|
236
|
103 enum class SymtabPresence {
|
|
104 All,
|
|
105 None,
|
|
106 SelectivelyIncluded,
|
|
107 SelectivelyExcluded,
|
|
108 };
|
|
109
|
173
|
110 struct Configuration {
|
221
|
111 Symbol *entry = nullptr;
|
173
|
112 bool hasReexports = false;
|
221
|
113 bool allLoad = false;
|
223
|
114 bool applicationExtension = false;
|
|
115 bool archMultiple = false;
|
|
116 bool exportDynamic = false;
|
221
|
117 bool forceLoadObjC = false;
|
236
|
118 bool forceLoadSwift = false; // Only applies to LC_LINKER_OPTIONs.
|
221
|
119 bool staticLink = false;
|
|
120 bool implicitDylibs = false;
|
|
121 bool isPic = false;
|
|
122 bool headerPadMaxInstallNames = false;
|
|
123 bool markDeadStrippableDylib = false;
|
223
|
124 bool printDylibSearch = false;
|
221
|
125 bool printEachFile = false;
|
|
126 bool printWhyLoad = false;
|
|
127 bool searchDylibsFirst = false;
|
|
128 bool saveTemps = false;
|
|
129 bool adhocCodesign = false;
|
|
130 bool emitFunctionStarts = false;
|
|
131 bool emitBitcodeBundle = false;
|
223
|
132 bool emitDataInCodeInfo = false;
|
221
|
133 bool emitEncryptionInfo = false;
|
236
|
134 bool emitInitOffsets = false;
|
|
135 bool emitChainedFixups = false;
|
221
|
136 bool timeTraceEnabled = false;
|
|
137 bool dataConst = false;
|
223
|
138 bool dedupLiterals = true;
|
236
|
139 bool deadStripDuplicates = false;
|
|
140 bool omitDebugInfo = false;
|
|
141 bool warnDylibInstallName = false;
|
|
142 bool ignoreOptimizationHints = false;
|
|
143 bool forceExactCpuSubtypeMatch = false;
|
221
|
144 uint32_t headerPad;
|
|
145 uint32_t dylibCompatibilityVersion = 0;
|
|
146 uint32_t dylibCurrentVersion = 0;
|
|
147 uint32_t timeTraceGranularity = 500;
|
223
|
148 unsigned optimize;
|
221
|
149 std::string progName;
|
223
|
150
|
|
151 // For `clang -arch arm64 -arch x86_64`, clang will:
|
|
152 // 1. invoke the linker twice, to write one temporary output per arch
|
|
153 // 2. invoke `lipo` to merge the two outputs into a single file
|
|
154 // `outputFile` is the name of the temporary file the linker writes to.
|
|
155 // `finalOutput `is the name of the file lipo writes to after the link.
|
|
156 llvm::StringRef outputFile;
|
|
157 llvm::StringRef finalOutput;
|
|
158
|
173
|
159 llvm::StringRef installName;
|
221
|
160 llvm::StringRef mapFile;
|
|
161 llvm::StringRef ltoObjPath;
|
|
162 llvm::StringRef thinLTOJobs;
|
223
|
163 llvm::StringRef umbrella;
|
|
164 uint32_t ltoo = 2;
|
|
165 llvm::CachePruningPolicy thinLTOCachePolicy;
|
|
166 llvm::StringRef thinLTOCacheDir;
|
221
|
167 bool deadStripDylibs = false;
|
|
168 bool demangle = false;
|
|
169 bool deadStrip = false;
|
236
|
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;
|
221
|
177 PlatformInfo platformInfo;
|
236
|
178 llvm::Optional<PlatformInfo> secondaryPlatformInfo;
|
221
|
179 NamespaceKind namespaceKind = NamespaceKind::twolevel;
|
|
180 UndefinedSymbolTreatment undefinedSymbolTreatment =
|
|
181 UndefinedSymbolTreatment::error;
|
223
|
182 ICFLevel icfLevel = ICFLevel::none;
|
236
|
183 ObjCStubsMode objcStubsMode = ObjCStubsMode::fast;
|
173
|
184 llvm::MachO::HeaderFileType outputType;
|
221
|
185 std::vector<llvm::StringRef> systemLibraryRoots;
|
|
186 std::vector<llvm::StringRef> librarySearchPaths;
|
|
187 std::vector<llvm::StringRef> frameworkSearchPaths;
|
236
|
188 llvm::SmallVector<llvm::StringRef, 0> runtimePaths;
|
221
|
189 std::vector<std::string> astPaths;
|
|
190 std::vector<Symbol *> explicitUndefineds;
|
236
|
191 llvm::StringSet<> explicitDynamicLookups;
|
221
|
192 // There are typically few custom sectionAlignments or segmentProtections,
|
|
193 // so use a vector instead of a map.
|
|
194 std::vector<SectionAlign> sectionAlignments;
|
|
195 std::vector<SegmentProtection> segmentProtections;
|
|
196
|
236
|
197 bool callGraphProfileSort = false;
|
|
198 llvm::StringRef printSymbolOrder;
|
|
199
|
221
|
200 SectionRenameMap sectionRenameMap;
|
|
201 SegmentRenameMap segmentRenameMap;
|
|
202
|
236
|
203 bool hasExplicitExports = false;
|
221
|
204 SymbolPatterns exportedSymbols;
|
|
205 SymbolPatterns unexportedSymbols;
|
236
|
206 SymbolPatterns whyLive;
|
221
|
207
|
236
|
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;
|
221
|
218
|
|
219 llvm::MachO::Architecture arch() const { return platformInfo.target.Arch; }
|
|
220
|
236
|
221 llvm::MachO::PlatformType platform() const {
|
221
|
222 return platformInfo.target.Platform;
|
|
223 }
|
173
|
224 };
|
|
225
|
236
|
226 extern std::unique_ptr<Configuration> config;
|
173
|
227
|
|
228 } // namespace macho
|
|
229 } // namespace lld
|
|
230
|
|
231 #endif
|