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;
106 bool showTiming = false;
107 bool showSummary = false;
108 unsigned debugTypes = static_cast<unsigned>(DebugType::None);
109 std::vector<std::string> natvisFiles;
110 llvm::SmallString<128> pdbAltPath;
111 llvm::SmallString<128> pdbPath;
112 llvm::SmallString<128> pdbSourcePath;
113 std::vector<llvm::StringRef> argv;
115 // Symbols in this set are considered as live by the garbage collector.
116 std::vector<Symbol *> gcroot;
118 std::set<std::string> noDefaultLibs;
119 bool noDefaultLibAll = false;
121 // True if we are creating a DLL.
124 std::vector<Export> exports;
125 std::set<std::string> delayLoads;
126 std::map<std::string, int> dllOrder;
127 Symbol *delayLoadHelper = nullptr;
129 bool saveTemps = false;
132 GuardCFLevel guardCF = GuardCFLevel::Off;
135 bool safeSEH = false;
136 Symbol *sehTable = nullptr;
137 Symbol *sehCount = nullptr;
139 // Used for /opt:lldlto=N
142 // Used for /opt:lldltojobs=N
143 unsigned thinLTOJobs = 0;
144 // Used for /opt:lldltopartitions=N
145 unsigned ltoPartitions = 1;
147 // Used for /opt:lldltocache=path
149 // Used for /opt:lldltocachepolicy=policy
150 llvm::CachePruningPolicy ltoCachePolicy;
152 // Used for /merge:from=to (e.g. /merge:.rdata=.text)
153 std::map<StringRef, StringRef> merge;
155 // Used for /section=.name,{DEKPRSW} to set section attributes.
156 std::map<StringRef, uint32_t> section;
158 // Options for manifest files.
159 ManifestKind manifest = No;
161 StringRef manifestDependency;
162 bool manifestUAC = true;
163 std::vector<std::string> manifestInput;
164 StringRef manifestLevel = "'asInvoker'";
165 StringRef manifestUIAccess = "'false'";
166 StringRef manifestFile;
168 // Used for /aligncomm.
169 std::map<std::string, int> alignComm;
171 // Used for /failifmismatch.
172 std::map<StringRef, std::pair<StringRef, InputFile *>> mustMatch;
174 // Used for /alternatename.
175 std::map<StringRef, StringRef> alternateNames;
178 llvm::StringMap<int> order;
183 // Used for /thinlto-index-only:
184 llvm::StringRef thinLTOIndexOnlyArg;
186 // Used for /thinlto-object-prefix-replace:
187 std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace;
189 // Used for /thinlto-object-suffix-replace:
190 std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
192 uint64_t align = 4096;
193 uint64_t imageBase = -1;
194 uint64_t fileAlign = 512;
195 uint64_t stackReserve = 1024 * 1024;
196 uint64_t stackCommit = 4096;
197 uint64_t heapReserve = 1024 * 1024;
198 uint64_t heapCommit = 4096;
199 uint32_t majorImageVersion = 0;
200 uint32_t minorImageVersion = 0;
201 uint32_t majorOSVersion = 6;
202 uint32_t minorOSVersion = 0;
203 uint32_t timestamp = 0;
204 uint32_t functionPadMin = 0;
205 bool dynamicBase = true;
206 bool allowBind = true;
207 bool nxCompat = true;
208 bool allowIsolation = true;
209 bool terminalServerAware = true;
210 bool largeAddressAware = false;
211 bool highEntropyVA = false;
212 bool appContainer = false;
214 bool warnMissingOrderSymbol = true;
215 bool warnLocallyDefinedImported = true;
216 bool warnDebugInfoUnusable = true;
217 bool incremental = true;
218 bool integrityCheck = false;
221 bool swaprunCD = false;
222 bool swaprunNet = false;
223 bool thinLTOEmitImportsFiles;
224 bool thinLTOIndexOnly;
227 extern Configuration *config;