1 //===- Config.h -------------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Linker 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLD_ELF_CONFIG_H 11 #define LLD_ELF_CONFIG_H 12 13 #include "llvm/ADT/CachedHashString.h" 14 #include "llvm/ADT/MapVector.h" 15 #include "llvm/ADT/StringRef.h" 16 #include "llvm/Support/ELF.h" 17 18 #include <vector> 19 20 namespace lld { 21 namespace elf { 22 23 class InputFile; 24 struct Symbol; 25 26 enum ELFKind { 27 ELFNoneKind, 28 ELF32LEKind, 29 ELF32BEKind, 30 ELF64LEKind, 31 ELF64BEKind 32 }; 33 34 // For --build-id. 35 enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid }; 36 37 // For --discard-{all,locals,none}. 38 enum class DiscardPolicy { Default, All, Locals, None }; 39 40 // For --strip-{all,debug}. 41 enum class StripPolicy { None, All, Debug }; 42 43 // For --unresolved-symbols. 44 enum class UnresolvedPolicy { NoUndef, ReportError, Warn, Ignore }; 45 46 // For --sort-section and linkerscript sorting rules. 47 enum class SortSectionPolicy { Default, None, Alignment, Name, Priority }; 48 49 // For --target2 50 enum class Target2Policy { Abs, Rel, GotRel }; 51 52 struct SymbolVersion { 53 llvm::StringRef Name; 54 bool IsExternCpp; 55 bool HasWildcard; 56 }; 57 58 // This struct contains symbols version definition that 59 // can be found in version script if it is used for link. 60 struct VersionDefinition { 61 VersionDefinition(llvm::StringRef Name, uint16_t Id) : Name(Name), Id(Id) {} 62 llvm::StringRef Name; 63 uint16_t Id; 64 std::vector<SymbolVersion> Globals; 65 size_t NameOff; // Offset in string table. 66 }; 67 68 // This struct contains the global configuration for the linker. 69 // Most fields are direct mapping from the command line options 70 // and such fields have the same name as the corresponding options. 71 // Most fields are initialized by the driver. 72 struct Configuration { 73 InputFile *FirstElf = nullptr; 74 uint8_t OSABI = 0; 75 llvm::DenseMap<llvm::CachedHashStringRef, unsigned> SymbolOrderingFile; 76 llvm::StringMap<uint64_t> SectionStartMap; 77 llvm::StringRef DynamicLinker; 78 llvm::StringRef Entry; 79 llvm::StringRef Emulation; 80 llvm::StringRef Fini; 81 llvm::StringRef Init; 82 llvm::StringRef LTOAAPipeline; 83 llvm::StringRef LTONewPmPasses; 84 llvm::StringRef OutputFile; 85 llvm::StringRef SoName; 86 llvm::StringRef Sysroot; 87 std::string RPath; 88 std::vector<VersionDefinition> VersionDefinitions; 89 std::vector<llvm::StringRef> AuxiliaryList; 90 std::vector<llvm::StringRef> SearchPaths; 91 std::vector<llvm::StringRef> Undefined; 92 std::vector<SymbolVersion> VersionScriptGlobals; 93 std::vector<SymbolVersion> VersionScriptLocals; 94 std::vector<uint8_t> BuildIdVector; 95 bool AllowMultipleDefinition; 96 bool AsNeeded = false; 97 bool Bsymbolic; 98 bool BsymbolicFunctions; 99 bool ColorDiagnostics = false; 100 bool Demangle = true; 101 bool DisableVerify; 102 bool EhFrameHdr; 103 bool EnableNewDtags; 104 bool ExportDynamic; 105 bool FatalWarnings; 106 bool GcSections; 107 bool GdbIndex; 108 bool GnuHash = false; 109 bool ICF; 110 bool Mips64EL = false; 111 bool MipsN32Abi = false; 112 bool NoGnuUnique; 113 bool NoUndefinedVersion; 114 bool Nostdlib; 115 bool OFormatBinary; 116 bool OMagic; 117 bool Pic; 118 bool Pie; 119 bool PrintGcSections; 120 bool Rela; 121 bool Relocatable; 122 bool SaveTemps; 123 bool SingleRoRx; 124 bool Shared; 125 bool Static = false; 126 bool SysvHash = true; 127 bool Target1Rel; 128 bool Threads; 129 bool Trace; 130 bool Verbose; 131 bool WarnCommon; 132 bool WarnMissingEntry; 133 bool ZCombreloc; 134 bool ZExecstack; 135 bool ZNodelete; 136 bool ZNow; 137 bool ZOrigin; 138 bool ZRelro; 139 bool ExitEarly; 140 bool ZWxneeded; 141 DiscardPolicy Discard; 142 SortSectionPolicy SortSection; 143 StripPolicy Strip = StripPolicy::None; 144 UnresolvedPolicy UnresolvedSymbols; 145 Target2Policy Target2 = Target2Policy::GotRel; 146 BuildIdKind BuildId = BuildIdKind::None; 147 ELFKind EKind = ELFNoneKind; 148 uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL; 149 uint16_t EMachine = llvm::ELF::EM_NONE; 150 uint64_t ErrorLimit = 20; 151 uint64_t ImageBase; 152 uint64_t MaxPageSize; 153 uint64_t ZStackSize; 154 unsigned LTOPartitions; 155 unsigned LTOO; 156 unsigned Optimize; 157 unsigned ThinLTOJobs; 158 }; 159 160 // The only instance of Configuration struct. 161 extern Configuration *Config; 162 163 } // namespace elf 164 } // namespace lld 165 166 #endif 167