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/SmallVector.h"
15 #include "llvm/ADT/StringMap.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Object/COFF.h"
18 #include "llvm/Support/CachePruning.h"
19 #include "llvm/Support/VirtualFileSystem.h"
27 using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN
;
28 using llvm::COFF::WindowsSubsystem
;
29 using llvm::StringRef
;
30 class DefinedAbsolute
;
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 ARM64EC
= llvm::COFF::IMAGE_FILE_MACHINE_ARM64EC
;
40 static const auto ARM64X
= llvm::COFF::IMAGE_FILE_MACHINE_ARM64X
;
41 static const auto ARMNT
= llvm::COFF::IMAGE_FILE_MACHINE_ARMNT
;
42 static const auto I386
= llvm::COFF::IMAGE_FILE_MACHINE_I386
;
44 enum class ExportSource
{
51 enum class EmitKind
{ Obj
, LLVM
, ASM
};
53 // Represents an /export option.
55 StringRef name
; // N in /export:N or /export:E=N
56 StringRef extName
; // E in /export:E=N
57 StringRef exportAs
; // E in /export:N,EXPORTAS,E
58 StringRef importName
; // GNU specific: N in "othername == N"
59 Symbol
*sym
= nullptr;
63 bool isPrivate
= false;
64 bool constant
= false;
66 // If an export is a form of /export:foo=dllname.bar, that means
67 // that foo should be exported as an alias to bar in the DLL.
68 // forwardTo is set to "dllname.bar" part. Usually empty.
70 StringChunk
*forwardChunk
= nullptr;
72 ExportSource source
= ExportSource::Unset
;
74 StringRef exportName
; // Name in DLL
76 bool operator==(const Export
&e
) const {
77 return (name
== e
.name
&& extName
== e
.extName
&& exportAs
== e
.exportAs
&&
78 importName
== e
.importName
&& ordinal
== e
.ordinal
&&
79 noname
== e
.noname
&& data
== e
.data
&& isPrivate
== e
.isPrivate
);
83 enum class DebugType
{
85 CV
= 0x1, /// CodeView
86 PData
= 0x2, /// Procedure Data
87 Fixup
= 0x4, /// Relocation Table
92 CF
= 0x1, /// Emit gfids tables
93 LongJmp
= 0x2, /// Emit longjmp tables
94 EHCont
= 0x4, /// Emit ehcont tables
95 All
= 0x7 /// Enable all protections
100 Safe
, // Safe ICF for all sections.
101 All
, // Aggressive ICF for code, but safe ICF for data, similar to MSVC's
105 enum class BuildIDHash
{
111 // Global configuration.
112 struct Configuration
{
113 enum ManifestKind
{ Default
, SideBySide
, Embed
, No
};
114 bool is64() const { return llvm::COFF::is64Bit(machine
); }
116 llvm::COFF::MachineTypes machine
= IMAGE_FILE_MACHINE_UNKNOWN
;
118 bool verbose
= false;
119 WindowsSubsystem subsystem
= llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN
;
120 Symbol
*entry
= nullptr;
121 bool noEntry
= false;
122 std::string outputFile
;
123 std::string importName
;
124 bool demangle
= true;
126 ICFLevel doICF
= ICFLevel::None
;
128 bool relocatable
= true;
129 bool forceMultiple
= false;
130 bool forceMultipleRes
= false;
131 bool forceUnresolved
= false;
133 bool includeDwarfChunks
= false;
134 bool debugGHashes
= false;
135 bool writeSymtab
= false;
137 bool driverUponly
= false;
138 bool driverWdm
= false;
139 bool showTiming
= false;
140 bool showSummary
= false;
141 bool printSearchPaths
= false;
142 unsigned debugTypes
= static_cast<unsigned>(DebugType::None
);
143 llvm::SmallVector
<llvm::StringRef
, 0> mllvmOpts
;
144 std::vector
<std::string
> natvisFiles
;
145 llvm::StringMap
<std::string
> namedStreams
;
146 llvm::SmallString
<128> pdbAltPath
;
147 int pdbPageSize
= 4096;
148 llvm::SmallString
<128> pdbPath
;
149 llvm::SmallString
<128> pdbSourcePath
;
150 std::vector
<llvm::StringRef
> argv
;
152 // Symbols in this set are considered as live by the garbage collector.
153 std::vector
<Symbol
*> gcroot
;
155 std::set
<std::string
> noDefaultLibs
;
156 bool noDefaultLibAll
= false;
158 // True if we are creating a DLL.
161 bool noimplib
= false;
162 std::vector
<Export
> exports
;
163 bool hadExplicitExports
;
164 std::set
<std::string
> delayLoads
;
165 std::map
<std::string
, int> dllOrder
;
166 Symbol
*delayLoadHelper
= nullptr;
168 bool saveTemps
= false;
171 int guardCF
= GuardCFLevel::Off
;
174 bool safeSEH
= false;
175 Symbol
*sehTable
= nullptr;
176 Symbol
*sehCount
= nullptr;
179 // Used for /opt:lldlto=N
181 // Used for /opt:lldltocgo=N
182 std::optional
<unsigned> ltoCgo
;
184 // Used for /opt:lldltojobs=N
185 std::string thinLTOJobs
;
186 // Used for /opt:lldltopartitions=N
187 unsigned ltoPartitions
= 1;
189 // Used for /lldltocache=path
191 // Used for /lldltocachepolicy=policy
192 llvm::CachePruningPolicy ltoCachePolicy
;
194 // Used for /opt:[no]ltodebugpassmanager
195 bool ltoDebugPassManager
= false;
197 // Used for /merge:from=to (e.g. /merge:.rdata=.text)
198 std::map
<StringRef
, StringRef
> merge
;
200 // Used for /section=.name,{DEKPRSW} to set section attributes.
201 std::map
<StringRef
, uint32_t> section
;
203 // Options for manifest files.
204 ManifestKind manifest
= Default
;
206 llvm::SetVector
<StringRef
> manifestDependencies
;
207 bool manifestUAC
= true;
208 std::vector
<std::string
> manifestInput
;
209 StringRef manifestLevel
= "'asInvoker'";
210 StringRef manifestUIAccess
= "'false'";
211 StringRef manifestFile
;
216 // Used for /aligncomm.
217 std::map
<std::string
, int> alignComm
;
219 // Used for /failifmismatch.
220 std::map
<StringRef
, std::pair
<StringRef
, InputFile
*>> mustMatch
;
222 // Used for /alternatename.
223 std::map
<StringRef
, StringRef
> alternateNames
;
226 llvm::StringMap
<int> order
;
229 std::string lldmapFile
;
234 // Used for /mapinfo.
235 bool mapInfo
= false;
237 // Used for /thinlto-index-only:
238 llvm::StringRef thinLTOIndexOnlyArg
;
240 // Used for /thinlto-prefix-replace:
241 // Replace the prefix in paths generated for ThinLTO, replacing
242 // thinLTOPrefixReplaceOld with thinLTOPrefixReplaceNew. If
243 // thinLTOPrefixReplaceNativeObject is defined, replace the prefix of object
244 // file paths written to the response file given in the
245 // --thinlto-index-only=${response} option with
246 // thinLTOPrefixReplaceNativeObject, instead of thinLTOPrefixReplaceNew.
247 llvm::StringRef thinLTOPrefixReplaceOld
;
248 llvm::StringRef thinLTOPrefixReplaceNew
;
249 llvm::StringRef thinLTOPrefixReplaceNativeObject
;
251 // Used for /thinlto-object-suffix-replace:
252 std::pair
<llvm::StringRef
, llvm::StringRef
> thinLTOObjectSuffixReplace
;
254 // Used for /lto-obj-path:
255 llvm::StringRef ltoObjPath
;
257 // Used for /lto-cs-profile-generate:
258 bool ltoCSProfileGenerate
= false;
260 // Used for /lto-cs-profile-path
261 llvm::StringRef ltoCSProfileFile
;
263 // Used for /lto-pgo-warn-mismatch:
264 bool ltoPGOWarnMismatch
= true;
266 // Used for /lto-sample-profile:
267 llvm::StringRef ltoSampleProfileName
;
269 // Used for /call-graph-ordering-file:
270 llvm::MapVector
<std::pair
<const SectionChunk
*, const SectionChunk
*>,
273 bool callGraphProfileSort
= false;
275 // Used for /print-symbol-order:
276 StringRef printSymbolOrder
;
278 // Used for /vfsoverlay:
279 std::unique_ptr
<llvm::vfs::FileSystem
> vfs
;
281 uint64_t align
= 4096;
282 uint64_t imageBase
= -1;
283 uint64_t fileAlign
= 512;
284 uint64_t stackReserve
= 1024 * 1024;
285 uint64_t stackCommit
= 4096;
286 uint64_t heapReserve
= 1024 * 1024;
287 uint64_t heapCommit
= 4096;
288 uint32_t majorImageVersion
= 0;
289 uint32_t minorImageVersion
= 0;
290 // If changing the default os/subsys version here, update the default in
291 // the MinGW driver accordingly.
292 uint32_t majorOSVersion
= 6;
293 uint32_t minorOSVersion
= 0;
294 uint32_t majorSubsystemVersion
= 6;
295 uint32_t minorSubsystemVersion
= 0;
296 uint32_t timestamp
= 0;
297 uint32_t functionPadMin
= 0;
298 uint32_t timeTraceGranularity
= 0;
299 uint16_t dependentLoadFlags
= 0;
300 bool dynamicBase
= true;
301 bool allowBind
= true;
302 bool cetCompat
= false;
303 bool nxCompat
= true;
304 bool allowIsolation
= true;
305 bool terminalServerAware
= true;
306 bool largeAddressAware
= false;
307 bool highEntropyVA
= false;
308 bool appContainer
= false;
310 bool warnMissingOrderSymbol
= true;
311 bool warnLocallyDefinedImported
= true;
312 bool warnDebugInfoUnusable
= true;
313 bool warnLongSectionNames
= true;
314 bool warnStdcallFixup
= true;
315 bool incremental
= true;
316 bool integrityCheck
= false;
319 bool swaprunCD
= false;
320 bool swaprunNet
= false;
321 bool thinLTOEmitImportsFiles
;
322 bool thinLTOIndexOnly
;
323 bool timeTraceEnabled
= false;
324 bool autoImport
= false;
325 bool pseudoRelocs
= false;
326 bool stdcallFixup
= false;
327 bool writeCheckSum
= false;
328 EmitKind emit
= EmitKind::Obj
;
329 bool allowDuplicateWeak
= false;
330 BuildIDHash buildIDHash
= BuildIDHash::None
;
333 } // namespace lld::coff