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 bool noimplib = false; 144 std::vector<Export> exports; 145 bool hadExplicitExports; 146 std::set<std::string> delayLoads; 147 std::map<std::string, int> dllOrder; 148 Symbol *delayLoadHelper = nullptr; 149 150 bool saveTemps = false; 151 152 // /guard:cf 153 int guardCF = GuardCFLevel::Off; 154 155 // Used for SafeSEH. 156 bool safeSEH = false; 157 Symbol *sehTable = nullptr; 158 Symbol *sehCount = nullptr; 159 bool noSEH = false; 160 161 // Used for /opt:lldlto=N 162 unsigned ltoo = 2; 163 164 // Used for /opt:lldltojobs=N 165 std::string thinLTOJobs; 166 // Used for /opt:lldltopartitions=N 167 unsigned ltoPartitions = 1; 168 169 // Used for /opt:lldltocache=path 170 StringRef ltoCache; 171 // Used for /opt:lldltocachepolicy=policy 172 llvm::CachePruningPolicy ltoCachePolicy; 173 174 // Used for /opt:[no]ltodebugpassmanager 175 bool ltoDebugPassManager = false; 176 177 // Used for /merge:from=to (e.g. /merge:.rdata=.text) 178 std::map<StringRef, StringRef> merge; 179 180 // Used for /section=.name,{DEKPRSW} to set section attributes. 181 std::map<StringRef, uint32_t> section; 182 183 // Options for manifest files. 184 ManifestKind manifest = Default; 185 int manifestID = 1; 186 llvm::SetVector<StringRef> manifestDependencies; 187 bool manifestUAC = true; 188 std::vector<std::string> manifestInput; 189 StringRef manifestLevel = "'asInvoker'"; 190 StringRef manifestUIAccess = "'false'"; 191 StringRef manifestFile; 192 193 // Used for /aligncomm. 194 std::map<std::string, int> alignComm; 195 196 // Used for /failifmismatch. 197 std::map<StringRef, std::pair<StringRef, InputFile *>> mustMatch; 198 199 // Used for /alternatename. 200 std::map<StringRef, StringRef> alternateNames; 201 202 // Used for /order. 203 llvm::StringMap<int> order; 204 205 // Used for /lldmap. 206 std::string lldmapFile; 207 208 // Used for /map. 209 std::string mapFile; 210 211 // Used for /thinlto-index-only: 212 llvm::StringRef thinLTOIndexOnlyArg; 213 214 // Used for /thinlto-object-prefix-replace: 215 std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace; 216 217 // Used for /thinlto-object-suffix-replace: 218 std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace; 219 220 // Used for /lto-obj-path: 221 llvm::StringRef ltoObjPath; 222 223 // Used for /lto-cs-profile-generate: 224 bool ltoCSProfileGenerate = false; 225 226 // Used for /lto-cs-profile-path 227 llvm::StringRef ltoCSProfileFile; 228 229 // Used for /lto-pgo-warn-mismatch: 230 bool ltoPGOWarnMismatch = true; 231 232 // Used for /call-graph-ordering-file: 233 llvm::MapVector<std::pair<const SectionChunk *, const SectionChunk *>, 234 uint64_t> 235 callGraphProfile; 236 bool callGraphProfileSort = false; 237 238 // Used for /print-symbol-order: 239 StringRef printSymbolOrder; 240 241 uint64_t align = 4096; 242 uint64_t imageBase = -1; 243 uint64_t fileAlign = 512; 244 uint64_t stackReserve = 1024 * 1024; 245 uint64_t stackCommit = 4096; 246 uint64_t heapReserve = 1024 * 1024; 247 uint64_t heapCommit = 4096; 248 uint32_t majorImageVersion = 0; 249 uint32_t minorImageVersion = 0; 250 // If changing the default os/subsys version here, update the default in 251 // the MinGW driver accordingly. 252 uint32_t majorOSVersion = 6; 253 uint32_t minorOSVersion = 0; 254 uint32_t majorSubsystemVersion = 6; 255 uint32_t minorSubsystemVersion = 0; 256 uint32_t timestamp = 0; 257 uint32_t functionPadMin = 0; 258 bool dynamicBase = true; 259 bool allowBind = true; 260 bool cetCompat = false; 261 bool nxCompat = true; 262 bool allowIsolation = true; 263 bool terminalServerAware = true; 264 bool largeAddressAware = false; 265 bool highEntropyVA = false; 266 bool appContainer = false; 267 bool mingw = false; 268 bool warnMissingOrderSymbol = true; 269 bool warnLocallyDefinedImported = true; 270 bool warnDebugInfoUnusable = true; 271 bool warnLongSectionNames = true; 272 bool warnStdcallFixup = true; 273 bool incremental = true; 274 bool integrityCheck = false; 275 bool killAt = false; 276 bool repro = false; 277 bool swaprunCD = false; 278 bool swaprunNet = false; 279 bool thinLTOEmitImportsFiles; 280 bool thinLTOIndexOnly; 281 bool autoImport = false; 282 bool pseudoRelocs = false; 283 bool stdcallFixup = false; 284 }; 285 286 extern std::unique_ptr<Configuration> config; 287 288 } // namespace coff 289 } // namespace lld 290 291 #endif 292