1 //===- Config.h -------------------------------------------------*- C++ -*-===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLD_ELF_CONFIG_H
11 #define LLD_ELF_CONFIG_H
13 #include "llvm/ADT/MapVector.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/StringSet.h"
16 #include "llvm/BinaryFormat/ELF.h"
17 #include "llvm/Support/CachePruning.h"
18 #include "llvm/Support/CodeGen.h"
19 #include "llvm/Support/Endian.h"
38 enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid };
40 // For --discard-{all,locals,none}.
41 enum class DiscardPolicy { Default, All, Locals, None };
43 // For --strip-{all,debug}.
44 enum class StripPolicy { None, All, Debug };
46 // For --unresolved-symbols.
47 enum class UnresolvedPolicy { ReportError, Warn, WarnAll, Ignore, IgnoreAll };
49 // For --sort-section and linkerscript sorting rules.
50 enum class SortSectionPolicy { Default, None, Alignment, Name, Priority };
53 enum class Target2Policy { Abs, Rel, GotRel };
55 struct SymbolVersion {
61 // This struct contains symbols version definition that
62 // can be found in version script if it is used for link.
63 struct VersionDefinition {
66 std::vector<SymbolVersion> Globals;
67 size_t NameOff = 0; // Offset in the string table
70 // Structure for mapping renamed symbols
71 struct RenamedSymbol {
73 uint8_t OriginalBinding;
76 // This struct contains the global configuration for the linker.
77 // Most fields are direct mapping from the command line options
78 // and such fields have the same name as the corresponding options.
79 // Most fields are initialized by the driver.
80 struct Configuration {
81 InputFile *FirstElf = nullptr;
83 llvm::CachePruningPolicy ThinLTOCachePolicy;
84 llvm::StringMap<uint64_t> SectionStartMap;
85 llvm::StringRef DynamicLinker;
86 llvm::StringRef Entry;
87 llvm::StringRef Emulation;
90 llvm::StringRef LTOAAPipeline;
91 llvm::StringRef LTONewPmPasses;
92 llvm::StringRef MapFile;
93 llvm::StringRef OutputFile;
94 llvm::StringRef OptRemarksFilename;
95 llvm::StringRef SoName;
96 llvm::StringRef Sysroot;
97 llvm::StringRef ThinLTOCacheDir;
99 std::vector<VersionDefinition> VersionDefinitions;
100 std::vector<llvm::StringRef> Argv;
101 std::vector<llvm::StringRef> AuxiliaryList;
102 std::vector<llvm::StringRef> FilterList;
103 std::vector<llvm::StringRef> SearchPaths;
104 std::vector<llvm::StringRef> SymbolOrderingFile;
105 std::vector<llvm::StringRef> Undefined;
106 std::vector<SymbolVersion> VersionScriptGlobals;
107 std::vector<SymbolVersion> VersionScriptLocals;
108 std::vector<uint8_t> BuildIdVector;
109 llvm::MapVector<Symbol *, RenamedSymbol> RenamedSymbols;
110 bool AllowMultipleDefinition;
111 bool AsNeeded = false;
113 bool BsymbolicFunctions;
114 bool ColorDiagnostics = false;
115 bool CompressDebugSections;
117 bool Demangle = true;
128 bool MipsN32Abi = false;
130 bool NoUndefinedVersion;
134 bool OptRemarksWithHotness;
136 bool PrintGcSections;
148 bool WarnMissingEntry;
161 DiscardPolicy Discard;
162 SortSectionPolicy SortSection;
164 UnresolvedPolicy UnresolvedSymbols;
165 Target2Policy Target2;
166 BuildIdKind BuildId = BuildIdKind::None;
167 ELFKind EKind = ELFNoneKind;
168 uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
169 uint16_t EMachine = llvm::ELF::EM_NONE;
170 uint64_t ErrorLimit = 20;
172 uint64_t MaxPageSize;
174 unsigned LTOPartitions;
177 unsigned ThinLTOJobs;
179 // The following config options do not directly correspond to any
180 // particualr command line options.
182 // True if we need to pass through relocations in input files to the
183 // output file. Usually false because we consume relocations.
186 // True if the target is ELF64. False if ELF32.
189 // True if the target is little-endian. False if big-endian.
192 // endianness::little if IsLE is true. endianness::big otherwise.
193 llvm::support::endianness Endianness;
195 // True if the target is the little-endian MIPS64.
197 // The reason why we have this variable only for the MIPS is because
198 // we use this often. Some ELF headers for MIPS64EL are in a
199 // mixed-endian (which is horrible and I'd say that's a serious spec
200 // bug), and we need to know whether we are reading MIPS ELF files or
201 // not in various places.
203 // (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
204 // name whatever that means. A fun hypothesis is that "EL" is short for
205 // little-endian written in the little-endian order, but I don't know
209 // The ELF spec defines two types of relocation table entries, RELA and
210 // REL. RELA is a triplet of (offset, info, addend) while REL is a
211 // tuple of (offset, info). Addends for REL are implicit and read from
212 // the location where the relocations are applied. So, REL is more
213 // compact than RELA but requires a bit of more work to process.
215 // (From the linker writer's view, this distinction is not necessary.
216 // If the ELF had chosen whichever and sticked with it, it would have
217 // been easier to write code to process relocations, but it's too late
218 // to change the spec.)
220 // Each ABI defines its relocation type. IsRela is true if target
221 // uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
222 // few 32-bit ABIs are using RELA too.
225 // True if we are creating position-independent code.
228 // 4 for ELF32, 8 for ELF64.
232 // The only instance of Configuration struct.
233 extern Configuration *Config;