Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / lld / MachO / Config.h
blob8f6da6330d7ad477c3381ff4ad158afa44a97638
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 //===----------------------------------------------------------------------===//
9 #ifndef LLD_MACHO_CONFIG_H
10 #define LLD_MACHO_CONFIG_H
12 #include "llvm/ADT/CachedHashString.h"
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/DenseSet.h"
15 #include "llvm/ADT/SetVector.h"
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/StringSet.h"
19 #include "llvm/BinaryFormat/MachO.h"
20 #include "llvm/Support/CachePruning.h"
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"
27 #include <vector>
29 namespace llvm {
30 enum class CodeGenOptLevel;
31 } // namespace llvm
33 namespace lld {
34 namespace macho {
36 class InputSection;
37 class Symbol;
39 using NamePair = std::pair<llvm::StringRef, llvm::StringRef>;
40 using SectionRenameMap = llvm::DenseMap<NamePair, NamePair>;
41 using SegmentRenameMap = llvm::DenseMap<llvm::StringRef, llvm::StringRef>;
43 struct PlatformInfo {
44 llvm::MachO::Target target;
45 llvm::VersionTuple sdk;
48 inline uint32_t encodeVersion(const llvm::VersionTuple &version) {
49 return ((version.getMajor() << 020) |
50 (version.getMinor().value_or(0) << 010) |
51 version.getSubminor().value_or(0));
54 enum class NamespaceKind {
55 twolevel,
56 flat,
59 enum class UndefinedSymbolTreatment {
60 unknown,
61 error,
62 warning,
63 suppress,
64 dynamic_lookup,
67 enum class ICFLevel {
68 unknown,
69 none,
70 safe,
71 safe_thunks,
72 all,
75 enum class ObjCStubsMode {
76 fast,
77 small,
80 struct SectionAlign {
81 llvm::StringRef segName;
82 llvm::StringRef sectName;
83 uint32_t align;
86 struct SegmentProtection {
87 llvm::StringRef name;
88 uint32_t maxProt;
89 uint32_t initProt;
92 class SymbolPatterns {
93 public:
94 // GlobPattern can also match literals,
95 // but we prefer the O(1) lookup of DenseSet.
96 llvm::SetVector<llvm::CachedHashStringRef> literals;
97 std::vector<llvm::GlobPattern> globs;
99 bool empty() const { return literals.empty() && globs.empty(); }
100 void clear();
101 void insert(llvm::StringRef symbolName);
102 bool matchLiteral(llvm::StringRef symbolName) const;
103 bool matchGlob(llvm::StringRef symbolName) const;
104 bool match(llvm::StringRef symbolName) const;
107 enum class SymtabPresence {
108 All,
109 None,
110 SelectivelyIncluded,
111 SelectivelyExcluded,
114 struct Configuration {
115 Symbol *entry = nullptr;
116 bool hasReexports = false;
117 bool allLoad = false;
118 bool applicationExtension = false;
119 bool archMultiple = false;
120 bool exportDynamic = false;
121 bool forceLoadObjC = false;
122 bool forceLoadSwift = false; // Only applies to LC_LINKER_OPTIONs.
123 bool staticLink = false;
124 bool implicitDylibs = false;
125 bool isPic = false;
126 bool headerPadMaxInstallNames = false;
127 bool markDeadStrippableDylib = false;
128 bool printDylibSearch = false;
129 bool printEachFile = false;
130 bool printWhyLoad = false;
131 bool searchDylibsFirst = false;
132 bool saveTemps = false;
133 bool adhocCodesign = false;
134 bool emitFunctionStarts = false;
135 bool emitDataInCodeInfo = false;
136 bool emitEncryptionInfo = false;
137 bool emitInitOffsets = false;
138 bool emitChainedFixups = false;
139 bool emitRelativeMethodLists = false;
140 bool thinLTOEmitImportsFiles;
141 bool thinLTOEmitIndexFiles;
142 bool thinLTOIndexOnly;
143 bool timeTraceEnabled = false;
144 bool dataConst = false;
145 bool dedupStrings = true;
146 bool deadStripDuplicates = false;
147 bool omitDebugInfo = false;
148 bool warnDylibInstallName = false;
149 bool ignoreOptimizationHints = false;
150 bool forceExactCpuSubtypeMatch = false;
151 uint32_t headerPad;
152 uint32_t dylibCompatibilityVersion = 0;
153 uint32_t dylibCurrentVersion = 0;
154 uint32_t timeTraceGranularity = 500;
155 unsigned optimize;
156 std::string progName;
158 // For `clang -arch arm64 -arch x86_64`, clang will:
159 // 1. invoke the linker twice, to write one temporary output per arch
160 // 2. invoke `lipo` to merge the two outputs into a single file
161 // `outputFile` is the name of the temporary file the linker writes to.
162 // `finalOutput `is the name of the file lipo writes to after the link.
163 llvm::StringRef outputFile;
164 llvm::StringRef finalOutput;
166 llvm::StringRef installName;
167 llvm::StringRef mapFile;
168 llvm::StringRef ltoObjPath;
169 llvm::StringRef thinLTOJobs;
170 llvm::StringRef umbrella;
171 uint32_t ltoo = 2;
172 llvm::CodeGenOptLevel ltoCgo;
173 llvm::CachePruningPolicy thinLTOCachePolicy;
174 llvm::StringRef thinLTOCacheDir;
175 llvm::StringRef thinLTOIndexOnlyArg;
176 std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
177 llvm::StringRef thinLTOPrefixReplaceOld;
178 llvm::StringRef thinLTOPrefixReplaceNew;
179 llvm::StringRef thinLTOPrefixReplaceNativeObject;
180 bool deadStripDylibs = false;
181 bool demangle = false;
182 bool deadStrip = false;
183 bool errorForArchMismatch = false;
184 bool ignoreAutoLink = false;
185 // ld64 allows invalid auto link options as long as the link succeeds. LLD
186 // does not, but there are cases in the wild where the invalid linker options
187 // exist. This allows users to ignore the specific invalid options in the case
188 // they can't easily fix them.
189 llvm::StringSet<> ignoreAutoLinkOptions;
190 bool strictAutoLink = false;
191 PlatformInfo platformInfo;
192 std::optional<PlatformInfo> secondaryPlatformInfo;
193 NamespaceKind namespaceKind = NamespaceKind::twolevel;
194 UndefinedSymbolTreatment undefinedSymbolTreatment =
195 UndefinedSymbolTreatment::error;
196 ICFLevel icfLevel = ICFLevel::none;
197 bool keepICFStabs = false;
198 ObjCStubsMode objcStubsMode = ObjCStubsMode::fast;
199 llvm::MachO::HeaderFileType outputType;
200 std::vector<llvm::StringRef> systemLibraryRoots;
201 std::vector<llvm::StringRef> librarySearchPaths;
202 std::vector<llvm::StringRef> frameworkSearchPaths;
203 bool warnDuplicateRpath = true;
204 llvm::SmallVector<llvm::StringRef, 0> runtimePaths;
205 std::vector<std::string> astPaths;
206 std::vector<Symbol *> explicitUndefineds;
207 llvm::StringSet<> explicitDynamicLookups;
208 // There are typically few custom sectionAlignments or segmentProtections,
209 // so use a vector instead of a map.
210 std::vector<SectionAlign> sectionAlignments;
211 std::vector<SegmentProtection> segmentProtections;
212 bool ltoDebugPassManager = false;
213 llvm::StringRef codegenDataGeneratePath;
214 bool csProfileGenerate = false;
215 llvm::StringRef csProfilePath;
216 bool pgoWarnMismatch;
217 bool warnThinArchiveMissingMembers;
219 bool callGraphProfileSort = false;
220 llvm::StringRef printSymbolOrder;
222 llvm::StringRef irpgoProfileSortProfilePath;
223 bool compressionSortStartupFunctions = false;
224 bool functionOrderForCompression = false;
225 bool dataOrderForCompression = false;
226 bool verboseBpSectionOrderer = false;
228 SectionRenameMap sectionRenameMap;
229 SegmentRenameMap segmentRenameMap;
231 bool hasExplicitExports = false;
232 SymbolPatterns exportedSymbols;
233 SymbolPatterns unexportedSymbols;
234 SymbolPatterns whyLive;
236 std::vector<std::pair<llvm::StringRef, llvm::StringRef>> aliasedSymbols;
238 SymtabPresence localSymbolsPresence = SymtabPresence::All;
239 SymbolPatterns localSymbolPatterns;
240 llvm::SmallVector<llvm::StringRef, 0> mllvmOpts;
242 bool zeroModTime = true;
243 bool generateUuid = true;
245 llvm::StringRef osoPrefix;
247 std::vector<llvm::StringRef> dyldEnvs;
249 llvm::MachO::Architecture arch() const { return platformInfo.target.Arch; }
251 llvm::MachO::PlatformType platform() const {
252 return platformInfo.target.Platform;
256 extern std::unique_ptr<Configuration> config;
258 } // namespace macho
259 } // namespace lld
261 #endif