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/MapVector.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::DenseSet
<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 thinLTOEmitImportsFiles
;
139 bool thinLTOEmitIndexFiles
;
140 bool thinLTOIndexOnly
;
141 bool timeTraceEnabled
= false;
142 bool dataConst
= false;
143 bool dedupStrings
= true;
144 bool deadStripDuplicates
= false;
145 bool omitDebugInfo
= false;
146 bool warnDylibInstallName
= false;
147 bool ignoreOptimizationHints
= false;
148 bool forceExactCpuSubtypeMatch
= false;
150 uint32_t dylibCompatibilityVersion
= 0;
151 uint32_t dylibCurrentVersion
= 0;
152 uint32_t timeTraceGranularity
= 500;
154 std::string progName
;
156 // For `clang -arch arm64 -arch x86_64`, clang will:
157 // 1. invoke the linker twice, to write one temporary output per arch
158 // 2. invoke `lipo` to merge the two outputs into a single file
159 // `outputFile` is the name of the temporary file the linker writes to.
160 // `finalOutput `is the name of the file lipo writes to after the link.
161 llvm::StringRef outputFile
;
162 llvm::StringRef finalOutput
;
164 llvm::StringRef installName
;
165 llvm::StringRef mapFile
;
166 llvm::StringRef ltoObjPath
;
167 llvm::StringRef thinLTOJobs
;
168 llvm::StringRef umbrella
;
170 llvm::CodeGenOptLevel ltoCgo
;
171 llvm::CachePruningPolicy thinLTOCachePolicy
;
172 llvm::StringRef thinLTOCacheDir
;
173 llvm::StringRef thinLTOIndexOnlyArg
;
174 std::pair
<llvm::StringRef
, llvm::StringRef
> thinLTOObjectSuffixReplace
;
175 llvm::StringRef thinLTOPrefixReplaceOld
;
176 llvm::StringRef thinLTOPrefixReplaceNew
;
177 llvm::StringRef thinLTOPrefixReplaceNativeObject
;
178 bool deadStripDylibs
= false;
179 bool demangle
= false;
180 bool deadStrip
= false;
181 bool errorForArchMismatch
= false;
182 bool ignoreAutoLink
= false;
183 // ld64 allows invalid auto link options as long as the link succeeds. LLD
184 // does not, but there are cases in the wild where the invalid linker options
185 // exist. This allows users to ignore the specific invalid options in the case
186 // they can't easily fix them.
187 llvm::StringSet
<> ignoreAutoLinkOptions
;
188 bool strictAutoLink
= false;
189 PlatformInfo platformInfo
;
190 std::optional
<PlatformInfo
> secondaryPlatformInfo
;
191 NamespaceKind namespaceKind
= NamespaceKind::twolevel
;
192 UndefinedSymbolTreatment undefinedSymbolTreatment
=
193 UndefinedSymbolTreatment::error
;
194 ICFLevel icfLevel
= ICFLevel::none
;
195 ObjCStubsMode objcStubsMode
= ObjCStubsMode::fast
;
196 llvm::MachO::HeaderFileType outputType
;
197 std::vector
<llvm::StringRef
> systemLibraryRoots
;
198 std::vector
<llvm::StringRef
> librarySearchPaths
;
199 std::vector
<llvm::StringRef
> frameworkSearchPaths
;
200 llvm::SmallVector
<llvm::StringRef
, 0> runtimePaths
;
201 std::vector
<std::string
> astPaths
;
202 std::vector
<Symbol
*> explicitUndefineds
;
203 llvm::StringSet
<> explicitDynamicLookups
;
204 // There are typically few custom sectionAlignments or segmentProtections,
205 // so use a vector instead of a map.
206 std::vector
<SectionAlign
> sectionAlignments
;
207 std::vector
<SegmentProtection
> segmentProtections
;
208 bool ltoDebugPassManager
= false;
209 bool csProfileGenerate
= false;
210 llvm::StringRef csProfilePath
;
211 bool pgoWarnMismatch
;
213 bool callGraphProfileSort
= false;
214 llvm::StringRef printSymbolOrder
;
216 SectionRenameMap sectionRenameMap
;
217 SegmentRenameMap segmentRenameMap
;
219 bool hasExplicitExports
= false;
220 SymbolPatterns exportedSymbols
;
221 SymbolPatterns unexportedSymbols
;
222 SymbolPatterns whyLive
;
224 std::vector
<std::pair
<llvm::StringRef
, llvm::StringRef
>> aliasedSymbols
;
226 SymtabPresence localSymbolsPresence
= SymtabPresence::All
;
227 SymbolPatterns localSymbolPatterns
;
228 llvm::SmallVector
<llvm::StringRef
, 0> mllvmOpts
;
230 bool zeroModTime
= true;
231 bool generateUuid
= true;
233 llvm::StringRef osoPrefix
;
235 std::vector
<llvm::StringRef
> dyldEnvs
;
237 llvm::MachO::Architecture
arch() const { return platformInfo
.target
.Arch
; }
239 llvm::MachO::PlatformType
platform() const {
240 return platformInfo
.target
.Platform
;
244 extern std::unique_ptr
<Configuration
> config
;