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/StringMap.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Object/COFF.h"
16 #include "llvm/Support/CachePruning.h"
25 using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN
;
26 using llvm::COFF::WindowsSubsystem
;
27 using llvm::StringRef
;
28 class DefinedAbsolute
;
29 class DefinedRelative
;
36 static const auto AMD64
= llvm::COFF::IMAGE_FILE_MACHINE_AMD64
;
37 static const auto ARM64
= llvm::COFF::IMAGE_FILE_MACHINE_ARM64
;
38 static const auto ARMNT
= llvm::COFF::IMAGE_FILE_MACHINE_ARMNT
;
39 static const auto I386
= llvm::COFF::IMAGE_FILE_MACHINE_I386
;
41 // Represents an /export option.
43 StringRef name
; // N in /export:N or /export:E=N
44 StringRef extName
; // E in /export:E=N
45 Symbol
*sym
= nullptr;
49 bool isPrivate
= false;
50 bool constant
= false;
52 // If an export is a form of /export:foo=dllname.bar, that means
53 // that foo should be exported as an alias to bar in the DLL.
54 // forwardTo is set to "dllname.bar" part. Usually empty.
56 StringChunk
*forwardChunk
= nullptr;
58 // True if this /export option was in .drectves section.
59 bool directives
= false;
61 StringRef exportName
; // Name in DLL
63 bool operator==(const Export
&e
) {
64 return (name
== e
.name
&& extName
== e
.extName
&&
65 ordinal
== e
.ordinal
&& noname
== e
.noname
&&
66 data
== e
.data
&& isPrivate
== e
.isPrivate
);
70 enum class DebugType
{
72 CV
= 0x1, /// CodeView
73 PData
= 0x2, /// Procedure Data
74 Fixup
= 0x4, /// Relocation Table
79 CF
= 0x1, /// Emit gfids tables
80 LongJmp
= 0x2, /// Emit longjmp tables
81 EHCont
= 0x4, /// Emit ehcont tables
82 All
= 0x7 /// Enable all protections
87 Safe
, // Safe ICF for all sections.
88 All
, // Aggressive ICF for code, but safe ICF for data, similar to MSVC's
92 // Global configuration.
93 struct Configuration
{
94 enum ManifestKind
{ SideBySide
, Embed
, No
};
95 bool is64() { return machine
== AMD64
|| machine
== ARM64
; }
97 llvm::COFF::MachineTypes machine
= IMAGE_FILE_MACHINE_UNKNOWN
;
100 WindowsSubsystem subsystem
= llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN
;
101 Symbol
*entry
= nullptr;
102 bool noEntry
= false;
103 std::string outputFile
;
104 std::string importName
;
105 bool demangle
= true;
107 ICFLevel doICF
= ICFLevel::None
;
109 bool relocatable
= true;
110 bool forceMultiple
= false;
111 bool forceMultipleRes
= false;
112 bool forceUnresolved
= false;
114 bool debugDwarf
= false;
115 bool debugGHashes
= false;
116 bool debugSymtab
= false;
118 bool driverUponly
= false;
119 bool driverWdm
= false;
120 bool showTiming
= false;
121 bool showSummary
= false;
122 unsigned debugTypes
= static_cast<unsigned>(DebugType::None
);
123 std::vector
<std::string
> natvisFiles
;
124 llvm::StringMap
<std::string
> namedStreams
;
125 llvm::SmallString
<128> pdbAltPath
;
126 llvm::SmallString
<128> pdbPath
;
127 llvm::SmallString
<128> pdbSourcePath
;
128 std::vector
<llvm::StringRef
> argv
;
130 // Symbols in this set are considered as live by the garbage collector.
131 std::vector
<Symbol
*> gcroot
;
133 std::set
<std::string
> noDefaultLibs
;
134 bool noDefaultLibAll
= false;
136 // True if we are creating a DLL.
139 std::vector
<Export
> exports
;
140 bool hadExplicitExports
;
141 std::set
<std::string
> delayLoads
;
142 std::map
<std::string
, int> dllOrder
;
143 Symbol
*delayLoadHelper
= nullptr;
145 bool saveTemps
= false;
148 int guardCF
= GuardCFLevel::Off
;
151 bool safeSEH
= false;
152 Symbol
*sehTable
= nullptr;
153 Symbol
*sehCount
= nullptr;
156 // Used for /opt:lldlto=N
159 // Used for /opt:lldltojobs=N
160 std::string thinLTOJobs
;
161 // Used for /opt:lldltopartitions=N
162 unsigned ltoPartitions
= 1;
164 // Used for /opt:lldltocache=path
166 // Used for /opt:lldltocachepolicy=policy
167 llvm::CachePruningPolicy ltoCachePolicy
;
169 // Used for /opt:[no]ltonewpassmanager
170 bool ltoNewPassManager
= false;
171 // Used for /opt:[no]ltodebugpassmanager
172 bool ltoDebugPassManager
= false;
174 // Used for /merge:from=to (e.g. /merge:.rdata=.text)
175 std::map
<StringRef
, StringRef
> merge
;
177 // Used for /section=.name,{DEKPRSW} to set section attributes.
178 std::map
<StringRef
, uint32_t> section
;
180 // Options for manifest files.
181 ManifestKind manifest
= No
;
183 StringRef manifestDependency
;
184 bool manifestUAC
= true;
185 std::vector
<std::string
> manifestInput
;
186 StringRef manifestLevel
= "'asInvoker'";
187 StringRef manifestUIAccess
= "'false'";
188 StringRef manifestFile
;
190 // Used for /aligncomm.
191 std::map
<std::string
, int> alignComm
;
193 // Used for /failifmismatch.
194 std::map
<StringRef
, std::pair
<StringRef
, InputFile
*>> mustMatch
;
196 // Used for /alternatename.
197 std::map
<StringRef
, StringRef
> alternateNames
;
200 llvm::StringMap
<int> order
;
203 std::string lldmapFile
;
208 // Used for /thinlto-index-only:
209 llvm::StringRef thinLTOIndexOnlyArg
;
211 // Used for /thinlto-object-prefix-replace:
212 std::pair
<llvm::StringRef
, llvm::StringRef
> thinLTOPrefixReplace
;
214 // Used for /thinlto-object-suffix-replace:
215 std::pair
<llvm::StringRef
, llvm::StringRef
> thinLTOObjectSuffixReplace
;
217 // Used for /lto-obj-path:
218 llvm::StringRef ltoObjPath
;
220 // Used for /lto-cs-profile-generate:
221 bool ltoCSProfileGenerate
= false;
223 // Used for /lto-cs-profile-path
224 llvm::StringRef ltoCSProfileFile
;
226 // Used for /lto-pgo-warn-mismatch:
227 bool ltoPGOWarnMismatch
= true;
229 // Used for /call-graph-ordering-file:
230 llvm::MapVector
<std::pair
<const SectionChunk
*, const SectionChunk
*>,
233 bool callGraphProfileSort
= false;
235 // Used for /print-symbol-order:
236 StringRef printSymbolOrder
;
238 uint64_t align
= 4096;
239 uint64_t imageBase
= -1;
240 uint64_t fileAlign
= 512;
241 uint64_t stackReserve
= 1024 * 1024;
242 uint64_t stackCommit
= 4096;
243 uint64_t heapReserve
= 1024 * 1024;
244 uint64_t heapCommit
= 4096;
245 uint32_t majorImageVersion
= 0;
246 uint32_t minorImageVersion
= 0;
247 // If changing the default os/subsys version here, update the default in
248 // the MinGW driver accordingly.
249 uint32_t majorOSVersion
= 6;
250 uint32_t minorOSVersion
= 0;
251 uint32_t majorSubsystemVersion
= 6;
252 uint32_t minorSubsystemVersion
= 0;
253 uint32_t timestamp
= 0;
254 uint32_t functionPadMin
= 0;
255 bool dynamicBase
= true;
256 bool allowBind
= true;
257 bool cetCompat
= false;
258 bool nxCompat
= true;
259 bool allowIsolation
= true;
260 bool terminalServerAware
= true;
261 bool largeAddressAware
= false;
262 bool highEntropyVA
= false;
263 bool appContainer
= false;
265 bool warnMissingOrderSymbol
= true;
266 bool warnLocallyDefinedImported
= true;
267 bool warnDebugInfoUnusable
= true;
268 bool warnLongSectionNames
= true;
269 bool warnStdcallFixup
= true;
270 bool incremental
= true;
271 bool integrityCheck
= false;
274 bool swaprunCD
= false;
275 bool swaprunNet
= false;
276 bool thinLTOEmitImportsFiles
;
277 bool thinLTOIndexOnly
;
278 bool autoImport
= false;
279 bool pseudoRelocs
= false;
280 bool stdcallFixup
= false;
283 extern Configuration
*config
;