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 // Represents an /export option.
53 StringRef name
; // N in /export:N or /export:E=N
54 StringRef extName
; // E in /export:E=N
55 StringRef aliasTarget
; // GNU specific: N in "alias == N"
56 Symbol
*sym
= nullptr;
60 bool isPrivate
= false;
61 bool constant
= false;
63 // If an export is a form of /export:foo=dllname.bar, that means
64 // that foo should be exported as an alias to bar in the DLL.
65 // forwardTo is set to "dllname.bar" part. Usually empty.
67 StringChunk
*forwardChunk
= nullptr;
69 ExportSource source
= ExportSource::Unset
;
71 StringRef exportName
; // Name in DLL
73 bool operator==(const Export
&e
) {
74 return (name
== e
.name
&& extName
== e
.extName
&&
75 aliasTarget
== e
.aliasTarget
&&
76 ordinal
== e
.ordinal
&& noname
== e
.noname
&&
77 data
== e
.data
&& isPrivate
== e
.isPrivate
);
81 enum class DebugType
{
83 CV
= 0x1, /// CodeView
84 PData
= 0x2, /// Procedure Data
85 Fixup
= 0x4, /// Relocation Table
90 CF
= 0x1, /// Emit gfids tables
91 LongJmp
= 0x2, /// Emit longjmp tables
92 EHCont
= 0x4, /// Emit ehcont tables
93 All
= 0x7 /// Enable all protections
98 Safe
, // Safe ICF for all sections.
99 All
, // Aggressive ICF for code, but safe ICF for data, similar to MSVC's
103 // Global configuration.
104 struct Configuration
{
105 enum ManifestKind
{ Default
, SideBySide
, Embed
, No
};
106 bool is64() const { return llvm::COFF::is64Bit(machine
); }
108 llvm::COFF::MachineTypes machine
= IMAGE_FILE_MACHINE_UNKNOWN
;
110 bool verbose
= false;
111 WindowsSubsystem subsystem
= llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN
;
112 Symbol
*entry
= nullptr;
113 bool noEntry
= false;
114 std::string outputFile
;
115 std::string importName
;
116 bool demangle
= true;
118 ICFLevel doICF
= ICFLevel::None
;
120 bool relocatable
= true;
121 bool forceMultiple
= false;
122 bool forceMultipleRes
= false;
123 bool forceUnresolved
= false;
125 bool debugDwarf
= false;
126 bool debugGHashes
= false;
127 bool debugSymtab
= false;
129 bool driverUponly
= false;
130 bool driverWdm
= false;
131 bool showTiming
= false;
132 bool showSummary
= false;
133 bool printSearchPaths
= false;
134 unsigned debugTypes
= static_cast<unsigned>(DebugType::None
);
135 llvm::SmallVector
<llvm::StringRef
, 0> mllvmOpts
;
136 std::vector
<std::string
> natvisFiles
;
137 llvm::StringMap
<std::string
> namedStreams
;
138 llvm::SmallString
<128> pdbAltPath
;
139 int pdbPageSize
= 4096;
140 llvm::SmallString
<128> pdbPath
;
141 llvm::SmallString
<128> pdbSourcePath
;
142 std::vector
<llvm::StringRef
> argv
;
144 // Symbols in this set are considered as live by the garbage collector.
145 std::vector
<Symbol
*> gcroot
;
147 std::set
<std::string
> noDefaultLibs
;
148 bool noDefaultLibAll
= false;
150 // True if we are creating a DLL.
153 bool noimplib
= false;
154 std::vector
<Export
> exports
;
155 bool hadExplicitExports
;
156 std::set
<std::string
> delayLoads
;
157 std::map
<std::string
, int> dllOrder
;
158 Symbol
*delayLoadHelper
= nullptr;
160 bool saveTemps
= false;
163 int guardCF
= GuardCFLevel::Off
;
166 bool safeSEH
= false;
167 Symbol
*sehTable
= nullptr;
168 Symbol
*sehCount
= nullptr;
171 // Used for /opt:lldlto=N
173 // Used for /opt:lldltocgo=N
174 std::optional
<unsigned> ltoCgo
;
176 // Used for /opt:lldltojobs=N
177 std::string thinLTOJobs
;
178 // Used for /opt:lldltopartitions=N
179 unsigned ltoPartitions
= 1;
181 // Used for /opt:lldltocache=path
183 // Used for /opt:lldltocachepolicy=policy
184 llvm::CachePruningPolicy ltoCachePolicy
;
186 // Used for /opt:[no]ltodebugpassmanager
187 bool ltoDebugPassManager
= false;
189 // Used for /merge:from=to (e.g. /merge:.rdata=.text)
190 std::map
<StringRef
, StringRef
> merge
;
192 // Used for /section=.name,{DEKPRSW} to set section attributes.
193 std::map
<StringRef
, uint32_t> section
;
195 // Options for manifest files.
196 ManifestKind manifest
= Default
;
198 llvm::SetVector
<StringRef
> manifestDependencies
;
199 bool manifestUAC
= true;
200 std::vector
<std::string
> manifestInput
;
201 StringRef manifestLevel
= "'asInvoker'";
202 StringRef manifestUIAccess
= "'false'";
203 StringRef manifestFile
;
208 // Used for /aligncomm.
209 std::map
<std::string
, int> alignComm
;
211 // Used for /failifmismatch.
212 std::map
<StringRef
, std::pair
<StringRef
, InputFile
*>> mustMatch
;
214 // Used for /alternatename.
215 std::map
<StringRef
, StringRef
> alternateNames
;
218 llvm::StringMap
<int> order
;
221 std::string lldmapFile
;
226 // Used for /mapinfo.
227 bool mapInfo
= false;
229 // Used for /thinlto-index-only:
230 llvm::StringRef thinLTOIndexOnlyArg
;
232 // Used for /thinlto-prefix-replace:
233 // Replace the prefix in paths generated for ThinLTO, replacing
234 // thinLTOPrefixReplaceOld with thinLTOPrefixReplaceNew. If
235 // thinLTOPrefixReplaceNativeObject is defined, replace the prefix of object
236 // file paths written to the response file given in the
237 // --thinlto-index-only=${response} option with
238 // thinLTOPrefixReplaceNativeObject, instead of thinLTOPrefixReplaceNew.
239 llvm::StringRef thinLTOPrefixReplaceOld
;
240 llvm::StringRef thinLTOPrefixReplaceNew
;
241 llvm::StringRef thinLTOPrefixReplaceNativeObject
;
243 // Used for /thinlto-object-suffix-replace:
244 std::pair
<llvm::StringRef
, llvm::StringRef
> thinLTOObjectSuffixReplace
;
246 // Used for /lto-obj-path:
247 llvm::StringRef ltoObjPath
;
249 // Used for /lto-cs-profile-generate:
250 bool ltoCSProfileGenerate
= false;
252 // Used for /lto-cs-profile-path
253 llvm::StringRef ltoCSProfileFile
;
255 // Used for /lto-pgo-warn-mismatch:
256 bool ltoPGOWarnMismatch
= true;
258 // Used for /call-graph-ordering-file:
259 llvm::MapVector
<std::pair
<const SectionChunk
*, const SectionChunk
*>,
262 bool callGraphProfileSort
= false;
264 // Used for /print-symbol-order:
265 StringRef printSymbolOrder
;
267 // Used for /vfsoverlay:
268 std::unique_ptr
<llvm::vfs::FileSystem
> vfs
;
270 uint64_t align
= 4096;
271 uint64_t imageBase
= -1;
272 uint64_t fileAlign
= 512;
273 uint64_t stackReserve
= 1024 * 1024;
274 uint64_t stackCommit
= 4096;
275 uint64_t heapReserve
= 1024 * 1024;
276 uint64_t heapCommit
= 4096;
277 uint32_t majorImageVersion
= 0;
278 uint32_t minorImageVersion
= 0;
279 // If changing the default os/subsys version here, update the default in
280 // the MinGW driver accordingly.
281 uint32_t majorOSVersion
= 6;
282 uint32_t minorOSVersion
= 0;
283 uint32_t majorSubsystemVersion
= 6;
284 uint32_t minorSubsystemVersion
= 0;
285 uint32_t timestamp
= 0;
286 uint32_t functionPadMin
= 0;
287 bool dynamicBase
= true;
288 bool allowBind
= true;
289 bool cetCompat
= false;
290 bool nxCompat
= true;
291 bool allowIsolation
= true;
292 bool terminalServerAware
= true;
293 bool largeAddressAware
= false;
294 bool highEntropyVA
= false;
295 bool appContainer
= false;
297 bool warnMissingOrderSymbol
= true;
298 bool warnLocallyDefinedImported
= true;
299 bool warnDebugInfoUnusable
= true;
300 bool warnLongSectionNames
= true;
301 bool warnStdcallFixup
= true;
302 bool incremental
= true;
303 bool integrityCheck
= false;
306 bool swaprunCD
= false;
307 bool swaprunNet
= false;
308 bool thinLTOEmitImportsFiles
;
309 bool thinLTOIndexOnly
;
310 bool autoImport
= false;
311 bool pseudoRelocs
= false;
312 bool stdcallFixup
= false;
313 bool writeCheckSum
= false;
316 } // namespace lld::coff