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
{
74 enum class ObjCStubsMode
{
80 llvm::StringRef segName
;
81 llvm::StringRef sectName
;
85 struct SegmentProtection
{
91 class SymbolPatterns
{
93 // GlobPattern can also match literals,
94 // but we prefer the O(1) lookup of DenseSet.
95 llvm::SetVector
<llvm::CachedHashStringRef
> literals
;
96 std::vector
<llvm::GlobPattern
> globs
;
98 bool empty() const { return literals
.empty() && globs
.empty(); }
100 void insert(llvm::StringRef symbolName
);
101 bool matchLiteral(llvm::StringRef symbolName
) const;
102 bool matchGlob(llvm::StringRef symbolName
) const;
103 bool match(llvm::StringRef symbolName
) const;
106 enum class SymtabPresence
{
113 struct Configuration
{
114 Symbol
*entry
= nullptr;
115 bool hasReexports
= false;
116 bool allLoad
= false;
117 bool applicationExtension
= false;
118 bool archMultiple
= false;
119 bool exportDynamic
= false;
120 bool forceLoadObjC
= false;
121 bool forceLoadSwift
= false; // Only applies to LC_LINKER_OPTIONs.
122 bool staticLink
= false;
123 bool implicitDylibs
= false;
125 bool headerPadMaxInstallNames
= false;
126 bool markDeadStrippableDylib
= false;
127 bool printDylibSearch
= false;
128 bool printEachFile
= false;
129 bool printWhyLoad
= false;
130 bool searchDylibsFirst
= false;
131 bool saveTemps
= false;
132 bool adhocCodesign
= false;
133 bool emitFunctionStarts
= false;
134 bool emitDataInCodeInfo
= false;
135 bool emitEncryptionInfo
= false;
136 bool emitInitOffsets
= false;
137 bool emitChainedFixups
= false;
138 bool emitRelativeMethodLists
= false;
139 bool thinLTOEmitImportsFiles
;
140 bool thinLTOEmitIndexFiles
;
141 bool thinLTOIndexOnly
;
142 bool timeTraceEnabled
= false;
143 bool dataConst
= false;
144 bool dedupStrings
= true;
145 bool deadStripDuplicates
= false;
146 bool omitDebugInfo
= false;
147 bool warnDylibInstallName
= false;
148 bool ignoreOptimizationHints
= false;
149 bool forceExactCpuSubtypeMatch
= false;
151 uint32_t dylibCompatibilityVersion
= 0;
152 uint32_t dylibCurrentVersion
= 0;
153 uint32_t timeTraceGranularity
= 500;
155 std::string progName
;
157 // For `clang -arch arm64 -arch x86_64`, clang will:
158 // 1. invoke the linker twice, to write one temporary output per arch
159 // 2. invoke `lipo` to merge the two outputs into a single file
160 // `outputFile` is the name of the temporary file the linker writes to.
161 // `finalOutput `is the name of the file lipo writes to after the link.
162 llvm::StringRef outputFile
;
163 llvm::StringRef finalOutput
;
165 llvm::StringRef installName
;
166 llvm::StringRef mapFile
;
167 llvm::StringRef ltoObjPath
;
168 llvm::StringRef thinLTOJobs
;
169 llvm::StringRef umbrella
;
171 llvm::CodeGenOptLevel ltoCgo
;
172 llvm::CachePruningPolicy thinLTOCachePolicy
;
173 llvm::StringRef thinLTOCacheDir
;
174 llvm::StringRef thinLTOIndexOnlyArg
;
175 std::pair
<llvm::StringRef
, llvm::StringRef
> thinLTOObjectSuffixReplace
;
176 llvm::StringRef thinLTOPrefixReplaceOld
;
177 llvm::StringRef thinLTOPrefixReplaceNew
;
178 llvm::StringRef thinLTOPrefixReplaceNativeObject
;
179 bool deadStripDylibs
= false;
180 bool demangle
= false;
181 bool deadStrip
= false;
182 bool errorForArchMismatch
= false;
183 bool ignoreAutoLink
= false;
184 // ld64 allows invalid auto link options as long as the link succeeds. LLD
185 // does not, but there are cases in the wild where the invalid linker options
186 // exist. This allows users to ignore the specific invalid options in the case
187 // they can't easily fix them.
188 llvm::StringSet
<> ignoreAutoLinkOptions
;
189 bool strictAutoLink
= false;
190 PlatformInfo platformInfo
;
191 std::optional
<PlatformInfo
> secondaryPlatformInfo
;
192 NamespaceKind namespaceKind
= NamespaceKind::twolevel
;
193 UndefinedSymbolTreatment undefinedSymbolTreatment
=
194 UndefinedSymbolTreatment::error
;
195 ICFLevel icfLevel
= ICFLevel::none
;
196 bool keepICFStabs
= false;
197 ObjCStubsMode objcStubsMode
= ObjCStubsMode::fast
;
198 llvm::MachO::HeaderFileType outputType
;
199 std::vector
<llvm::StringRef
> systemLibraryRoots
;
200 std::vector
<llvm::StringRef
> librarySearchPaths
;
201 std::vector
<llvm::StringRef
> frameworkSearchPaths
;
202 bool warnDuplicateRpath
= true;
203 llvm::SmallVector
<llvm::StringRef
, 0> runtimePaths
;
204 std::vector
<std::string
> astPaths
;
205 std::vector
<Symbol
*> explicitUndefineds
;
206 llvm::StringSet
<> explicitDynamicLookups
;
207 // There are typically few custom sectionAlignments or segmentProtections,
208 // so use a vector instead of a map.
209 std::vector
<SectionAlign
> sectionAlignments
;
210 std::vector
<SegmentProtection
> segmentProtections
;
211 bool ltoDebugPassManager
= false;
212 bool csProfileGenerate
= false;
213 llvm::StringRef csProfilePath
;
214 bool pgoWarnMismatch
;
215 bool warnThinArchiveMissingMembers
;
217 bool callGraphProfileSort
= false;
218 llvm::StringRef printSymbolOrder
;
220 SectionRenameMap sectionRenameMap
;
221 SegmentRenameMap segmentRenameMap
;
223 bool hasExplicitExports
= false;
224 SymbolPatterns exportedSymbols
;
225 SymbolPatterns unexportedSymbols
;
226 SymbolPatterns whyLive
;
228 std::vector
<std::pair
<llvm::StringRef
, llvm::StringRef
>> aliasedSymbols
;
230 SymtabPresence localSymbolsPresence
= SymtabPresence::All
;
231 SymbolPatterns localSymbolPatterns
;
232 llvm::SmallVector
<llvm::StringRef
, 0> mllvmOpts
;
234 bool zeroModTime
= true;
235 bool generateUuid
= true;
237 llvm::StringRef osoPrefix
;
239 std::vector
<llvm::StringRef
> dyldEnvs
;
241 llvm::MachO::Architecture
arch() const { return platformInfo
.target
.Arch
; }
243 llvm::MachO::PlatformType
platform() const {
244 return platformInfo
.target
.Platform
;
248 extern std::unique_ptr
<Configuration
> config
;