xref: /freebsd/contrib/llvm-project/lld/COFF/Config.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
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"
13349cc55cSDimitry Andric #include "llvm/ADT/SetVector.h"
14*bdd1243dSDimitry Andric #include "llvm/ADT/SmallVector.h"
150b57cec5SDimitry Andric #include "llvm/ADT/StringMap.h"
160b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
170b57cec5SDimitry Andric #include "llvm/Object/COFF.h"
180b57cec5SDimitry Andric #include "llvm/Support/CachePruning.h"
19753f127fSDimitry Andric #include "llvm/Support/VirtualFileSystem.h"
200b57cec5SDimitry Andric #include <cstdint>
210b57cec5SDimitry Andric #include <map>
220b57cec5SDimitry Andric #include <set>
230b57cec5SDimitry Andric #include <string>
240b57cec5SDimitry Andric 
25*bdd1243dSDimitry Andric namespace lld::coff {
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
280b57cec5SDimitry Andric using llvm::COFF::WindowsSubsystem;
290b57cec5SDimitry Andric using llvm::StringRef;
300b57cec5SDimitry Andric class DefinedAbsolute;
310b57cec5SDimitry Andric class DefinedRelative;
320b57cec5SDimitry Andric class StringChunk;
330b57cec5SDimitry Andric class Symbol;
340b57cec5SDimitry Andric class InputFile;
35e8d8bef9SDimitry Andric class SectionChunk;
360b57cec5SDimitry Andric 
370b57cec5SDimitry Andric // Short aliases.
380b57cec5SDimitry Andric static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
390b57cec5SDimitry Andric static const auto ARM64 = llvm::COFF::IMAGE_FILE_MACHINE_ARM64;
400b57cec5SDimitry Andric static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT;
410b57cec5SDimitry Andric static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386;
420b57cec5SDimitry Andric 
430b57cec5SDimitry Andric // Represents an /export option.
440b57cec5SDimitry Andric struct Export {
450b57cec5SDimitry Andric   StringRef name;       // N in /export:N or /export:E=N
460b57cec5SDimitry Andric   StringRef extName;    // E in /export:E=N
4704eeddc0SDimitry Andric   StringRef aliasTarget; // GNU specific: N in "alias == N"
480b57cec5SDimitry Andric   Symbol *sym = nullptr;
490b57cec5SDimitry Andric   uint16_t ordinal = 0;
500b57cec5SDimitry Andric   bool noname = false;
510b57cec5SDimitry Andric   bool data = false;
520b57cec5SDimitry Andric   bool isPrivate = false;
530b57cec5SDimitry Andric   bool constant = false;
540b57cec5SDimitry Andric 
550b57cec5SDimitry Andric   // If an export is a form of /export:foo=dllname.bar, that means
560b57cec5SDimitry Andric   // that foo should be exported as an alias to bar in the DLL.
570b57cec5SDimitry Andric   // forwardTo is set to "dllname.bar" part. Usually empty.
580b57cec5SDimitry Andric   StringRef forwardTo;
590b57cec5SDimitry Andric   StringChunk *forwardChunk = nullptr;
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric   // True if this /export option was in .drectves section.
620b57cec5SDimitry Andric   bool directives = false;
630b57cec5SDimitry Andric   StringRef symbolName;
640b57cec5SDimitry Andric   StringRef exportName; // Name in DLL
650b57cec5SDimitry Andric 
660b57cec5SDimitry Andric   bool operator==(const Export &e) {
670b57cec5SDimitry Andric     return (name == e.name && extName == e.extName &&
6804eeddc0SDimitry Andric             aliasTarget == e.aliasTarget &&
690b57cec5SDimitry Andric             ordinal == e.ordinal && noname == e.noname &&
700b57cec5SDimitry Andric             data == e.data && isPrivate == e.isPrivate);
710b57cec5SDimitry Andric   }
720b57cec5SDimitry Andric };
730b57cec5SDimitry Andric 
740b57cec5SDimitry Andric enum class DebugType {
750b57cec5SDimitry Andric   None  = 0x0,
760b57cec5SDimitry Andric   CV    = 0x1,  /// CodeView
770b57cec5SDimitry Andric   PData = 0x2,  /// Procedure Data
780b57cec5SDimitry Andric   Fixup = 0x4,  /// Relocation Table
790b57cec5SDimitry Andric };
800b57cec5SDimitry Andric 
81fe6060f1SDimitry Andric enum GuardCFLevel {
82fe6060f1SDimitry Andric   Off     = 0x0,
83fe6060f1SDimitry Andric   CF      = 0x1, /// Emit gfids tables
84fe6060f1SDimitry Andric   LongJmp = 0x2, /// Emit longjmp tables
85fe6060f1SDimitry Andric   EHCont  = 0x4, /// Emit ehcont tables
86fe6060f1SDimitry Andric   All     = 0x7  /// Enable all protections
87fe6060f1SDimitry Andric };
88fe6060f1SDimitry Andric 
89fe6060f1SDimitry Andric enum class ICFLevel {
90fe6060f1SDimitry Andric   None,
91fe6060f1SDimitry Andric   Safe, // Safe ICF for all sections.
92fe6060f1SDimitry Andric   All,  // Aggressive ICF for code, but safe ICF for data, similar to MSVC's
93fe6060f1SDimitry Andric         // behavior.
940b57cec5SDimitry Andric };
950b57cec5SDimitry Andric 
960b57cec5SDimitry Andric // Global configuration.
970b57cec5SDimitry Andric struct Configuration {
98349cc55cSDimitry Andric   enum ManifestKind { Default, SideBySide, Embed, No };
99*bdd1243dSDimitry Andric   bool is64() const { return machine == AMD64 || machine == ARM64; }
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric   llvm::COFF::MachineTypes machine = IMAGE_FILE_MACHINE_UNKNOWN;
1020b57cec5SDimitry Andric   size_t wordsize;
1030b57cec5SDimitry Andric   bool verbose = false;
1040b57cec5SDimitry Andric   WindowsSubsystem subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;
1050b57cec5SDimitry Andric   Symbol *entry = nullptr;
1060b57cec5SDimitry Andric   bool noEntry = false;
1070b57cec5SDimitry Andric   std::string outputFile;
1080b57cec5SDimitry Andric   std::string importName;
1090b57cec5SDimitry Andric   bool demangle = true;
1100b57cec5SDimitry Andric   bool doGC = true;
111fe6060f1SDimitry Andric   ICFLevel doICF = ICFLevel::None;
1120b57cec5SDimitry Andric   bool tailMerge;
1130b57cec5SDimitry Andric   bool relocatable = true;
1140b57cec5SDimitry Andric   bool forceMultiple = false;
1150b57cec5SDimitry Andric   bool forceMultipleRes = false;
1160b57cec5SDimitry Andric   bool forceUnresolved = false;
1170b57cec5SDimitry Andric   bool debug = false;
1180b57cec5SDimitry Andric   bool debugDwarf = false;
1190b57cec5SDimitry Andric   bool debugGHashes = false;
1200b57cec5SDimitry Andric   bool debugSymtab = false;
121480093f4SDimitry Andric   bool driver = false;
122480093f4SDimitry Andric   bool driverUponly = false;
123480093f4SDimitry Andric   bool driverWdm = false;
1240b57cec5SDimitry Andric   bool showTiming = false;
1250b57cec5SDimitry Andric   bool showSummary = false;
1260b57cec5SDimitry Andric   unsigned debugTypes = static_cast<unsigned>(DebugType::None);
127*bdd1243dSDimitry Andric   llvm::SmallVector<llvm::StringRef, 0> mllvmOpts;
1280b57cec5SDimitry Andric   std::vector<std::string> natvisFiles;
1295ffd83dbSDimitry Andric   llvm::StringMap<std::string> namedStreams;
1300b57cec5SDimitry Andric   llvm::SmallString<128> pdbAltPath;
131349cc55cSDimitry Andric   int pdbPageSize = 4096;
1320b57cec5SDimitry Andric   llvm::SmallString<128> pdbPath;
1330b57cec5SDimitry Andric   llvm::SmallString<128> pdbSourcePath;
1340b57cec5SDimitry Andric   std::vector<llvm::StringRef> argv;
1350b57cec5SDimitry Andric 
1360b57cec5SDimitry Andric   // Symbols in this set are considered as live by the garbage collector.
1370b57cec5SDimitry Andric   std::vector<Symbol *> gcroot;
1380b57cec5SDimitry Andric 
1390b57cec5SDimitry Andric   std::set<std::string> noDefaultLibs;
1400b57cec5SDimitry Andric   bool noDefaultLibAll = false;
1410b57cec5SDimitry Andric 
1420b57cec5SDimitry Andric   // True if we are creating a DLL.
1430b57cec5SDimitry Andric   bool dll = false;
1440b57cec5SDimitry Andric   StringRef implib;
14581ad6265SDimitry Andric   bool noimplib = false;
1460b57cec5SDimitry Andric   std::vector<Export> exports;
14785868e8aSDimitry Andric   bool hadExplicitExports;
1480b57cec5SDimitry Andric   std::set<std::string> delayLoads;
1490b57cec5SDimitry Andric   std::map<std::string, int> dllOrder;
1500b57cec5SDimitry Andric   Symbol *delayLoadHelper = nullptr;
1510b57cec5SDimitry Andric 
1520b57cec5SDimitry Andric   bool saveTemps = false;
1530b57cec5SDimitry Andric 
1540b57cec5SDimitry Andric   // /guard:cf
155fe6060f1SDimitry Andric   int guardCF = GuardCFLevel::Off;
1560b57cec5SDimitry Andric 
1570b57cec5SDimitry Andric   // Used for SafeSEH.
1580b57cec5SDimitry Andric   bool safeSEH = false;
1590b57cec5SDimitry Andric   Symbol *sehTable = nullptr;
1600b57cec5SDimitry Andric   Symbol *sehCount = nullptr;
161979e22ffSDimitry Andric   bool noSEH = false;
1620b57cec5SDimitry Andric 
1630b57cec5SDimitry Andric   // Used for /opt:lldlto=N
1640b57cec5SDimitry Andric   unsigned ltoo = 2;
1650b57cec5SDimitry Andric 
1660b57cec5SDimitry Andric   // Used for /opt:lldltojobs=N
1675ffd83dbSDimitry Andric   std::string thinLTOJobs;
1680b57cec5SDimitry Andric   // Used for /opt:lldltopartitions=N
1690b57cec5SDimitry Andric   unsigned ltoPartitions = 1;
1700b57cec5SDimitry Andric 
1710b57cec5SDimitry Andric   // Used for /opt:lldltocache=path
1720b57cec5SDimitry Andric   StringRef ltoCache;
1730b57cec5SDimitry Andric   // Used for /opt:lldltocachepolicy=policy
1740b57cec5SDimitry Andric   llvm::CachePruningPolicy ltoCachePolicy;
1750b57cec5SDimitry Andric 
176e8d8bef9SDimitry Andric   // Used for /opt:[no]ltodebugpassmanager
177e8d8bef9SDimitry Andric   bool ltoDebugPassManager = false;
178e8d8bef9SDimitry Andric 
1790b57cec5SDimitry Andric   // Used for /merge:from=to (e.g. /merge:.rdata=.text)
1800b57cec5SDimitry Andric   std::map<StringRef, StringRef> merge;
1810b57cec5SDimitry Andric 
1820b57cec5SDimitry Andric   // Used for /section=.name,{DEKPRSW} to set section attributes.
1830b57cec5SDimitry Andric   std::map<StringRef, uint32_t> section;
1840b57cec5SDimitry Andric 
1850b57cec5SDimitry Andric   // Options for manifest files.
186349cc55cSDimitry Andric   ManifestKind manifest = Default;
1870b57cec5SDimitry Andric   int manifestID = 1;
188349cc55cSDimitry Andric   llvm::SetVector<StringRef> manifestDependencies;
1890b57cec5SDimitry Andric   bool manifestUAC = true;
1900b57cec5SDimitry Andric   std::vector<std::string> manifestInput;
1910b57cec5SDimitry Andric   StringRef manifestLevel = "'asInvoker'";
1920b57cec5SDimitry Andric   StringRef manifestUIAccess = "'false'";
1930b57cec5SDimitry Andric   StringRef manifestFile;
1940b57cec5SDimitry Andric 
1950b57cec5SDimitry Andric   // Used for /aligncomm.
1960b57cec5SDimitry Andric   std::map<std::string, int> alignComm;
1970b57cec5SDimitry Andric 
1980b57cec5SDimitry Andric   // Used for /failifmismatch.
1990b57cec5SDimitry Andric   std::map<StringRef, std::pair<StringRef, InputFile *>> mustMatch;
2000b57cec5SDimitry Andric 
2010b57cec5SDimitry Andric   // Used for /alternatename.
2020b57cec5SDimitry Andric   std::map<StringRef, StringRef> alternateNames;
2030b57cec5SDimitry Andric 
2040b57cec5SDimitry Andric   // Used for /order.
2050b57cec5SDimitry Andric   llvm::StringMap<int> order;
2060b57cec5SDimitry Andric 
2070b57cec5SDimitry Andric   // Used for /lldmap.
2085ffd83dbSDimitry Andric   std::string lldmapFile;
2095ffd83dbSDimitry Andric 
2105ffd83dbSDimitry Andric   // Used for /map.
2110b57cec5SDimitry Andric   std::string mapFile;
2120b57cec5SDimitry Andric 
213*bdd1243dSDimitry Andric   // Used for /mapinfo.
214*bdd1243dSDimitry Andric   bool mapInfo = false;
215*bdd1243dSDimitry Andric 
2160b57cec5SDimitry Andric   // Used for /thinlto-index-only:
2170b57cec5SDimitry Andric   llvm::StringRef thinLTOIndexOnlyArg;
2180b57cec5SDimitry Andric 
2190b57cec5SDimitry Andric   // Used for /thinlto-object-prefix-replace:
2200b57cec5SDimitry Andric   std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace;
2210b57cec5SDimitry Andric 
2220b57cec5SDimitry Andric   // Used for /thinlto-object-suffix-replace:
2230b57cec5SDimitry Andric   std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
2240b57cec5SDimitry Andric 
22585868e8aSDimitry Andric   // Used for /lto-obj-path:
22685868e8aSDimitry Andric   llvm::StringRef ltoObjPath;
22785868e8aSDimitry Andric 
228fe6060f1SDimitry Andric   // Used for /lto-cs-profile-generate:
229fe6060f1SDimitry Andric   bool ltoCSProfileGenerate = false;
230fe6060f1SDimitry Andric 
231fe6060f1SDimitry Andric   // Used for /lto-cs-profile-path
232fe6060f1SDimitry Andric   llvm::StringRef ltoCSProfileFile;
233fe6060f1SDimitry Andric 
234349cc55cSDimitry Andric   // Used for /lto-pgo-warn-mismatch:
235349cc55cSDimitry Andric   bool ltoPGOWarnMismatch = true;
236349cc55cSDimitry Andric 
237e8d8bef9SDimitry Andric   // Used for /call-graph-ordering-file:
238e8d8bef9SDimitry Andric   llvm::MapVector<std::pair<const SectionChunk *, const SectionChunk *>,
239e8d8bef9SDimitry Andric                   uint64_t>
240e8d8bef9SDimitry Andric       callGraphProfile;
241e8d8bef9SDimitry Andric   bool callGraphProfileSort = false;
242e8d8bef9SDimitry Andric 
243e8d8bef9SDimitry Andric   // Used for /print-symbol-order:
244e8d8bef9SDimitry Andric   StringRef printSymbolOrder;
245e8d8bef9SDimitry Andric 
246753f127fSDimitry Andric   // Used for /vfsoverlay:
247753f127fSDimitry Andric   std::unique_ptr<llvm::vfs::FileSystem> vfs;
248753f127fSDimitry Andric 
2490b57cec5SDimitry Andric   uint64_t align = 4096;
2500b57cec5SDimitry Andric   uint64_t imageBase = -1;
2510b57cec5SDimitry Andric   uint64_t fileAlign = 512;
2520b57cec5SDimitry Andric   uint64_t stackReserve = 1024 * 1024;
2530b57cec5SDimitry Andric   uint64_t stackCommit = 4096;
2540b57cec5SDimitry Andric   uint64_t heapReserve = 1024 * 1024;
2550b57cec5SDimitry Andric   uint64_t heapCommit = 4096;
2560b57cec5SDimitry Andric   uint32_t majorImageVersion = 0;
2570b57cec5SDimitry Andric   uint32_t minorImageVersion = 0;
258e8d8bef9SDimitry Andric   // If changing the default os/subsys version here, update the default in
259e8d8bef9SDimitry Andric   // the MinGW driver accordingly.
2600b57cec5SDimitry Andric   uint32_t majorOSVersion = 6;
2610b57cec5SDimitry Andric   uint32_t minorOSVersion = 0;
262e8d8bef9SDimitry Andric   uint32_t majorSubsystemVersion = 6;
263e8d8bef9SDimitry Andric   uint32_t minorSubsystemVersion = 0;
2640b57cec5SDimitry Andric   uint32_t timestamp = 0;
2650b57cec5SDimitry Andric   uint32_t functionPadMin = 0;
2660b57cec5SDimitry Andric   bool dynamicBase = true;
2670b57cec5SDimitry Andric   bool allowBind = true;
2685ffd83dbSDimitry Andric   bool cetCompat = false;
2690b57cec5SDimitry Andric   bool nxCompat = true;
2700b57cec5SDimitry Andric   bool allowIsolation = true;
2710b57cec5SDimitry Andric   bool terminalServerAware = true;
2720b57cec5SDimitry Andric   bool largeAddressAware = false;
2730b57cec5SDimitry Andric   bool highEntropyVA = false;
2740b57cec5SDimitry Andric   bool appContainer = false;
2750b57cec5SDimitry Andric   bool mingw = false;
2760b57cec5SDimitry Andric   bool warnMissingOrderSymbol = true;
2770b57cec5SDimitry Andric   bool warnLocallyDefinedImported = true;
2780b57cec5SDimitry Andric   bool warnDebugInfoUnusable = true;
279480093f4SDimitry Andric   bool warnLongSectionNames = true;
280fe6060f1SDimitry Andric   bool warnStdcallFixup = true;
2810b57cec5SDimitry Andric   bool incremental = true;
2820b57cec5SDimitry Andric   bool integrityCheck = false;
2830b57cec5SDimitry Andric   bool killAt = false;
2840b57cec5SDimitry Andric   bool repro = false;
2850b57cec5SDimitry Andric   bool swaprunCD = false;
2860b57cec5SDimitry Andric   bool swaprunNet = false;
2870b57cec5SDimitry Andric   bool thinLTOEmitImportsFiles;
2880b57cec5SDimitry Andric   bool thinLTOIndexOnly;
2895ffd83dbSDimitry Andric   bool autoImport = false;
2905ffd83dbSDimitry Andric   bool pseudoRelocs = false;
291fe6060f1SDimitry Andric   bool stdcallFixup = false;
292*bdd1243dSDimitry Andric   bool writeCheckSum = false;
2930b57cec5SDimitry Andric };
2940b57cec5SDimitry Andric 
295*bdd1243dSDimitry Andric } // namespace lld::coff
2960b57cec5SDimitry Andric 
2970b57cec5SDimitry Andric #endif
298