1 //===- Config.h -------------------------------------------------*- C++ -*-===//
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
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"
30 enum class CodeGenOptLevel
;
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
>;
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
{
59 enum class UndefinedSymbolTreatment
{
75 enum class ObjCStubsMode
{
81 llvm::StringRef segName
;
82 llvm::StringRef sectName
;
86 struct SegmentProtection
{
92 class SymbolPatterns
{
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(); }
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
{
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;
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;
152 uint32_t dylibCompatibilityVersion
= 0;
153 uint32_t dylibCurrentVersion
= 0;
154 uint32_t timeTraceGranularity
= 500;
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
;
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
;