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/StringMap.h" 13 #include "llvm/ADT/StringRef.h" 14 #include "llvm/Object/COFF.h" 15 #include "llvm/Support/CachePruning.h" 16 #include <cstdint> 17 #include <map> 18 #include <set> 19 #include <string> 20 21 namespace lld { 22 namespace coff { 23 24 using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN; 25 using llvm::COFF::WindowsSubsystem; 26 using llvm::StringRef; 27 class DefinedAbsolute; 28 class DefinedRelative; 29 class StringChunk; 30 class Symbol; 31 class InputFile; 32 33 // Short aliases. 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; 38 39 // Represents an /export option. 40 struct Export { 41 StringRef name; // N in /export:N or /export:E=N 42 StringRef extName; // E in /export:E=N 43 Symbol *sym = nullptr; 44 uint16_t ordinal = 0; 45 bool noname = false; 46 bool data = false; 47 bool isPrivate = false; 48 bool constant = false; 49 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. 53 StringRef forwardTo; 54 StringChunk *forwardChunk = nullptr; 55 56 // True if this /export option was in .drectves section. 57 bool directives = false; 58 StringRef symbolName; 59 StringRef exportName; // Name in DLL 60 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 && isPrivate == e.isPrivate); 65 } 66 }; 67 68 enum class DebugType { 69 None = 0x0, 70 CV = 0x1, /// CodeView 71 PData = 0x2, /// Procedure Data 72 Fixup = 0x4, /// Relocation Table 73 }; 74 75 enum class GuardCFLevel { 76 Off, 77 NoLongJmp, // Emit gfids but no longjmp tables 78 Full, // Enable all protections. 79 }; 80 81 // Global configuration. 82 struct Configuration { 83 enum ManifestKind { SideBySide, Embed, No }; 84 bool is64() { return machine == AMD64 || machine == ARM64; } 85 86 llvm::COFF::MachineTypes machine = IMAGE_FILE_MACHINE_UNKNOWN; 87 size_t wordsize; 88 bool verbose = false; 89 WindowsSubsystem subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN; 90 Symbol *entry = nullptr; 91 bool noEntry = false; 92 std::string outputFile; 93 std::string importName; 94 bool demangle = true; 95 bool doGC = true; 96 bool doICF = true; 97 bool tailMerge; 98 bool relocatable = true; 99 bool forceMultiple = false; 100 bool forceMultipleRes = false; 101 bool forceUnresolved = false; 102 bool debug = false; 103 bool debugDwarf = false; 104 bool debugGHashes = false; 105 bool debugSymtab = false; 106 bool driver = false; 107 bool driverUponly = false; 108 bool driverWdm = false; 109 bool showTiming = false; 110 bool showSummary = false; 111 unsigned debugTypes = static_cast<unsigned>(DebugType::None); 112 std::vector<std::string> natvisFiles; 113 llvm::SmallString<128> pdbAltPath; 114 llvm::SmallString<128> pdbPath; 115 llvm::SmallString<128> pdbSourcePath; 116 std::vector<llvm::StringRef> argv; 117 118 // Symbols in this set are considered as live by the garbage collector. 119 std::vector<Symbol *> gcroot; 120 121 std::set<std::string> noDefaultLibs; 122 bool noDefaultLibAll = false; 123 124 // True if we are creating a DLL. 125 bool dll = false; 126 StringRef implib; 127 std::vector<Export> exports; 128 bool hadExplicitExports; 129 std::set<std::string> delayLoads; 130 std::map<std::string, int> dllOrder; 131 Symbol *delayLoadHelper = nullptr; 132 133 bool saveTemps = false; 134 135 // /guard:cf 136 GuardCFLevel guardCF = GuardCFLevel::Off; 137 138 // Used for SafeSEH. 139 bool safeSEH = false; 140 Symbol *sehTable = nullptr; 141 Symbol *sehCount = nullptr; 142 143 // Used for /opt:lldlto=N 144 unsigned ltoo = 2; 145 146 // Used for /opt:lldltojobs=N 147 unsigned thinLTOJobs = 0; 148 // Used for /opt:lldltopartitions=N 149 unsigned ltoPartitions = 1; 150 151 // Used for /opt:lldltocache=path 152 StringRef ltoCache; 153 // Used for /opt:lldltocachepolicy=policy 154 llvm::CachePruningPolicy ltoCachePolicy; 155 156 // Used for /merge:from=to (e.g. /merge:.rdata=.text) 157 std::map<StringRef, StringRef> merge; 158 159 // Used for /section=.name,{DEKPRSW} to set section attributes. 160 std::map<StringRef, uint32_t> section; 161 162 // Options for manifest files. 163 ManifestKind manifest = No; 164 int manifestID = 1; 165 StringRef manifestDependency; 166 bool manifestUAC = true; 167 std::vector<std::string> manifestInput; 168 StringRef manifestLevel = "'asInvoker'"; 169 StringRef manifestUIAccess = "'false'"; 170 StringRef manifestFile; 171 172 // Used for /aligncomm. 173 std::map<std::string, int> alignComm; 174 175 // Used for /failifmismatch. 176 std::map<StringRef, std::pair<StringRef, InputFile *>> mustMatch; 177 178 // Used for /alternatename. 179 std::map<StringRef, StringRef> alternateNames; 180 181 // Used for /order. 182 llvm::StringMap<int> order; 183 184 // Used for /lldmap. 185 std::string mapFile; 186 187 // Used for /thinlto-index-only: 188 llvm::StringRef thinLTOIndexOnlyArg; 189 190 // Used for /thinlto-object-prefix-replace: 191 std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace; 192 193 // Used for /thinlto-object-suffix-replace: 194 std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace; 195 196 // Used for /lto-obj-path: 197 llvm::StringRef ltoObjPath; 198 199 uint64_t align = 4096; 200 uint64_t imageBase = -1; 201 uint64_t fileAlign = 512; 202 uint64_t stackReserve = 1024 * 1024; 203 uint64_t stackCommit = 4096; 204 uint64_t heapReserve = 1024 * 1024; 205 uint64_t heapCommit = 4096; 206 uint32_t majorImageVersion = 0; 207 uint32_t minorImageVersion = 0; 208 uint32_t majorOSVersion = 6; 209 uint32_t minorOSVersion = 0; 210 uint32_t timestamp = 0; 211 uint32_t functionPadMin = 0; 212 bool dynamicBase = true; 213 bool allowBind = true; 214 bool nxCompat = true; 215 bool allowIsolation = true; 216 bool terminalServerAware = true; 217 bool largeAddressAware = false; 218 bool highEntropyVA = false; 219 bool appContainer = false; 220 bool mingw = false; 221 bool warnMissingOrderSymbol = true; 222 bool warnLocallyDefinedImported = true; 223 bool warnDebugInfoUnusable = true; 224 bool warnLongSectionNames = true; 225 bool incremental = true; 226 bool integrityCheck = false; 227 bool killAt = false; 228 bool repro = false; 229 bool swaprunCD = false; 230 bool swaprunNet = false; 231 bool thinLTOEmitImportsFiles; 232 bool thinLTOIndexOnly; 233 }; 234 235 extern Configuration *config; 236 237 } // namespace coff 238 } // namespace lld 239 240 #endif 241