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"
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
>;
40 llvm::MachO::Target target
;
41 llvm::VersionTuple minimum
;
42 llvm::VersionTuple sdk
;
45 inline uint32_t encodeVersion(const llvm::VersionTuple
&version
) {
46 return ((version
.getMajor() << 020) |
47 (version
.getMinor().value_or(0) << 010) |
48 version
.getSubminor().value_or(0));
51 enum class NamespaceKind
{
56 enum class UndefinedSymbolTreatment
{
72 llvm::StringRef segName
;
73 llvm::StringRef sectName
;
77 struct SegmentProtection
{
83 class SymbolPatterns
{
85 // GlobPattern can also match literals,
86 // but we prefer the O(1) lookup of DenseSet.
87 llvm::DenseSet
<llvm::CachedHashStringRef
> literals
;
88 std::vector
<llvm::GlobPattern
> globs
;
90 bool empty() const { return literals
.empty() && globs
.empty(); }
92 void insert(llvm::StringRef symbolName
);
93 bool matchLiteral(llvm::StringRef symbolName
) const;
94 bool matchGlob(llvm::StringRef symbolName
) const;
95 bool match(llvm::StringRef symbolName
) const;
98 enum class SymtabPresence
{
105 struct Configuration
{
106 Symbol
*entry
= nullptr;
107 bool hasReexports
= false;
108 bool allLoad
= false;
109 bool applicationExtension
= false;
110 bool archMultiple
= false;
111 bool exportDynamic
= false;
112 bool forceLoadObjC
= false;
113 bool forceLoadSwift
= false; // Only applies to LC_LINKER_OPTIONs.
114 bool staticLink
= false;
115 bool implicitDylibs
= false;
117 bool headerPadMaxInstallNames
= false;
118 bool markDeadStrippableDylib
= false;
119 bool printDylibSearch
= false;
120 bool printEachFile
= false;
121 bool printWhyLoad
= false;
122 bool searchDylibsFirst
= false;
123 bool saveTemps
= false;
124 bool adhocCodesign
= false;
125 bool emitFunctionStarts
= false;
126 bool emitBitcodeBundle
= false;
127 bool emitDataInCodeInfo
= false;
128 bool emitEncryptionInfo
= false;
129 bool timeTraceEnabled
= false;
130 bool dataConst
= false;
131 bool dedupLiterals
= true;
132 bool omitDebugInfo
= false;
133 bool warnDylibInstallName
= false;
134 bool ignoreOptimizationHints
= false;
135 bool forceExactCpuSubtypeMatch
= false;
137 uint32_t dylibCompatibilityVersion
= 0;
138 uint32_t dylibCurrentVersion
= 0;
139 uint32_t timeTraceGranularity
= 500;
141 std::string progName
;
143 // For `clang -arch arm64 -arch x86_64`, clang will:
144 // 1. invoke the linker twice, to write one temporary output per arch
145 // 2. invoke `lipo` to merge the two outputs into a single file
146 // `outputFile` is the name of the temporary file the linker writes to.
147 // `finalOutput `is the name of the file lipo writes to after the link.
148 llvm::StringRef outputFile
;
149 llvm::StringRef finalOutput
;
151 llvm::StringRef installName
;
152 llvm::StringRef mapFile
;
153 llvm::StringRef ltoObjPath
;
154 llvm::StringRef thinLTOJobs
;
155 llvm::StringRef umbrella
;
157 llvm::CachePruningPolicy thinLTOCachePolicy
;
158 llvm::StringRef thinLTOCacheDir
;
159 bool deadStripDylibs
= false;
160 bool demangle
= false;
161 bool deadStrip
= false;
162 bool errorForArchMismatch
= false;
163 PlatformInfo platformInfo
;
164 llvm::Optional
<PlatformInfo
> secondaryPlatformInfo
;
165 NamespaceKind namespaceKind
= NamespaceKind::twolevel
;
166 UndefinedSymbolTreatment undefinedSymbolTreatment
=
167 UndefinedSymbolTreatment::error
;
168 ICFLevel icfLevel
= ICFLevel::none
;
169 llvm::MachO::HeaderFileType outputType
;
170 std::vector
<llvm::StringRef
> systemLibraryRoots
;
171 std::vector
<llvm::StringRef
> librarySearchPaths
;
172 std::vector
<llvm::StringRef
> frameworkSearchPaths
;
173 llvm::SmallVector
<llvm::StringRef
, 0> runtimePaths
;
174 std::vector
<std::string
> astPaths
;
175 std::vector
<Symbol
*> explicitUndefineds
;
176 llvm::StringSet
<> explicitDynamicLookups
;
177 // There are typically few custom sectionAlignments or segmentProtections,
178 // so use a vector instead of a map.
179 std::vector
<SectionAlign
> sectionAlignments
;
180 std::vector
<SegmentProtection
> segmentProtections
;
182 bool callGraphProfileSort
= false;
183 llvm::StringRef printSymbolOrder
;
185 SectionRenameMap sectionRenameMap
;
186 SegmentRenameMap segmentRenameMap
;
188 bool hasExplicitExports
= false;
189 SymbolPatterns exportedSymbols
;
190 SymbolPatterns unexportedSymbols
;
191 SymbolPatterns whyLive
;
193 std::vector
<std::pair
<llvm::StringRef
, llvm::StringRef
>> aliasedSymbols
;
195 SymtabPresence localSymbolsPresence
= SymtabPresence::All
;
196 SymbolPatterns localSymbolPatterns
;
198 bool zeroModTime
= false;
200 llvm::StringRef osoPrefix
;
202 llvm::MachO::Architecture
arch() const { return platformInfo
.target
.Arch
; }
204 llvm::MachO::PlatformType
platform() const {
205 return platformInfo
.target
.Platform
;
209 extern std::unique_ptr
<Configuration
> config
;