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/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> 21 22 namespace lld { 23 namespace coff { 24 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; 34 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; 40 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; 51 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; 57 58 // True if this /export option was in .drectves section. 59 bool directives = false; 60 StringRef symbolName; 61 StringRef exportName; // Name in DLL 62 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); 67 } 68 }; 69 70 enum class DebugType { 71 None = 0x0, 72 CV = 0x1, /// CodeView 73 PData = 0x2, /// Procedure Data 74 Fixup = 0x4, /// Relocation Table 75 }; 76 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 83 }; 84 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. 90 }; 91 92 // Global configuration. 93 struct Configuration { 94 enum ManifestKind { SideBySide, Embed, No }; 95 bool is64() { return machine == AMD64 || machine == ARM64; } 96 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; 129 130 // Symbols in this set are considered as live by the garbage collector. 131 std::vector<Symbol *> gcroot; 132 133 std::set<std::string> noDefaultLibs; 134 bool noDefaultLibAll = false; 135 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; 144 145 bool saveTemps = false; 146 147 // /guard:cf 148 int guardCF = GuardCFLevel::Off; 149 150 // Used for SafeSEH. 151 bool safeSEH = false; 152 Symbol *sehTable = nullptr; 153 Symbol *sehCount = nullptr; 154 bool noSEH = false; 155 156 // Used for /opt:lldlto=N 157 unsigned ltoo = 2; 158 159 // Used for /opt:lldltojobs=N 160 std::string thinLTOJobs; 161 // Used for /opt:lldltopartitions=N 162 unsigned ltoPartitions = 1; 163 164 // Used for /opt:lldltocache=path 165 StringRef ltoCache; 166 // Used for /opt:lldltocachepolicy=policy 167 llvm::CachePruningPolicy ltoCachePolicy; 168 169 // Used for /opt:[no]ltonewpassmanager 170 bool ltoNewPassManager = false; 171 // Used for /opt:[no]ltodebugpassmanager 172 bool ltoDebugPassManager = false; 173 174 // Used for /merge:from=to (e.g. /merge:.rdata=.text) 175 std::map<StringRef, StringRef> merge; 176 177 // Used for /section=.name,{DEKPRSW} to set section attributes. 178 std::map<StringRef, uint32_t> section; 179 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; 189 190 // Used for /aligncomm. 191 std::map<std::string, int> alignComm; 192 193 // Used for /failifmismatch. 194 std::map<StringRef, std::pair<StringRef, InputFile *>> mustMatch; 195 196 // Used for /alternatename. 197 std::map<StringRef, StringRef> alternateNames; 198 199 // Used for /order. 200 llvm::StringMap<int> order; 201 202 // Used for /lldmap. 203 std::string lldmapFile; 204 205 // Used for /map. 206 std::string mapFile; 207 208 // Used for /thinlto-index-only: 209 llvm::StringRef thinLTOIndexOnlyArg; 210 211 // Used for /thinlto-object-prefix-replace: 212 std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace; 213 214 // Used for /thinlto-object-suffix-replace: 215 std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace; 216 217 // Used for /lto-obj-path: 218 llvm::StringRef ltoObjPath; 219 220 // Used for /lto-cs-profile-generate: 221 bool ltoCSProfileGenerate = false; 222 223 // Used for /lto-cs-profile-path 224 llvm::StringRef ltoCSProfileFile; 225 226 // Used for /call-graph-ordering-file: 227 llvm::MapVector<std::pair<const SectionChunk *, const SectionChunk *>, 228 uint64_t> 229 callGraphProfile; 230 bool callGraphProfileSort = false; 231 232 // Used for /print-symbol-order: 233 StringRef printSymbolOrder; 234 235 uint64_t align = 4096; 236 uint64_t imageBase = -1; 237 uint64_t fileAlign = 512; 238 uint64_t stackReserve = 1024 * 1024; 239 uint64_t stackCommit = 4096; 240 uint64_t heapReserve = 1024 * 1024; 241 uint64_t heapCommit = 4096; 242 uint32_t majorImageVersion = 0; 243 uint32_t minorImageVersion = 0; 244 // If changing the default os/subsys version here, update the default in 245 // the MinGW driver accordingly. 246 uint32_t majorOSVersion = 6; 247 uint32_t minorOSVersion = 0; 248 uint32_t majorSubsystemVersion = 6; 249 uint32_t minorSubsystemVersion = 0; 250 uint32_t timestamp = 0; 251 uint32_t functionPadMin = 0; 252 bool dynamicBase = true; 253 bool allowBind = true; 254 bool cetCompat = false; 255 bool nxCompat = true; 256 bool allowIsolation = true; 257 bool terminalServerAware = true; 258 bool largeAddressAware = false; 259 bool highEntropyVA = false; 260 bool appContainer = false; 261 bool mingw = false; 262 bool warnMissingOrderSymbol = true; 263 bool warnLocallyDefinedImported = true; 264 bool warnDebugInfoUnusable = true; 265 bool warnLongSectionNames = true; 266 bool warnStdcallFixup = true; 267 bool incremental = true; 268 bool integrityCheck = false; 269 bool killAt = false; 270 bool repro = false; 271 bool swaprunCD = false; 272 bool swaprunNet = false; 273 bool thinLTOEmitImportsFiles; 274 bool thinLTOIndexOnly; 275 bool autoImport = false; 276 bool pseudoRelocs = false; 277 bool stdcallFixup = false; 278 }; 279 280 extern Configuration *config; 281 282 } // namespace coff 283 } // namespace lld 284 285 #endif 286