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;
167 Symbol
*arm64ECIcallHelper
= nullptr;
169 llvm::DenseSet
<llvm::StringRef
> saveTempsArgs
;
172 int guardCF
= GuardCFLevel::Off
;
175 bool safeSEH
= false;
176 Symbol
*sehTable
= nullptr;
177 Symbol
*sehCount
= nullptr;
180 // Used for /opt:lldlto=N
182 // Used for /opt:lldltocgo=N
183 std::optional
<unsigned> ltoCgo
;
185 // Used for /opt:lldltojobs=N
186 std::string thinLTOJobs
;
187 // Used for /opt:lldltopartitions=N
188 unsigned ltoPartitions
= 1;
190 // Used for /lldltocache=path
192 // Used for /lldltocachepolicy=policy
193 llvm::CachePruningPolicy ltoCachePolicy
;
195 // Used for /opt:[no]ltodebugpassmanager
196 bool ltoDebugPassManager
= false;
198 // Used for /merge:from=to (e.g. /merge:.rdata=.text)
199 std::map
<StringRef
, StringRef
> merge
;
201 // Used for /section=.name,{DEKPRSW} to set section attributes.
202 std::map
<StringRef
, uint32_t> section
;
204 // Options for manifest files.
205 ManifestKind manifest
= Default
;
207 llvm::SetVector
<StringRef
> manifestDependencies
;
208 bool manifestUAC
= true;
209 std::vector
<std::string
> manifestInput
;
210 StringRef manifestLevel
= "'asInvoker'";
211 StringRef manifestUIAccess
= "'false'";
212 StringRef manifestFile
;
217 // Used for /aligncomm.
218 std::map
<std::string
, int> alignComm
;
220 // Used for /failifmismatch.
221 std::map
<StringRef
, std::pair
<StringRef
, InputFile
*>> mustMatch
;
223 // Used for /alternatename.
224 std::map
<StringRef
, StringRef
> alternateNames
;
227 llvm::StringMap
<int> order
;
230 std::string lldmapFile
;
235 // Used for /mapinfo.
236 bool mapInfo
= false;
238 // Used for /thinlto-index-only:
239 llvm::StringRef thinLTOIndexOnlyArg
;
241 // Used for /thinlto-prefix-replace:
242 // Replace the prefix in paths generated for ThinLTO, replacing
243 // thinLTOPrefixReplaceOld with thinLTOPrefixReplaceNew. If
244 // thinLTOPrefixReplaceNativeObject is defined, replace the prefix of object
245 // file paths written to the response file given in the
246 // --thinlto-index-only=${response} option with
247 // thinLTOPrefixReplaceNativeObject, instead of thinLTOPrefixReplaceNew.
248 llvm::StringRef thinLTOPrefixReplaceOld
;
249 llvm::StringRef thinLTOPrefixReplaceNew
;
250 llvm::StringRef thinLTOPrefixReplaceNativeObject
;
252 // Used for /thinlto-object-suffix-replace:
253 std::pair
<llvm::StringRef
, llvm::StringRef
> thinLTOObjectSuffixReplace
;
255 // Used for /lto-obj-path:
256 llvm::StringRef ltoObjPath
;
258 // Used for /lto-cs-profile-generate:
259 bool ltoCSProfileGenerate
= false;
261 // Used for /lto-cs-profile-path
262 llvm::StringRef ltoCSProfileFile
;
264 // Used for /lto-pgo-warn-mismatch:
265 bool ltoPGOWarnMismatch
= true;
267 // Used for /lto-sample-profile:
268 llvm::StringRef ltoSampleProfileName
;
270 // Used for /call-graph-ordering-file:
271 llvm::MapVector
<std::pair
<const SectionChunk
*, const SectionChunk
*>,
274 bool callGraphProfileSort
= false;
276 // Used for /print-symbol-order:
277 StringRef printSymbolOrder
;
279 // Used for /vfsoverlay:
280 std::unique_ptr
<llvm::vfs::FileSystem
> vfs
;
282 uint64_t align
= 4096;
283 uint64_t imageBase
= -1;
284 uint64_t fileAlign
= 512;
285 uint64_t stackReserve
= 1024 * 1024;
286 uint64_t stackCommit
= 4096;
287 uint64_t heapReserve
= 1024 * 1024;
288 uint64_t heapCommit
= 4096;
289 uint32_t majorImageVersion
= 0;
290 uint32_t minorImageVersion
= 0;
291 // If changing the default os/subsys version here, update the default in
292 // the MinGW driver accordingly.
293 uint32_t majorOSVersion
= 6;
294 uint32_t minorOSVersion
= 0;
295 uint32_t majorSubsystemVersion
= 6;
296 uint32_t minorSubsystemVersion
= 0;
297 uint32_t timestamp
= 0;
298 uint32_t functionPadMin
= 0;
299 uint32_t timeTraceGranularity
= 0;
300 uint16_t dependentLoadFlags
= 0;
301 bool dynamicBase
= true;
302 bool allowBind
= true;
303 bool cetCompat
= false;
304 bool nxCompat
= true;
305 bool allowIsolation
= true;
306 bool terminalServerAware
= true;
307 bool largeAddressAware
= false;
308 bool highEntropyVA
= false;
309 bool appContainer
= false;
311 bool warnMissingOrderSymbol
= true;
312 bool warnLocallyDefinedImported
= true;
313 bool warnDebugInfoUnusable
= true;
314 bool warnLongSectionNames
= true;
315 bool warnStdcallFixup
= true;
316 bool incremental
= true;
317 bool integrityCheck
= false;
320 bool swaprunCD
= false;
321 bool swaprunNet
= false;
322 bool thinLTOEmitImportsFiles
;
323 bool thinLTOIndexOnly
;
324 bool timeTraceEnabled
= false;
325 bool autoImport
= false;
326 bool pseudoRelocs
= false;
327 bool stdcallFixup
= false;
328 bool writeCheckSum
= false;
329 EmitKind emit
= EmitKind::Obj
;
330 bool allowDuplicateWeak
= false;
331 BuildIDHash buildIDHash
= BuildIDHash::None
;
334 } // namespace lld::coff