1 //===- Config.h -------------------------------------------------*- C++ -*-===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLD_COFF_CONFIG_H
11 #define LLD_COFF_CONFIG_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"
25 using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
26 using llvm::COFF::WindowsSubsystem;
27 using llvm::StringRef;
28 class DefinedAbsolute;
29 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;
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 && Private == E.Private);
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;
88 WindowsSubsystem Subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;
89 Symbol *Entry = nullptr;
91 std::string OutputFile;
92 std::string ImportName;
96 bool Relocatable = true;
99 bool DebugDwarf = false;
100 bool DebugGHashes = false;
101 bool DebugSymtab = false;
102 bool ShowTiming = false;
103 unsigned DebugTypes = static_cast<unsigned>(DebugType::None);
104 std::vector<std::string> NatvisFiles;
105 llvm::SmallString<128> PDBAltPath;
106 llvm::SmallString<128> PDBPath;
107 llvm::SmallString<128> PDBSourcePath;
108 std::vector<llvm::StringRef> Argv;
110 // Symbols in this set are considered as live by the garbage collector.
111 std::vector<Symbol *> GCRoot;
113 std::set<StringRef> NoDefaultLibs;
114 bool NoDefaultLibAll = false;
116 // True if we are creating a DLL.
119 std::vector<Export> Exports;
120 std::set<std::string> DelayLoads;
121 std::map<std::string, int> DLLOrder;
122 Symbol *DelayLoadHelper = nullptr;
124 bool SaveTemps = false;
127 GuardCFLevel GuardCF = GuardCFLevel::Off;
130 Symbol *SEHTable = nullptr;
131 Symbol *SEHCount = nullptr;
133 // Used for /opt:lldlto=N
136 // Used for /opt:lldltojobs=N
137 unsigned ThinLTOJobs = 0;
138 // Used for /opt:lldltopartitions=N
139 unsigned LTOPartitions = 1;
141 // Used for /opt:lldltocache=path
143 // Used for /opt:lldltocachepolicy=policy
144 llvm::CachePruningPolicy LTOCachePolicy;
146 // Used for /merge:from=to (e.g. /merge:.rdata=.text)
147 std::map<StringRef, StringRef> Merge;
149 // Used for /section=.name,{DEKPRSW} to set section attributes.
150 std::map<StringRef, uint32_t> Section;
152 // Options for manifest files.
153 ManifestKind Manifest = No;
155 StringRef ManifestDependency;
156 bool ManifestUAC = true;
157 std::vector<std::string> ManifestInput;
158 StringRef ManifestLevel = "'asInvoker'";
159 StringRef ManifestUIAccess = "'false'";
160 StringRef ManifestFile;
162 // Used for /aligncomm.
163 std::map<std::string, int> AlignComm;
165 // Used for /failifmismatch.
166 std::map<StringRef, StringRef> MustMatch;
168 // Used for /alternatename.
169 std::map<StringRef, StringRef> AlternateNames;
172 llvm::StringMap<int> Order;
177 uint64_t ImageBase = -1;
178 uint64_t StackReserve = 1024 * 1024;
179 uint64_t StackCommit = 4096;
180 uint64_t HeapReserve = 1024 * 1024;
181 uint64_t HeapCommit = 4096;
182 uint32_t MajorImageVersion = 0;
183 uint32_t MinorImageVersion = 0;
184 uint32_t MajorOSVersion = 6;
185 uint32_t MinorOSVersion = 0;
186 uint32_t Timestamp = 0;
187 bool DynamicBase = true;
188 bool AllowBind = true;
189 bool NxCompat = true;
190 bool AllowIsolation = true;
191 bool TerminalServerAware = true;
192 bool LargeAddressAware = false;
193 bool HighEntropyVA = false;
194 bool AppContainer = false;
196 bool WarnMissingOrderSymbol = true;
197 bool WarnLocallyDefinedImported = true;
198 bool Incremental = true;
199 bool IntegrityCheck = false;
204 extern Configuration *Config;