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/StringMap.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Object/COFF.h"
15 #include "llvm/Support/CachePruning.h"
24 using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
25 using llvm::COFF::WindowsSubsystem;
26 using llvm::StringRef;
27 class DefinedAbsolute;
28 class DefinedRelative;
34 static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
35 static const auto ARM64 = llvm::COFF::IMAGE_FILE_MACHINE_ARM64;
36 static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT;
37 static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386;
39 // Represents an /export option.
41 StringRef name; // N in /export:N or /export:E=N
42 StringRef extName; // E in /export:E=N
43 Symbol *sym = nullptr;
47 bool isPrivate = false;
48 bool constant = false;
50 // If an export is a form of /export:foo=dllname.bar, that means
51 // that foo should be exported as an alias to bar in the DLL.
52 // forwardTo is set to "dllname.bar" part. Usually empty.
54 StringChunk *forwardChunk = nullptr;
56 // True if this /export option was in .drectves section.
57 bool directives = false;
59 StringRef exportName; // Name in DLL
61 bool operator==(const Export &e) {
62 return (name == e.name && extName == e.extName &&
63 ordinal == e.ordinal && noname == e.noname &&
64 data == e.data && isPrivate == e.isPrivate);
68 enum class DebugType {
70 CV = 0x1, /// CodeView
71 PData = 0x2, /// Procedure Data
72 Fixup = 0x4, /// Relocation Table
75 enum class GuardCFLevel {
77 NoLongJmp, // Emit gfids but no longjmp tables
78 Full, // Enable all protections.
81 // Global configuration.
82 struct Configuration {
83 enum ManifestKind { SideBySide, Embed, No };
84 bool is64() { return machine == AMD64 || machine == ARM64; }
86 llvm::COFF::MachineTypes machine = IMAGE_FILE_MACHINE_UNKNOWN;
89 WindowsSubsystem subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;
90 Symbol *entry = nullptr;
92 std::string outputFile;
93 std::string importName;
98 bool relocatable = true;
99 bool forceMultiple = false;
100 bool forceMultipleRes = false;
101 bool forceUnresolved = false;
103 bool debugDwarf = false;
104 bool debugGHashes = false;
105 bool debugSymtab = false;
107 bool driverUponly = false;
108 bool driverWdm = false;
109 bool showTiming = false;
110 bool showSummary = false;
111 unsigned debugTypes = static_cast<unsigned>(DebugType::None);
112 std::vector<std::string> natvisFiles;
113 llvm::StringMap<std::string> namedStreams;
114 llvm::SmallString<128> pdbAltPath;
115 llvm::SmallString<128> pdbPath;
116 llvm::SmallString<128> pdbSourcePath;
117 std::vector<llvm::StringRef> argv;
119 // Symbols in this set are considered as live by the garbage collector.
120 std::vector<Symbol *> gcroot;
122 std::set<std::string> noDefaultLibs;
123 bool noDefaultLibAll = false;
125 // True if we are creating a DLL.
128 std::vector<Export> exports;
129 bool hadExplicitExports;
130 std::set<std::string> delayLoads;
131 std::map<std::string, int> dllOrder;
132 Symbol *delayLoadHelper = nullptr;
134 bool saveTemps = false;
137 GuardCFLevel guardCF = GuardCFLevel::Off;
140 bool safeSEH = false;
141 Symbol *sehTable = nullptr;
142 Symbol *sehCount = nullptr;
145 // Used for /opt:lldlto=N
148 // Used for /opt:lldltojobs=N
149 std::string thinLTOJobs;
150 // Used for /opt:lldltopartitions=N
151 unsigned ltoPartitions = 1;
153 // Used for /opt:lldltocache=path
155 // Used for /opt:lldltocachepolicy=policy
156 llvm::CachePruningPolicy ltoCachePolicy;
158 // Used for /merge:from=to (e.g. /merge:.rdata=.text)
159 std::map<StringRef, StringRef> merge;
161 // Used for /section=.name,{DEKPRSW} to set section attributes.
162 std::map<StringRef, uint32_t> section;
164 // Options for manifest files.
165 ManifestKind manifest = No;
167 StringRef manifestDependency;
168 bool manifestUAC = true;
169 std::vector<std::string> manifestInput;
170 StringRef manifestLevel = "'asInvoker'";
171 StringRef manifestUIAccess = "'false'";
172 StringRef manifestFile;
174 // Used for /aligncomm.
175 std::map<std::string, int> alignComm;
177 // Used for /failifmismatch.
178 std::map<StringRef, std::pair<StringRef, InputFile *>> mustMatch;
180 // Used for /alternatename.
181 std::map<StringRef, StringRef> alternateNames;
184 llvm::StringMap<int> order;
187 std::string lldmapFile;
192 // Used for /thinlto-index-only:
193 llvm::StringRef thinLTOIndexOnlyArg;
195 // Used for /thinlto-object-prefix-replace:
196 std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace;
198 // Used for /thinlto-object-suffix-replace:
199 std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
201 // Used for /lto-obj-path:
202 llvm::StringRef ltoObjPath;
204 uint64_t align = 4096;
205 uint64_t imageBase = -1;
206 uint64_t fileAlign = 512;
207 uint64_t stackReserve = 1024 * 1024;
208 uint64_t stackCommit = 4096;
209 uint64_t heapReserve = 1024 * 1024;
210 uint64_t heapCommit = 4096;
211 uint32_t majorImageVersion = 0;
212 uint32_t minorImageVersion = 0;
213 uint32_t majorOSVersion = 6;
214 uint32_t minorOSVersion = 0;
215 uint32_t timestamp = 0;
216 uint32_t functionPadMin = 0;
217 bool dynamicBase = true;
218 bool allowBind = true;
219 bool cetCompat = false;
220 bool nxCompat = true;
221 bool allowIsolation = true;
222 bool terminalServerAware = true;
223 bool largeAddressAware = false;
224 bool highEntropyVA = false;
225 bool appContainer = false;
227 bool warnMissingOrderSymbol = true;
228 bool warnLocallyDefinedImported = true;
229 bool warnDebugInfoUnusable = true;
230 bool warnLongSectionNames = true;
231 bool incremental = true;
232 bool integrityCheck = false;
235 bool swaprunCD = false;
236 bool swaprunNet = false;
237 bool thinLTOEmitImportsFiles;
238 bool thinLTOIndexOnly;
239 bool autoImport = false;
240 bool pseudoRelocs = false;
243 extern Configuration *config;