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/MapVector.h" 14 #include "llvm/ADT/StringRef.h" 15 #include "llvm/ADT/StringSet.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} and --retain-symbols-file. 38 enum class DiscardPolicy { Default, All, Locals, RetainFile, 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::StringMap<uint64_t> SectionStartMap; 76 llvm::StringRef DynamicLinker; 77 llvm::StringRef Entry; 78 llvm::StringRef Emulation; 79 llvm::StringRef Fini; 80 llvm::StringRef Init; 81 llvm::StringRef LTOAAPipeline; 82 llvm::StringRef LTONewPmPasses; 83 llvm::StringRef OutputFile; 84 llvm::StringRef SoName; 85 llvm::StringRef Sysroot; 86 llvm::StringSet<> RetainSymbolsFile; 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> SymbolOrderingFile; 92 std::vector<llvm::StringRef> Undefined; 93 std::vector<SymbolVersion> VersionScriptGlobals; 94 std::vector<SymbolVersion> VersionScriptLocals; 95 std::vector<uint8_t> BuildIdVector; 96 bool AllowMultipleDefinition; 97 bool AsNeeded = false; 98 bool Bsymbolic; 99 bool BsymbolicFunctions; 100 bool ColorDiagnostics = false; 101 bool Demangle = true; 102 bool DisableVerify; 103 bool EhFrameHdr; 104 bool EnableNewDtags; 105 bool ExportDynamic; 106 bool FatalWarnings; 107 bool GcSections; 108 bool GdbIndex; 109 bool GnuHash = false; 110 bool ICF; 111 bool Mips64EL = false; 112 bool MipsN32Abi = false; 113 bool NoGnuUnique; 114 bool NoUndefinedVersion; 115 bool Nostdlib; 116 bool OFormatBinary; 117 bool OMagic; 118 bool Pic; 119 bool Pie; 120 bool PrintGcSections; 121 bool Rela; 122 bool Relocatable; 123 bool SaveTemps; 124 bool SingleRoRx; 125 bool Shared; 126 bool Static = false; 127 bool SysvHash = true; 128 bool Target1Rel; 129 bool Threads; 130 bool Trace; 131 bool Verbose; 132 bool WarnCommon; 133 bool WarnMissingEntry; 134 bool ZCombreloc; 135 bool ZExecstack; 136 bool ZNodelete; 137 bool ZNow; 138 bool ZOrigin; 139 bool ZRelro; 140 bool ExitEarly; 141 bool ZWxneeded; 142 DiscardPolicy Discard; 143 SortSectionPolicy SortSection; 144 StripPolicy Strip = StripPolicy::None; 145 UnresolvedPolicy UnresolvedSymbols; 146 Target2Policy Target2 = Target2Policy::GotRel; 147 BuildIdKind BuildId = BuildIdKind::None; 148 ELFKind EKind = ELFNoneKind; 149 uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL; 150 uint16_t EMachine = llvm::ELF::EM_NONE; 151 uint64_t ErrorLimit = 20; 152 uint64_t ImageBase; 153 uint64_t MaxPageSize; 154 uint64_t ZStackSize; 155 unsigned LTOPartitions; 156 unsigned LTOO; 157 unsigned Optimize; 158 unsigned ThinLTOJobs; 159 }; 160 161 // The only instance of Configuration struct. 162 extern Configuration *Config; 163 164 } // namespace elf 165 } // namespace lld 166 167 #endif 168