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 "llvm/Support/VirtualFileSystem.h" 19 #include <cstdint> 20 #include <map> 21 #include <set> 22 #include <string> 23 24 namespace lld { 25 namespace coff { 26 27 using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN; 28 using llvm::COFF::WindowsSubsystem; 29 using llvm::StringRef; 30 class DefinedAbsolute; 31 class DefinedRelative; 32 class StringChunk; 33 class Symbol; 34 class InputFile; 35 class SectionChunk; 36 37 // Short aliases. 38 static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64; 39 static const auto ARM64 = llvm::COFF::IMAGE_FILE_MACHINE_ARM64; 40 static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT; 41 static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386; 42 43 // Represents an /export option. 44 struct Export { 45 StringRef name; // N in /export:N or /export:E=N 46 StringRef extName; // E in /export:E=N 47 StringRef aliasTarget; // GNU specific: N in "alias == N" 48 Symbol *sym = nullptr; 49 uint16_t ordinal = 0; 50 bool noname = false; 51 bool data = false; 52 bool isPrivate = false; 53 bool constant = false; 54 55 // If an export is a form of /export:foo=dllname.bar, that means 56 // that foo should be exported as an alias to bar in the DLL. 57 // forwardTo is set to "dllname.bar" part. Usually empty. 58 StringRef forwardTo; 59 StringChunk *forwardChunk = nullptr; 60 61 // True if this /export option was in .drectves section. 62 bool directives = false; 63 StringRef symbolName; 64 StringRef exportName; // Name in DLL 65 66 bool operator==(const Export &e) { 67 return (name == e.name && extName == e.extName && 68 aliasTarget == e.aliasTarget && 69 ordinal == e.ordinal && noname == e.noname && 70 data == e.data && isPrivate == e.isPrivate); 71 } 72 }; 73 74 enum class DebugType { 75 None = 0x0, 76 CV = 0x1, /// CodeView 77 PData = 0x2, /// Procedure Data 78 Fixup = 0x4, /// Relocation Table 79 }; 80 81 enum GuardCFLevel { 82 Off = 0x0, 83 CF = 0x1, /// Emit gfids tables 84 LongJmp = 0x2, /// Emit longjmp tables 85 EHCont = 0x4, /// Emit ehcont tables 86 All = 0x7 /// Enable all protections 87 }; 88 89 enum class ICFLevel { 90 None, 91 Safe, // Safe ICF for all sections. 92 All, // Aggressive ICF for code, but safe ICF for data, similar to MSVC's 93 // behavior. 94 }; 95 96 // Global configuration. 97 struct Configuration { 98 enum ManifestKind { Default, SideBySide, Embed, No }; 99 bool is64() { return machine == AMD64 || machine == ARM64; } 100 101 llvm::COFF::MachineTypes machine = IMAGE_FILE_MACHINE_UNKNOWN; 102 size_t wordsize; 103 bool verbose = false; 104 WindowsSubsystem subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN; 105 Symbol *entry = nullptr; 106 bool noEntry = false; 107 std::string outputFile; 108 std::string importName; 109 bool demangle = true; 110 bool doGC = true; 111 ICFLevel doICF = ICFLevel::None; 112 bool tailMerge; 113 bool relocatable = true; 114 bool forceMultiple = false; 115 bool forceMultipleRes = false; 116 bool forceUnresolved = false; 117 bool debug = false; 118 bool debugDwarf = false; 119 bool debugGHashes = false; 120 bool debugSymtab = false; 121 bool driver = false; 122 bool driverUponly = false; 123 bool driverWdm = false; 124 bool showTiming = false; 125 bool showSummary = false; 126 unsigned debugTypes = static_cast<unsigned>(DebugType::None); 127 std::vector<std::string> natvisFiles; 128 llvm::StringMap<std::string> namedStreams; 129 llvm::SmallString<128> pdbAltPath; 130 int pdbPageSize = 4096; 131 llvm::SmallString<128> pdbPath; 132 llvm::SmallString<128> pdbSourcePath; 133 std::vector<llvm::StringRef> argv; 134 135 // Symbols in this set are considered as live by the garbage collector. 136 std::vector<Symbol *> gcroot; 137 138 std::set<std::string> noDefaultLibs; 139 bool noDefaultLibAll = false; 140 141 // True if we are creating a DLL. 142 bool dll = false; 143 StringRef implib; 144 bool noimplib = false; 145 std::vector<Export> exports; 146 bool hadExplicitExports; 147 std::set<std::string> delayLoads; 148 std::map<std::string, int> dllOrder; 149 Symbol *delayLoadHelper = nullptr; 150 151 bool saveTemps = false; 152 153 // /guard:cf 154 int guardCF = GuardCFLevel::Off; 155 156 // Used for SafeSEH. 157 bool safeSEH = false; 158 Symbol *sehTable = nullptr; 159 Symbol *sehCount = nullptr; 160 bool noSEH = false; 161 162 // Used for /opt:lldlto=N 163 unsigned ltoo = 2; 164 165 // Used for /opt:lldltojobs=N 166 std::string thinLTOJobs; 167 // Used for /opt:lldltopartitions=N 168 unsigned ltoPartitions = 1; 169 170 // Used for /opt:lldltocache=path 171 StringRef ltoCache; 172 // Used for /opt:lldltocachepolicy=policy 173 llvm::CachePruningPolicy ltoCachePolicy; 174 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 // Used for /vfsoverlay: 243 std::unique_ptr<llvm::vfs::FileSystem> vfs; 244 245 uint64_t align = 4096; 246 uint64_t imageBase = -1; 247 uint64_t fileAlign = 512; 248 uint64_t stackReserve = 1024 * 1024; 249 uint64_t stackCommit = 4096; 250 uint64_t heapReserve = 1024 * 1024; 251 uint64_t heapCommit = 4096; 252 uint32_t majorImageVersion = 0; 253 uint32_t minorImageVersion = 0; 254 // If changing the default os/subsys version here, update the default in 255 // the MinGW driver accordingly. 256 uint32_t majorOSVersion = 6; 257 uint32_t minorOSVersion = 0; 258 uint32_t majorSubsystemVersion = 6; 259 uint32_t minorSubsystemVersion = 0; 260 uint32_t timestamp = 0; 261 uint32_t functionPadMin = 0; 262 bool dynamicBase = true; 263 bool allowBind = true; 264 bool cetCompat = false; 265 bool nxCompat = true; 266 bool allowIsolation = true; 267 bool terminalServerAware = true; 268 bool largeAddressAware = false; 269 bool highEntropyVA = false; 270 bool appContainer = false; 271 bool mingw = false; 272 bool warnMissingOrderSymbol = true; 273 bool warnLocallyDefinedImported = true; 274 bool warnDebugInfoUnusable = true; 275 bool warnLongSectionNames = true; 276 bool warnStdcallFixup = true; 277 bool incremental = true; 278 bool integrityCheck = false; 279 bool killAt = false; 280 bool repro = false; 281 bool swaprunCD = false; 282 bool swaprunNet = false; 283 bool thinLTOEmitImportsFiles; 284 bool thinLTOIndexOnly; 285 bool autoImport = false; 286 bool pseudoRelocs = false; 287 bool stdcallFixup = false; 288 }; 289 290 extern std::unique_ptr<Configuration> config; 291 292 } // namespace coff 293 } // namespace lld 294 295 #endif 296