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_COFF_CONFIG_H
10 #define LLD_COFF_CONFIG_H
12 #include "llvm/ADT/MapVector.h"
13 #include "llvm/ADT/SetVector.h"
14 #include "llvm/ADT/StringMap.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Object/COFF.h"
17 #include "llvm/Support/CachePruning.h"
26 using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN
;
27 using llvm::COFF::WindowsSubsystem
;
28 using llvm::StringRef
;
29 class DefinedAbsolute
;
30 class DefinedRelative
;
37 static const auto AMD64
= llvm::COFF::IMAGE_FILE_MACHINE_AMD64
;
38 static const auto ARM64
= llvm::COFF::IMAGE_FILE_MACHINE_ARM64
;
39 static const auto ARMNT
= llvm::COFF::IMAGE_FILE_MACHINE_ARMNT
;
40 static const auto I386
= llvm::COFF::IMAGE_FILE_MACHINE_I386
;
42 // Represents an /export option.
44 StringRef name
; // N in /export:N or /export:E=N
45 StringRef extName
; // E in /export:E=N
46 StringRef aliasTarget
; // GNU specific: N in "alias == N"
47 Symbol
*sym
= nullptr;
51 bool isPrivate
= false;
52 bool constant
= false;
54 // If an export is a form of /export:foo=dllname.bar, that means
55 // that foo should be exported as an alias to bar in the DLL.
56 // forwardTo is set to "dllname.bar" part. Usually empty.
58 StringChunk
*forwardChunk
= nullptr;
60 // True if this /export option was in .drectves section.
61 bool directives
= false;
63 StringRef exportName
; // Name in DLL
65 bool operator==(const Export
&e
) {
66 return (name
== e
.name
&& extName
== e
.extName
&&
67 aliasTarget
== e
.aliasTarget
&&
68 ordinal
== e
.ordinal
&& noname
== e
.noname
&&
69 data
== e
.data
&& isPrivate
== e
.isPrivate
);
73 enum class DebugType
{
75 CV
= 0x1, /// CodeView
76 PData
= 0x2, /// Procedure Data
77 Fixup
= 0x4, /// Relocation Table
82 CF
= 0x1, /// Emit gfids tables
83 LongJmp
= 0x2, /// Emit longjmp tables
84 EHCont
= 0x4, /// Emit ehcont tables
85 All
= 0x7 /// Enable all protections
90 Safe
, // Safe ICF for all sections.
91 All
, // Aggressive ICF for code, but safe ICF for data, similar to MSVC's
95 // Global configuration.
96 struct Configuration
{
97 enum ManifestKind
{ Default
, SideBySide
, Embed
, No
};
98 bool is64() { return machine
== AMD64
|| machine
== ARM64
; }
100 llvm::COFF::MachineTypes machine
= IMAGE_FILE_MACHINE_UNKNOWN
;
102 bool verbose
= false;
103 WindowsSubsystem subsystem
= llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN
;
104 Symbol
*entry
= nullptr;
105 bool noEntry
= false;
106 std::string outputFile
;
107 std::string importName
;
108 bool demangle
= true;
110 ICFLevel doICF
= ICFLevel::None
;
112 bool relocatable
= true;
113 bool forceMultiple
= false;
114 bool forceMultipleRes
= false;
115 bool forceUnresolved
= false;
117 bool debugDwarf
= false;
118 bool debugGHashes
= false;
119 bool debugSymtab
= false;
121 bool driverUponly
= false;
122 bool driverWdm
= false;
123 bool showTiming
= false;
124 bool showSummary
= false;
125 unsigned debugTypes
= static_cast<unsigned>(DebugType::None
);
126 std::vector
<std::string
> natvisFiles
;
127 llvm::StringMap
<std::string
> namedStreams
;
128 llvm::SmallString
<128> pdbAltPath
;
129 int pdbPageSize
= 4096;
130 llvm::SmallString
<128> pdbPath
;
131 llvm::SmallString
<128> pdbSourcePath
;
132 std::vector
<llvm::StringRef
> argv
;
134 // Symbols in this set are considered as live by the garbage collector.
135 std::vector
<Symbol
*> gcroot
;
137 std::set
<std::string
> noDefaultLibs
;
138 bool noDefaultLibAll
= false;
140 // True if we are creating a DLL.
143 std::vector
<Export
> exports
;
144 bool hadExplicitExports
;
145 std::set
<std::string
> delayLoads
;
146 std::map
<std::string
, int> dllOrder
;
147 Symbol
*delayLoadHelper
= nullptr;
149 bool saveTemps
= false;
152 int guardCF
= GuardCFLevel::Off
;
155 bool safeSEH
= false;
156 Symbol
*sehTable
= nullptr;
157 Symbol
*sehCount
= nullptr;
160 // Used for /opt:lldlto=N
163 // Used for /opt:lldltojobs=N
164 std::string thinLTOJobs
;
165 // Used for /opt:lldltopartitions=N
166 unsigned ltoPartitions
= 1;
168 // Used for /opt:lldltocache=path
170 // Used for /opt:lldltocachepolicy=policy
171 llvm::CachePruningPolicy ltoCachePolicy
;
173 // Used for /opt:[no]ltonewpassmanager
174 bool ltoNewPassManager
= false;
175 // Used for /opt:[no]ltodebugpassmanager
176 bool ltoDebugPassManager
= false;
178 // Used for /merge:from=to (e.g. /merge:.rdata=.text)
179 std::map
<StringRef
, StringRef
> merge
;
181 // Used for /section=.name,{DEKPRSW} to set section attributes.
182 std::map
<StringRef
, uint32_t> section
;
184 // Options for manifest files.
185 ManifestKind manifest
= Default
;
187 llvm::SetVector
<StringRef
> manifestDependencies
;
188 bool manifestUAC
= true;
189 std::vector
<std::string
> manifestInput
;
190 StringRef manifestLevel
= "'asInvoker'";
191 StringRef manifestUIAccess
= "'false'";
192 StringRef manifestFile
;
194 // Used for /aligncomm.
195 std::map
<std::string
, int> alignComm
;
197 // Used for /failifmismatch.
198 std::map
<StringRef
, std::pair
<StringRef
, InputFile
*>> mustMatch
;
200 // Used for /alternatename.
201 std::map
<StringRef
, StringRef
> alternateNames
;
204 llvm::StringMap
<int> order
;
207 std::string lldmapFile
;
212 // Used for /thinlto-index-only:
213 llvm::StringRef thinLTOIndexOnlyArg
;
215 // Used for /thinlto-object-prefix-replace:
216 std::pair
<llvm::StringRef
, llvm::StringRef
> thinLTOPrefixReplace
;
218 // Used for /thinlto-object-suffix-replace:
219 std::pair
<llvm::StringRef
, llvm::StringRef
> thinLTOObjectSuffixReplace
;
221 // Used for /lto-obj-path:
222 llvm::StringRef ltoObjPath
;
224 // Used for /lto-cs-profile-generate:
225 bool ltoCSProfileGenerate
= false;
227 // Used for /lto-cs-profile-path
228 llvm::StringRef ltoCSProfileFile
;
230 // Used for /lto-pgo-warn-mismatch:
231 bool ltoPGOWarnMismatch
= true;
233 // Used for /call-graph-ordering-file:
234 llvm::MapVector
<std::pair
<const SectionChunk
*, const SectionChunk
*>,
237 bool callGraphProfileSort
= false;
239 // Used for /print-symbol-order:
240 StringRef printSymbolOrder
;
242 uint64_t align
= 4096;
243 uint64_t imageBase
= -1;
244 uint64_t fileAlign
= 512;
245 uint64_t stackReserve
= 1024 * 1024;
246 uint64_t stackCommit
= 4096;
247 uint64_t heapReserve
= 1024 * 1024;
248 uint64_t heapCommit
= 4096;
249 uint32_t majorImageVersion
= 0;
250 uint32_t minorImageVersion
= 0;
251 // If changing the default os/subsys version here, update the default in
252 // the MinGW driver accordingly.
253 uint32_t majorOSVersion
= 6;
254 uint32_t minorOSVersion
= 0;
255 uint32_t majorSubsystemVersion
= 6;
256 uint32_t minorSubsystemVersion
= 0;
257 uint32_t timestamp
= 0;
258 uint32_t functionPadMin
= 0;
259 bool dynamicBase
= true;
260 bool allowBind
= true;
261 bool cetCompat
= false;
262 bool nxCompat
= true;
263 bool allowIsolation
= true;
264 bool terminalServerAware
= true;
265 bool largeAddressAware
= false;
266 bool highEntropyVA
= false;
267 bool appContainer
= false;
269 bool warnMissingOrderSymbol
= true;
270 bool warnLocallyDefinedImported
= true;
271 bool warnDebugInfoUnusable
= true;
272 bool warnLongSectionNames
= true;
273 bool warnStdcallFixup
= true;
274 bool incremental
= true;
275 bool integrityCheck
= false;
278 bool swaprunCD
= false;
279 bool swaprunNet
= false;
280 bool thinLTOEmitImportsFiles
;
281 bool thinLTOIndexOnly
;
282 bool autoImport
= false;
283 bool pseudoRelocs
= false;
284 bool stdcallFixup
= false;
287 extern std::unique_ptr
<Configuration
> config
;