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/StringRef.h"
16 #include "llvm/ADT/StringSet.h"
17 #include "llvm/BinaryFormat/MachO.h"
18 #include "llvm/Support/CachePruning.h"
19 #include "llvm/Support/GlobPattern.h"
20 #include "llvm/Support/VersionTuple.h"
21 #include "llvm/TextAPI/Architecture.h"
22 #include "llvm/TextAPI/Platform.h"
23 #include "llvm/TextAPI/Target.h"
31 struct SymbolPriorityEntry
;
33 using NamePair
= std::pair
<llvm::StringRef
, llvm::StringRef
>;
34 using SectionRenameMap
= llvm::DenseMap
<NamePair
, NamePair
>;
35 using SegmentRenameMap
= llvm::DenseMap
<llvm::StringRef
, llvm::StringRef
>;
38 llvm::MachO::Target target
;
39 llvm::VersionTuple minimum
;
40 llvm::VersionTuple sdk
;
43 inline uint32_t encodeVersion(const llvm::VersionTuple
&version
) {
44 return ((version
.getMajor() << 020) |
45 (version
.getMinor().getValueOr(0) << 010) |
46 version
.getSubminor().getValueOr(0));
49 enum class NamespaceKind
{
54 enum class UndefinedSymbolTreatment
{
70 llvm::StringRef segName
;
71 llvm::StringRef sectName
;
75 struct SegmentProtection
{
81 class SymbolPatterns
{
83 // GlobPattern can also match literals,
84 // but we prefer the O(1) lookup of DenseSet.
85 llvm::DenseSet
<llvm::CachedHashStringRef
> literals
;
86 std::vector
<llvm::GlobPattern
> globs
;
88 bool empty() const { return literals
.empty() && globs
.empty(); }
90 void insert(llvm::StringRef symbolName
);
91 bool matchLiteral(llvm::StringRef symbolName
) const;
92 bool matchGlob(llvm::StringRef symbolName
) const;
93 bool match(llvm::StringRef symbolName
) const;
96 struct Configuration
{
97 Symbol
*entry
= nullptr;
98 bool hasReexports
= false;
100 bool applicationExtension
= false;
101 bool archMultiple
= false;
102 bool exportDynamic
= false;
103 bool forceLoadObjC
= false;
104 bool forceLoadSwift
= false;
105 bool staticLink
= false;
106 bool implicitDylibs
= false;
108 bool headerPadMaxInstallNames
= false;
109 bool ltoNewPassManager
= LLVM_ENABLE_NEW_PASS_MANAGER
;
110 bool markDeadStrippableDylib
= false;
111 bool printDylibSearch
= false;
112 bool printEachFile
= false;
113 bool printWhyLoad
= false;
114 bool searchDylibsFirst
= false;
115 bool saveTemps
= false;
116 bool adhocCodesign
= false;
117 bool emitFunctionStarts
= false;
118 bool emitBitcodeBundle
= false;
119 bool emitDataInCodeInfo
= false;
120 bool emitEncryptionInfo
= false;
121 bool timeTraceEnabled
= false;
122 bool dataConst
= false;
123 bool dedupLiterals
= true;
125 uint32_t dylibCompatibilityVersion
= 0;
126 uint32_t dylibCurrentVersion
= 0;
127 uint32_t timeTraceGranularity
= 500;
129 std::string progName
;
131 // For `clang -arch arm64 -arch x86_64`, clang will:
132 // 1. invoke the linker twice, to write one temporary output per arch
133 // 2. invoke `lipo` to merge the two outputs into a single file
134 // `outputFile` is the name of the temporary file the linker writes to.
135 // `finalOutput `is the name of the file lipo writes to after the link.
136 llvm::StringRef outputFile
;
137 llvm::StringRef finalOutput
;
139 llvm::StringRef installName
;
140 llvm::StringRef mapFile
;
141 llvm::StringRef ltoObjPath
;
142 llvm::StringRef thinLTOJobs
;
143 llvm::StringRef umbrella
;
145 llvm::CachePruningPolicy thinLTOCachePolicy
;
146 llvm::StringRef thinLTOCacheDir
;
147 bool deadStripDylibs
= false;
148 bool demangle
= false;
149 bool deadStrip
= false;
150 PlatformInfo platformInfo
;
151 NamespaceKind namespaceKind
= NamespaceKind::twolevel
;
152 UndefinedSymbolTreatment undefinedSymbolTreatment
=
153 UndefinedSymbolTreatment::error
;
154 ICFLevel icfLevel
= ICFLevel::none
;
155 llvm::MachO::HeaderFileType outputType
;
156 std::vector
<llvm::StringRef
> systemLibraryRoots
;
157 std::vector
<llvm::StringRef
> librarySearchPaths
;
158 std::vector
<llvm::StringRef
> frameworkSearchPaths
;
159 std::vector
<llvm::StringRef
> runtimePaths
;
160 std::vector
<std::string
> astPaths
;
161 std::vector
<Symbol
*> explicitUndefineds
;
162 llvm::StringSet
<> explicitDynamicLookups
;
163 // There are typically few custom sectionAlignments or segmentProtections,
164 // so use a vector instead of a map.
165 std::vector
<SectionAlign
> sectionAlignments
;
166 std::vector
<SegmentProtection
> segmentProtections
;
168 llvm::DenseMap
<llvm::StringRef
, SymbolPriorityEntry
> priorities
;
169 SectionRenameMap sectionRenameMap
;
170 SegmentRenameMap segmentRenameMap
;
172 SymbolPatterns exportedSymbols
;
173 SymbolPatterns unexportedSymbols
;
175 bool zeroModTime
= false;
177 llvm::MachO::Architecture
arch() const { return platformInfo
.target
.Arch
; }
179 llvm::MachO::PlatformKind
platform() const {
180 return platformInfo
.target
.Platform
;
184 // The symbol with the highest priority should be ordered first in the output
185 // section (modulo input section contiguity constraints). Using priority
186 // (highest first) instead of order (lowest first) has the convenient property
187 // that the default-constructed zero priority -- for symbols/sections without a
188 // user-defined order -- naturally ends up putting them at the end of the
190 struct SymbolPriorityEntry
{
191 // The priority given to a matching symbol, regardless of which object file
192 // it originated from.
193 size_t anyObjectFile
= 0;
194 // The priority given to a matching symbol from a particular object file.
195 llvm::DenseMap
<llvm::StringRef
, size_t> objectFiles
;
198 extern Configuration
*config
;