10b57cec5SDimitry Andric //===- Config.h -------------------------------------------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #ifndef LLD_COFF_CONFIG_H 100b57cec5SDimitry Andric #define LLD_COFF_CONFIG_H 110b57cec5SDimitry Andric 12e8d8bef9SDimitry Andric #include "llvm/ADT/MapVector.h" 13*349cc55cSDimitry Andric #include "llvm/ADT/SetVector.h" 140b57cec5SDimitry Andric #include "llvm/ADT/StringMap.h" 150b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h" 160b57cec5SDimitry Andric #include "llvm/Object/COFF.h" 170b57cec5SDimitry Andric #include "llvm/Support/CachePruning.h" 180b57cec5SDimitry Andric #include <cstdint> 190b57cec5SDimitry Andric #include <map> 200b57cec5SDimitry Andric #include <set> 210b57cec5SDimitry Andric #include <string> 220b57cec5SDimitry Andric 230b57cec5SDimitry Andric namespace lld { 240b57cec5SDimitry Andric namespace coff { 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN; 270b57cec5SDimitry Andric using llvm::COFF::WindowsSubsystem; 280b57cec5SDimitry Andric using llvm::StringRef; 290b57cec5SDimitry Andric class DefinedAbsolute; 300b57cec5SDimitry Andric class DefinedRelative; 310b57cec5SDimitry Andric class StringChunk; 320b57cec5SDimitry Andric class Symbol; 330b57cec5SDimitry Andric class InputFile; 34e8d8bef9SDimitry Andric class SectionChunk; 350b57cec5SDimitry Andric 360b57cec5SDimitry Andric // Short aliases. 370b57cec5SDimitry Andric static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64; 380b57cec5SDimitry Andric static const auto ARM64 = llvm::COFF::IMAGE_FILE_MACHINE_ARM64; 390b57cec5SDimitry Andric static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT; 400b57cec5SDimitry Andric static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386; 410b57cec5SDimitry Andric 420b57cec5SDimitry Andric // Represents an /export option. 430b57cec5SDimitry Andric struct Export { 440b57cec5SDimitry Andric StringRef name; // N in /export:N or /export:E=N 450b57cec5SDimitry Andric StringRef extName; // E in /export:E=N 460b57cec5SDimitry Andric Symbol *sym = nullptr; 470b57cec5SDimitry Andric uint16_t ordinal = 0; 480b57cec5SDimitry Andric bool noname = false; 490b57cec5SDimitry Andric bool data = false; 500b57cec5SDimitry Andric bool isPrivate = false; 510b57cec5SDimitry Andric bool constant = false; 520b57cec5SDimitry Andric 530b57cec5SDimitry Andric // If an export is a form of /export:foo=dllname.bar, that means 540b57cec5SDimitry Andric // that foo should be exported as an alias to bar in the DLL. 550b57cec5SDimitry Andric // forwardTo is set to "dllname.bar" part. Usually empty. 560b57cec5SDimitry Andric StringRef forwardTo; 570b57cec5SDimitry Andric StringChunk *forwardChunk = nullptr; 580b57cec5SDimitry Andric 590b57cec5SDimitry Andric // True if this /export option was in .drectves section. 600b57cec5SDimitry Andric bool directives = false; 610b57cec5SDimitry Andric StringRef symbolName; 620b57cec5SDimitry Andric StringRef exportName; // Name in DLL 630b57cec5SDimitry Andric 640b57cec5SDimitry Andric bool operator==(const Export &e) { 650b57cec5SDimitry Andric return (name == e.name && extName == e.extName && 660b57cec5SDimitry Andric ordinal == e.ordinal && noname == e.noname && 670b57cec5SDimitry Andric data == e.data && isPrivate == e.isPrivate); 680b57cec5SDimitry Andric } 690b57cec5SDimitry Andric }; 700b57cec5SDimitry Andric 710b57cec5SDimitry Andric enum class DebugType { 720b57cec5SDimitry Andric None = 0x0, 730b57cec5SDimitry Andric CV = 0x1, /// CodeView 740b57cec5SDimitry Andric PData = 0x2, /// Procedure Data 750b57cec5SDimitry Andric Fixup = 0x4, /// Relocation Table 760b57cec5SDimitry Andric }; 770b57cec5SDimitry Andric 78fe6060f1SDimitry Andric enum GuardCFLevel { 79fe6060f1SDimitry Andric Off = 0x0, 80fe6060f1SDimitry Andric CF = 0x1, /// Emit gfids tables 81fe6060f1SDimitry Andric LongJmp = 0x2, /// Emit longjmp tables 82fe6060f1SDimitry Andric EHCont = 0x4, /// Emit ehcont tables 83fe6060f1SDimitry Andric All = 0x7 /// Enable all protections 84fe6060f1SDimitry Andric }; 85fe6060f1SDimitry Andric 86fe6060f1SDimitry Andric enum class ICFLevel { 87fe6060f1SDimitry Andric None, 88fe6060f1SDimitry Andric Safe, // Safe ICF for all sections. 89fe6060f1SDimitry Andric All, // Aggressive ICF for code, but safe ICF for data, similar to MSVC's 90fe6060f1SDimitry Andric // behavior. 910b57cec5SDimitry Andric }; 920b57cec5SDimitry Andric 930b57cec5SDimitry Andric // Global configuration. 940b57cec5SDimitry Andric struct Configuration { 95*349cc55cSDimitry Andric enum ManifestKind { Default, SideBySide, Embed, No }; 960b57cec5SDimitry Andric bool is64() { return machine == AMD64 || machine == ARM64; } 970b57cec5SDimitry Andric 980b57cec5SDimitry Andric llvm::COFF::MachineTypes machine = IMAGE_FILE_MACHINE_UNKNOWN; 990b57cec5SDimitry Andric size_t wordsize; 1000b57cec5SDimitry Andric bool verbose = false; 1010b57cec5SDimitry Andric WindowsSubsystem subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN; 1020b57cec5SDimitry Andric Symbol *entry = nullptr; 1030b57cec5SDimitry Andric bool noEntry = false; 1040b57cec5SDimitry Andric std::string outputFile; 1050b57cec5SDimitry Andric std::string importName; 1060b57cec5SDimitry Andric bool demangle = true; 1070b57cec5SDimitry Andric bool doGC = true; 108fe6060f1SDimitry Andric ICFLevel doICF = ICFLevel::None; 1090b57cec5SDimitry Andric bool tailMerge; 1100b57cec5SDimitry Andric bool relocatable = true; 1110b57cec5SDimitry Andric bool forceMultiple = false; 1120b57cec5SDimitry Andric bool forceMultipleRes = false; 1130b57cec5SDimitry Andric bool forceUnresolved = false; 1140b57cec5SDimitry Andric bool debug = false; 1150b57cec5SDimitry Andric bool debugDwarf = false; 1160b57cec5SDimitry Andric bool debugGHashes = false; 1170b57cec5SDimitry Andric bool debugSymtab = false; 118480093f4SDimitry Andric bool driver = false; 119480093f4SDimitry Andric bool driverUponly = false; 120480093f4SDimitry Andric bool driverWdm = false; 1210b57cec5SDimitry Andric bool showTiming = false; 1220b57cec5SDimitry Andric bool showSummary = false; 1230b57cec5SDimitry Andric unsigned debugTypes = static_cast<unsigned>(DebugType::None); 1240b57cec5SDimitry Andric std::vector<std::string> natvisFiles; 1255ffd83dbSDimitry Andric llvm::StringMap<std::string> namedStreams; 1260b57cec5SDimitry Andric llvm::SmallString<128> pdbAltPath; 127*349cc55cSDimitry Andric int pdbPageSize = 4096; 1280b57cec5SDimitry Andric llvm::SmallString<128> pdbPath; 1290b57cec5SDimitry Andric llvm::SmallString<128> pdbSourcePath; 1300b57cec5SDimitry Andric std::vector<llvm::StringRef> argv; 1310b57cec5SDimitry Andric 1320b57cec5SDimitry Andric // Symbols in this set are considered as live by the garbage collector. 1330b57cec5SDimitry Andric std::vector<Symbol *> gcroot; 1340b57cec5SDimitry Andric 1350b57cec5SDimitry Andric std::set<std::string> noDefaultLibs; 1360b57cec5SDimitry Andric bool noDefaultLibAll = false; 1370b57cec5SDimitry Andric 1380b57cec5SDimitry Andric // True if we are creating a DLL. 1390b57cec5SDimitry Andric bool dll = false; 1400b57cec5SDimitry Andric StringRef implib; 1410b57cec5SDimitry Andric std::vector<Export> exports; 14285868e8aSDimitry Andric bool hadExplicitExports; 1430b57cec5SDimitry Andric std::set<std::string> delayLoads; 1440b57cec5SDimitry Andric std::map<std::string, int> dllOrder; 1450b57cec5SDimitry Andric Symbol *delayLoadHelper = nullptr; 1460b57cec5SDimitry Andric 1470b57cec5SDimitry Andric bool saveTemps = false; 1480b57cec5SDimitry Andric 1490b57cec5SDimitry Andric // /guard:cf 150fe6060f1SDimitry Andric int guardCF = GuardCFLevel::Off; 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andric // Used for SafeSEH. 1530b57cec5SDimitry Andric bool safeSEH = false; 1540b57cec5SDimitry Andric Symbol *sehTable = nullptr; 1550b57cec5SDimitry Andric Symbol *sehCount = nullptr; 156979e22ffSDimitry Andric bool noSEH = false; 1570b57cec5SDimitry Andric 1580b57cec5SDimitry Andric // Used for /opt:lldlto=N 1590b57cec5SDimitry Andric unsigned ltoo = 2; 1600b57cec5SDimitry Andric 1610b57cec5SDimitry Andric // Used for /opt:lldltojobs=N 1625ffd83dbSDimitry Andric std::string thinLTOJobs; 1630b57cec5SDimitry Andric // Used for /opt:lldltopartitions=N 1640b57cec5SDimitry Andric unsigned ltoPartitions = 1; 1650b57cec5SDimitry Andric 1660b57cec5SDimitry Andric // Used for /opt:lldltocache=path 1670b57cec5SDimitry Andric StringRef ltoCache; 1680b57cec5SDimitry Andric // Used for /opt:lldltocachepolicy=policy 1690b57cec5SDimitry Andric llvm::CachePruningPolicy ltoCachePolicy; 1700b57cec5SDimitry Andric 171e8d8bef9SDimitry Andric // Used for /opt:[no]ltonewpassmanager 172e8d8bef9SDimitry Andric bool ltoNewPassManager = false; 173e8d8bef9SDimitry Andric // Used for /opt:[no]ltodebugpassmanager 174e8d8bef9SDimitry Andric bool ltoDebugPassManager = false; 175e8d8bef9SDimitry Andric 1760b57cec5SDimitry Andric // Used for /merge:from=to (e.g. /merge:.rdata=.text) 1770b57cec5SDimitry Andric std::map<StringRef, StringRef> merge; 1780b57cec5SDimitry Andric 1790b57cec5SDimitry Andric // Used for /section=.name,{DEKPRSW} to set section attributes. 1800b57cec5SDimitry Andric std::map<StringRef, uint32_t> section; 1810b57cec5SDimitry Andric 1820b57cec5SDimitry Andric // Options for manifest files. 183*349cc55cSDimitry Andric ManifestKind manifest = Default; 1840b57cec5SDimitry Andric int manifestID = 1; 185*349cc55cSDimitry Andric llvm::SetVector<StringRef> manifestDependencies; 1860b57cec5SDimitry Andric bool manifestUAC = true; 1870b57cec5SDimitry Andric std::vector<std::string> manifestInput; 1880b57cec5SDimitry Andric StringRef manifestLevel = "'asInvoker'"; 1890b57cec5SDimitry Andric StringRef manifestUIAccess = "'false'"; 1900b57cec5SDimitry Andric StringRef manifestFile; 1910b57cec5SDimitry Andric 1920b57cec5SDimitry Andric // Used for /aligncomm. 1930b57cec5SDimitry Andric std::map<std::string, int> alignComm; 1940b57cec5SDimitry Andric 1950b57cec5SDimitry Andric // Used for /failifmismatch. 1960b57cec5SDimitry Andric std::map<StringRef, std::pair<StringRef, InputFile *>> mustMatch; 1970b57cec5SDimitry Andric 1980b57cec5SDimitry Andric // Used for /alternatename. 1990b57cec5SDimitry Andric std::map<StringRef, StringRef> alternateNames; 2000b57cec5SDimitry Andric 2010b57cec5SDimitry Andric // Used for /order. 2020b57cec5SDimitry Andric llvm::StringMap<int> order; 2030b57cec5SDimitry Andric 2040b57cec5SDimitry Andric // Used for /lldmap. 2055ffd83dbSDimitry Andric std::string lldmapFile; 2065ffd83dbSDimitry Andric 2075ffd83dbSDimitry Andric // Used for /map. 2080b57cec5SDimitry Andric std::string mapFile; 2090b57cec5SDimitry Andric 2100b57cec5SDimitry Andric // Used for /thinlto-index-only: 2110b57cec5SDimitry Andric llvm::StringRef thinLTOIndexOnlyArg; 2120b57cec5SDimitry Andric 2130b57cec5SDimitry Andric // Used for /thinlto-object-prefix-replace: 2140b57cec5SDimitry Andric std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace; 2150b57cec5SDimitry Andric 2160b57cec5SDimitry Andric // Used for /thinlto-object-suffix-replace: 2170b57cec5SDimitry Andric std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace; 2180b57cec5SDimitry Andric 21985868e8aSDimitry Andric // Used for /lto-obj-path: 22085868e8aSDimitry Andric llvm::StringRef ltoObjPath; 22185868e8aSDimitry Andric 222fe6060f1SDimitry Andric // Used for /lto-cs-profile-generate: 223fe6060f1SDimitry Andric bool ltoCSProfileGenerate = false; 224fe6060f1SDimitry Andric 225fe6060f1SDimitry Andric // Used for /lto-cs-profile-path 226fe6060f1SDimitry Andric llvm::StringRef ltoCSProfileFile; 227fe6060f1SDimitry Andric 228*349cc55cSDimitry Andric // Used for /lto-pgo-warn-mismatch: 229*349cc55cSDimitry Andric bool ltoPGOWarnMismatch = true; 230*349cc55cSDimitry Andric 231e8d8bef9SDimitry Andric // Used for /call-graph-ordering-file: 232e8d8bef9SDimitry Andric llvm::MapVector<std::pair<const SectionChunk *, const SectionChunk *>, 233e8d8bef9SDimitry Andric uint64_t> 234e8d8bef9SDimitry Andric callGraphProfile; 235e8d8bef9SDimitry Andric bool callGraphProfileSort = false; 236e8d8bef9SDimitry Andric 237e8d8bef9SDimitry Andric // Used for /print-symbol-order: 238e8d8bef9SDimitry Andric StringRef printSymbolOrder; 239e8d8bef9SDimitry Andric 2400b57cec5SDimitry Andric uint64_t align = 4096; 2410b57cec5SDimitry Andric uint64_t imageBase = -1; 2420b57cec5SDimitry Andric uint64_t fileAlign = 512; 2430b57cec5SDimitry Andric uint64_t stackReserve = 1024 * 1024; 2440b57cec5SDimitry Andric uint64_t stackCommit = 4096; 2450b57cec5SDimitry Andric uint64_t heapReserve = 1024 * 1024; 2460b57cec5SDimitry Andric uint64_t heapCommit = 4096; 2470b57cec5SDimitry Andric uint32_t majorImageVersion = 0; 2480b57cec5SDimitry Andric uint32_t minorImageVersion = 0; 249e8d8bef9SDimitry Andric // If changing the default os/subsys version here, update the default in 250e8d8bef9SDimitry Andric // the MinGW driver accordingly. 2510b57cec5SDimitry Andric uint32_t majorOSVersion = 6; 2520b57cec5SDimitry Andric uint32_t minorOSVersion = 0; 253e8d8bef9SDimitry Andric uint32_t majorSubsystemVersion = 6; 254e8d8bef9SDimitry Andric uint32_t minorSubsystemVersion = 0; 2550b57cec5SDimitry Andric uint32_t timestamp = 0; 2560b57cec5SDimitry Andric uint32_t functionPadMin = 0; 2570b57cec5SDimitry Andric bool dynamicBase = true; 2580b57cec5SDimitry Andric bool allowBind = true; 2595ffd83dbSDimitry Andric bool cetCompat = false; 2600b57cec5SDimitry Andric bool nxCompat = true; 2610b57cec5SDimitry Andric bool allowIsolation = true; 2620b57cec5SDimitry Andric bool terminalServerAware = true; 2630b57cec5SDimitry Andric bool largeAddressAware = false; 2640b57cec5SDimitry Andric bool highEntropyVA = false; 2650b57cec5SDimitry Andric bool appContainer = false; 2660b57cec5SDimitry Andric bool mingw = false; 2670b57cec5SDimitry Andric bool warnMissingOrderSymbol = true; 2680b57cec5SDimitry Andric bool warnLocallyDefinedImported = true; 2690b57cec5SDimitry Andric bool warnDebugInfoUnusable = true; 270480093f4SDimitry Andric bool warnLongSectionNames = true; 271fe6060f1SDimitry Andric bool warnStdcallFixup = true; 2720b57cec5SDimitry Andric bool incremental = true; 2730b57cec5SDimitry Andric bool integrityCheck = false; 2740b57cec5SDimitry Andric bool killAt = false; 2750b57cec5SDimitry Andric bool repro = false; 2760b57cec5SDimitry Andric bool swaprunCD = false; 2770b57cec5SDimitry Andric bool swaprunNet = false; 2780b57cec5SDimitry Andric bool thinLTOEmitImportsFiles; 2790b57cec5SDimitry Andric bool thinLTOIndexOnly; 2805ffd83dbSDimitry Andric bool autoImport = false; 2815ffd83dbSDimitry Andric bool pseudoRelocs = false; 282fe6060f1SDimitry Andric bool stdcallFixup = false; 2830b57cec5SDimitry Andric }; 2840b57cec5SDimitry Andric 2850b57cec5SDimitry Andric extern Configuration *config; 2860b57cec5SDimitry Andric 2870b57cec5SDimitry Andric } // namespace coff 2880b57cec5SDimitry Andric } // namespace lld 2890b57cec5SDimitry Andric 2900b57cec5SDimitry Andric #endif 291