Path: blob/main/contrib/llvm-project/lld/COFF/Config.h
34870 views
//===- Config.h -------------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLD_COFF_CONFIG_H9#define LLD_COFF_CONFIG_H1011#include "llvm/ADT/MapVector.h"12#include "llvm/ADT/SetVector.h"13#include "llvm/ADT/SmallVector.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>2324namespace lld::coff {2526using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;27using llvm::COFF::WindowsSubsystem;28using llvm::StringRef;29class DefinedAbsolute;30class StringChunk;31class Symbol;32class InputFile;33class SectionChunk;3435// Short aliases.36static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;37static const auto ARM64 = llvm::COFF::IMAGE_FILE_MACHINE_ARM64;38static const auto ARM64EC = llvm::COFF::IMAGE_FILE_MACHINE_ARM64EC;39static const auto ARM64X = llvm::COFF::IMAGE_FILE_MACHINE_ARM64X;40static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT;41static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386;4243enum class ExportSource {44Unset,45Directives,46Export,47ModuleDefinition,48};4950enum class EmitKind { Obj, LLVM, ASM };5152// Represents an /export option.53struct Export {54StringRef name; // N in /export:N or /export:E=N55StringRef extName; // E in /export:E=N56StringRef exportAs; // E in /export:N,EXPORTAS,E57StringRef importName; // GNU specific: N in "othername == N"58Symbol *sym = nullptr;59uint16_t ordinal = 0;60bool noname = false;61bool data = false;62bool isPrivate = false;63bool constant = false;6465// If an export is a form of /export:foo=dllname.bar, that means66// that foo should be exported as an alias to bar in the DLL.67// forwardTo is set to "dllname.bar" part. Usually empty.68StringRef forwardTo;69StringChunk *forwardChunk = nullptr;7071ExportSource source = ExportSource::Unset;72StringRef symbolName;73StringRef exportName; // Name in DLL7475bool operator==(const Export &e) const {76return (name == e.name && extName == e.extName && exportAs == e.exportAs &&77importName == e.importName && ordinal == e.ordinal &&78noname == e.noname && data == e.data && isPrivate == e.isPrivate);79}80};8182enum class DebugType {83None = 0x0,84CV = 0x1, /// CodeView85PData = 0x2, /// Procedure Data86Fixup = 0x4, /// Relocation Table87};8889enum GuardCFLevel {90Off = 0x0,91CF = 0x1, /// Emit gfids tables92LongJmp = 0x2, /// Emit longjmp tables93EHCont = 0x4, /// Emit ehcont tables94All = 0x7 /// Enable all protections95};9697enum class ICFLevel {98None,99Safe, // Safe ICF for all sections.100All, // Aggressive ICF for code, but safe ICF for data, similar to MSVC's101// behavior.102};103104enum class BuildIDHash {105None,106PDB,107Binary,108};109110// Global configuration.111struct Configuration {112enum ManifestKind { Default, SideBySide, Embed, No };113bool is64() const { return llvm::COFF::is64Bit(machine); }114115llvm::COFF::MachineTypes machine = IMAGE_FILE_MACHINE_UNKNOWN;116size_t wordsize;117bool verbose = false;118WindowsSubsystem subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;119Symbol *entry = nullptr;120bool noEntry = false;121std::string outputFile;122std::string importName;123bool demangle = true;124bool doGC = true;125ICFLevel doICF = ICFLevel::None;126bool tailMerge;127bool relocatable = true;128bool forceMultiple = false;129bool forceMultipleRes = false;130bool forceUnresolved = false;131bool debug = false;132bool includeDwarfChunks = false;133bool debugGHashes = false;134bool writeSymtab = false;135bool driver = false;136bool driverUponly = false;137bool driverWdm = false;138bool showTiming = false;139bool showSummary = false;140bool printSearchPaths = false;141unsigned debugTypes = static_cast<unsigned>(DebugType::None);142llvm::SmallVector<llvm::StringRef, 0> mllvmOpts;143std::vector<std::string> natvisFiles;144llvm::StringMap<std::string> namedStreams;145llvm::SmallString<128> pdbAltPath;146int pdbPageSize = 4096;147llvm::SmallString<128> pdbPath;148llvm::SmallString<128> pdbSourcePath;149std::vector<llvm::StringRef> argv;150151// Symbols in this set are considered as live by the garbage collector.152std::vector<Symbol *> gcroot;153154std::set<std::string> noDefaultLibs;155bool noDefaultLibAll = false;156157// True if we are creating a DLL.158bool dll = false;159StringRef implib;160bool noimplib = false;161std::vector<Export> exports;162bool hadExplicitExports;163std::set<std::string> delayLoads;164std::map<std::string, int> dllOrder;165Symbol *delayLoadHelper = nullptr;166167bool saveTemps = false;168169// /guard:cf170int guardCF = GuardCFLevel::Off;171172// Used for SafeSEH.173bool safeSEH = false;174Symbol *sehTable = nullptr;175Symbol *sehCount = nullptr;176bool noSEH = false;177178// Used for /opt:lldlto=N179unsigned ltoo = 2;180// Used for /opt:lldltocgo=N181std::optional<unsigned> ltoCgo;182183// Used for /opt:lldltojobs=N184std::string thinLTOJobs;185// Used for /opt:lldltopartitions=N186unsigned ltoPartitions = 1;187188// Used for /lldltocache=path189StringRef ltoCache;190// Used for /lldltocachepolicy=policy191llvm::CachePruningPolicy ltoCachePolicy;192193// Used for /opt:[no]ltodebugpassmanager194bool ltoDebugPassManager = false;195196// Used for /merge:from=to (e.g. /merge:.rdata=.text)197std::map<StringRef, StringRef> merge;198199// Used for /section=.name,{DEKPRSW} to set section attributes.200std::map<StringRef, uint32_t> section;201202// Options for manifest files.203ManifestKind manifest = Default;204int manifestID = 1;205llvm::SetVector<StringRef> manifestDependencies;206bool manifestUAC = true;207std::vector<std::string> manifestInput;208StringRef manifestLevel = "'asInvoker'";209StringRef manifestUIAccess = "'false'";210StringRef manifestFile;211212// used for /dwodir213StringRef dwoDir;214215// Used for /aligncomm.216std::map<std::string, int> alignComm;217218// Used for /failifmismatch.219std::map<StringRef, std::pair<StringRef, InputFile *>> mustMatch;220221// Used for /alternatename.222std::map<StringRef, StringRef> alternateNames;223224// Used for /order.225llvm::StringMap<int> order;226227// Used for /lldmap.228std::string lldmapFile;229230// Used for /map.231std::string mapFile;232233// Used for /mapinfo.234bool mapInfo = false;235236// Used for /thinlto-index-only:237llvm::StringRef thinLTOIndexOnlyArg;238239// Used for /thinlto-prefix-replace:240// Replace the prefix in paths generated for ThinLTO, replacing241// thinLTOPrefixReplaceOld with thinLTOPrefixReplaceNew. If242// thinLTOPrefixReplaceNativeObject is defined, replace the prefix of object243// file paths written to the response file given in the244// --thinlto-index-only=${response} option with245// thinLTOPrefixReplaceNativeObject, instead of thinLTOPrefixReplaceNew.246llvm::StringRef thinLTOPrefixReplaceOld;247llvm::StringRef thinLTOPrefixReplaceNew;248llvm::StringRef thinLTOPrefixReplaceNativeObject;249250// Used for /thinlto-object-suffix-replace:251std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;252253// Used for /lto-obj-path:254llvm::StringRef ltoObjPath;255256// Used for /lto-cs-profile-generate:257bool ltoCSProfileGenerate = false;258259// Used for /lto-cs-profile-path260llvm::StringRef ltoCSProfileFile;261262// Used for /lto-pgo-warn-mismatch:263bool ltoPGOWarnMismatch = true;264265// Used for /lto-sample-profile:266llvm::StringRef ltoSampleProfileName;267268// Used for /call-graph-ordering-file:269llvm::MapVector<std::pair<const SectionChunk *, const SectionChunk *>,270uint64_t>271callGraphProfile;272bool callGraphProfileSort = false;273274// Used for /print-symbol-order:275StringRef printSymbolOrder;276277// Used for /vfsoverlay:278std::unique_ptr<llvm::vfs::FileSystem> vfs;279280uint64_t align = 4096;281uint64_t imageBase = -1;282uint64_t fileAlign = 512;283uint64_t stackReserve = 1024 * 1024;284uint64_t stackCommit = 4096;285uint64_t heapReserve = 1024 * 1024;286uint64_t heapCommit = 4096;287uint32_t majorImageVersion = 0;288uint32_t minorImageVersion = 0;289// If changing the default os/subsys version here, update the default in290// the MinGW driver accordingly.291uint32_t majorOSVersion = 6;292uint32_t minorOSVersion = 0;293uint32_t majorSubsystemVersion = 6;294uint32_t minorSubsystemVersion = 0;295uint32_t timestamp = 0;296uint32_t functionPadMin = 0;297uint32_t timeTraceGranularity = 0;298uint16_t dependentLoadFlags = 0;299bool dynamicBase = true;300bool allowBind = true;301bool cetCompat = false;302bool nxCompat = true;303bool allowIsolation = true;304bool terminalServerAware = true;305bool largeAddressAware = false;306bool highEntropyVA = false;307bool appContainer = false;308bool mingw = false;309bool warnMissingOrderSymbol = true;310bool warnLocallyDefinedImported = true;311bool warnDebugInfoUnusable = true;312bool warnLongSectionNames = true;313bool warnStdcallFixup = true;314bool incremental = true;315bool integrityCheck = false;316bool killAt = false;317bool repro = false;318bool swaprunCD = false;319bool swaprunNet = false;320bool thinLTOEmitImportsFiles;321bool thinLTOIndexOnly;322bool timeTraceEnabled = false;323bool autoImport = false;324bool pseudoRelocs = false;325bool stdcallFixup = false;326bool writeCheckSum = false;327EmitKind emit = EmitKind::Obj;328bool allowDuplicateWeak = false;329BuildIDHash buildIDHash = BuildIDHash::None;330};331332} // namespace lld::coff333334#endif335336337