[DAGCombiner] Add target hook function to decide folding (mul (add x, c1), c2)
[llvm-project.git] / lld / COFF / Config.h
blob002d128838ce2beb4eae2073a3cd52d1724da762
1 //===- Config.h -------------------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLD_COFF_CONFIG_H
10 #define LLD_COFF_CONFIG_H
12 #include "llvm/ADT/MapVector.h"
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Object/COFF.h"
16 #include "llvm/Support/CachePruning.h"
17 #include <cstdint>
18 #include <map>
19 #include <set>
20 #include <string>
22 namespace lld {
23 namespace coff {
25 using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
26 using llvm::COFF::WindowsSubsystem;
27 using llvm::StringRef;
28 class DefinedAbsolute;
29 class DefinedRelative;
30 class StringChunk;
31 class Symbol;
32 class InputFile;
33 class SectionChunk;
35 // Short aliases.
36 static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
37 static const auto ARM64 = llvm::COFF::IMAGE_FILE_MACHINE_ARM64;
38 static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT;
39 static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386;
41 // Represents an /export option.
42 struct Export {
43 StringRef name; // N in /export:N or /export:E=N
44 StringRef extName; // E in /export:E=N
45 Symbol *sym = nullptr;
46 uint16_t ordinal = 0;
47 bool noname = false;
48 bool data = false;
49 bool isPrivate = false;
50 bool constant = false;
52 // If an export is a form of /export:foo=dllname.bar, that means
53 // that foo should be exported as an alias to bar in the DLL.
54 // forwardTo is set to "dllname.bar" part. Usually empty.
55 StringRef forwardTo;
56 StringChunk *forwardChunk = nullptr;
58 // True if this /export option was in .drectves section.
59 bool directives = false;
60 StringRef symbolName;
61 StringRef exportName; // Name in DLL
63 bool operator==(const Export &e) {
64 return (name == e.name && extName == e.extName &&
65 ordinal == e.ordinal && noname == e.noname &&
66 data == e.data && isPrivate == e.isPrivate);
70 enum class DebugType {
71 None = 0x0,
72 CV = 0x1, /// CodeView
73 PData = 0x2, /// Procedure Data
74 Fixup = 0x4, /// Relocation Table
77 enum GuardCFLevel {
78 Off = 0x0,
79 CF = 0x1, /// Emit gfids tables
80 LongJmp = 0x2, /// Emit longjmp tables
81 EHCont = 0x4, /// Emit ehcont tables
82 All = 0x7 /// Enable all protections
85 enum class ICFLevel {
86 None,
87 Safe, // Safe ICF for all sections.
88 All, // Aggressive ICF for code, but safe ICF for data, similar to MSVC's
89 // behavior.
92 // Global configuration.
93 struct Configuration {
94 enum ManifestKind { SideBySide, Embed, No };
95 bool is64() { return machine == AMD64 || machine == ARM64; }
97 llvm::COFF::MachineTypes machine = IMAGE_FILE_MACHINE_UNKNOWN;
98 size_t wordsize;
99 bool verbose = false;
100 WindowsSubsystem subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;
101 Symbol *entry = nullptr;
102 bool noEntry = false;
103 std::string outputFile;
104 std::string importName;
105 bool demangle = true;
106 bool doGC = true;
107 ICFLevel doICF = ICFLevel::None;
108 bool tailMerge;
109 bool relocatable = true;
110 bool forceMultiple = false;
111 bool forceMultipleRes = false;
112 bool forceUnresolved = false;
113 bool debug = false;
114 bool debugDwarf = false;
115 bool debugGHashes = false;
116 bool debugSymtab = false;
117 bool driver = false;
118 bool driverUponly = false;
119 bool driverWdm = false;
120 bool showTiming = false;
121 bool showSummary = false;
122 unsigned debugTypes = static_cast<unsigned>(DebugType::None);
123 std::vector<std::string> natvisFiles;
124 llvm::StringMap<std::string> namedStreams;
125 llvm::SmallString<128> pdbAltPath;
126 llvm::SmallString<128> pdbPath;
127 llvm::SmallString<128> pdbSourcePath;
128 std::vector<llvm::StringRef> argv;
130 // Symbols in this set are considered as live by the garbage collector.
131 std::vector<Symbol *> gcroot;
133 std::set<std::string> noDefaultLibs;
134 bool noDefaultLibAll = false;
136 // True if we are creating a DLL.
137 bool dll = false;
138 StringRef implib;
139 std::vector<Export> exports;
140 bool hadExplicitExports;
141 std::set<std::string> delayLoads;
142 std::map<std::string, int> dllOrder;
143 Symbol *delayLoadHelper = nullptr;
145 bool saveTemps = false;
147 // /guard:cf
148 int guardCF = GuardCFLevel::Off;
150 // Used for SafeSEH.
151 bool safeSEH = false;
152 Symbol *sehTable = nullptr;
153 Symbol *sehCount = nullptr;
154 bool noSEH = false;
156 // Used for /opt:lldlto=N
157 unsigned ltoo = 2;
159 // Used for /opt:lldltojobs=N
160 std::string thinLTOJobs;
161 // Used for /opt:lldltopartitions=N
162 unsigned ltoPartitions = 1;
164 // Used for /opt:lldltocache=path
165 StringRef ltoCache;
166 // Used for /opt:lldltocachepolicy=policy
167 llvm::CachePruningPolicy ltoCachePolicy;
169 // Used for /opt:[no]ltonewpassmanager
170 bool ltoNewPassManager = false;
171 // Used for /opt:[no]ltodebugpassmanager
172 bool ltoDebugPassManager = false;
174 // Used for /merge:from=to (e.g. /merge:.rdata=.text)
175 std::map<StringRef, StringRef> merge;
177 // Used for /section=.name,{DEKPRSW} to set section attributes.
178 std::map<StringRef, uint32_t> section;
180 // Options for manifest files.
181 ManifestKind manifest = No;
182 int manifestID = 1;
183 StringRef manifestDependency;
184 bool manifestUAC = true;
185 std::vector<std::string> manifestInput;
186 StringRef manifestLevel = "'asInvoker'";
187 StringRef manifestUIAccess = "'false'";
188 StringRef manifestFile;
190 // Used for /aligncomm.
191 std::map<std::string, int> alignComm;
193 // Used for /failifmismatch.
194 std::map<StringRef, std::pair<StringRef, InputFile *>> mustMatch;
196 // Used for /alternatename.
197 std::map<StringRef, StringRef> alternateNames;
199 // Used for /order.
200 llvm::StringMap<int> order;
202 // Used for /lldmap.
203 std::string lldmapFile;
205 // Used for /map.
206 std::string mapFile;
208 // Used for /thinlto-index-only:
209 llvm::StringRef thinLTOIndexOnlyArg;
211 // Used for /thinlto-object-prefix-replace:
212 std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace;
214 // Used for /thinlto-object-suffix-replace:
215 std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
217 // Used for /lto-obj-path:
218 llvm::StringRef ltoObjPath;
220 // Used for /lto-cs-profile-generate:
221 bool ltoCSProfileGenerate = false;
223 // Used for /lto-cs-profile-path
224 llvm::StringRef ltoCSProfileFile;
226 // Used for /lto-pgo-warn-mismatch:
227 bool ltoPGOWarnMismatch = true;
229 // Used for /call-graph-ordering-file:
230 llvm::MapVector<std::pair<const SectionChunk *, const SectionChunk *>,
231 uint64_t>
232 callGraphProfile;
233 bool callGraphProfileSort = false;
235 // Used for /print-symbol-order:
236 StringRef printSymbolOrder;
238 uint64_t align = 4096;
239 uint64_t imageBase = -1;
240 uint64_t fileAlign = 512;
241 uint64_t stackReserve = 1024 * 1024;
242 uint64_t stackCommit = 4096;
243 uint64_t heapReserve = 1024 * 1024;
244 uint64_t heapCommit = 4096;
245 uint32_t majorImageVersion = 0;
246 uint32_t minorImageVersion = 0;
247 // If changing the default os/subsys version here, update the default in
248 // the MinGW driver accordingly.
249 uint32_t majorOSVersion = 6;
250 uint32_t minorOSVersion = 0;
251 uint32_t majorSubsystemVersion = 6;
252 uint32_t minorSubsystemVersion = 0;
253 uint32_t timestamp = 0;
254 uint32_t functionPadMin = 0;
255 bool dynamicBase = true;
256 bool allowBind = true;
257 bool cetCompat = false;
258 bool nxCompat = true;
259 bool allowIsolation = true;
260 bool terminalServerAware = true;
261 bool largeAddressAware = false;
262 bool highEntropyVA = false;
263 bool appContainer = false;
264 bool mingw = false;
265 bool warnMissingOrderSymbol = true;
266 bool warnLocallyDefinedImported = true;
267 bool warnDebugInfoUnusable = true;
268 bool warnLongSectionNames = true;
269 bool warnStdcallFixup = true;
270 bool incremental = true;
271 bool integrityCheck = false;
272 bool killAt = false;
273 bool repro = false;
274 bool swaprunCD = false;
275 bool swaprunNet = false;
276 bool thinLTOEmitImportsFiles;
277 bool thinLTOIndexOnly;
278 bool autoImport = false;
279 bool pseudoRelocs = false;
280 bool stdcallFixup = false;
283 extern Configuration *config;
285 } // namespace coff
286 } // namespace lld
288 #endif