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