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"
37 enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid };
39 // For --discard-{all,locals,none}.
40 enum class DiscardPolicy { Default, All, Locals, None };
42 // For --strip-{all,debug}.
43 enum class StripPolicy { None, All, Debug };
45 // For --unresolved-symbols.
46 enum class UnresolvedPolicy { ReportError, Warn, Ignore, IgnoreAll };
48 // For --orphan-handling.
49 enum class OrphanHandlingPolicy { Place, Warn, Error };
51 // For --sort-section and linkerscript sorting rules.
52 enum class SortSectionPolicy { Default, None, Alignment, Name, Priority };
55 enum class Target2Policy { Abs, Rel, GotRel };
57 struct SymbolVersion {
63 // This struct contains symbols version definition that
64 // can be found in version script if it is used for link.
65 struct VersionDefinition {
68 std::vector<SymbolVersion> Globals;
69 size_t NameOff = 0; // Offset in the string table
72 // This struct contains the global configuration for the linker.
73 // Most fields are direct mapping from the command line options
74 // and such fields have the same name as the corresponding options.
75 // Most fields are initialized by the driver.
76 struct Configuration {
78 llvm::CachePruningPolicy ThinLTOCachePolicy;
79 llvm::StringMap<uint64_t> SectionStartMap;
80 llvm::StringRef Chroot;
81 llvm::StringRef DynamicLinker;
82 llvm::StringRef Entry;
83 llvm::StringRef Emulation;
86 llvm::StringRef LTOAAPipeline;
87 llvm::StringRef LTONewPmPasses;
88 llvm::StringRef MapFile;
89 llvm::StringRef OutputFile;
90 llvm::StringRef OptRemarksFilename;
91 llvm::StringRef SoName;
92 llvm::StringRef Sysroot;
93 llvm::StringRef ThinLTOCacheDir;
95 std::vector<VersionDefinition> VersionDefinitions;
96 std::vector<llvm::StringRef> Argv;
97 std::vector<llvm::StringRef> AuxiliaryList;
98 std::vector<llvm::StringRef> FilterList;
99 std::vector<llvm::StringRef> SearchPaths;
100 std::vector<llvm::StringRef> SymbolOrderingFile;
101 std::vector<llvm::StringRef> Undefined;
102 std::vector<SymbolVersion> DynamicList;
103 std::vector<SymbolVersion> VersionScriptGlobals;
104 std::vector<SymbolVersion> VersionScriptLocals;
105 std::vector<uint8_t> BuildIdVector;
106 bool AllowMultipleDefinition;
107 bool AndroidPackDynRelocs = false;
108 bool ARMHasBlx = false;
109 bool ARMHasMovtMovw = false;
110 bool ARMJ1J2BranchEncoding = false;
111 bool AsNeeded = false;
113 bool BsymbolicFunctions;
114 bool CompressDebugSections;
116 bool Demangle = true;
122 bool FixCortexA53Errata843419;
125 bool GnuHash = false;
126 bool HasDynamicList = false;
131 bool MipsN32Abi = false;
133 bool NoUndefinedVersion;
138 bool OptRemarksWithHotness;
140 bool PrintGcSections;
146 bool SysvHash = false;
151 bool WarnMissingEntry;
165 DiscardPolicy Discard;
166 OrphanHandlingPolicy OrphanHandling;
167 SortSectionPolicy SortSection;
169 UnresolvedPolicy UnresolvedSymbols;
170 Target2Policy Target2;
171 BuildIdKind BuildId = BuildIdKind::None;
172 ELFKind EKind = ELFNoneKind;
173 uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
174 uint16_t EMachine = llvm::ELF::EM_NONE;
175 llvm::Optional<uint64_t> ImageBase;
176 uint64_t MaxPageSize;
178 unsigned LTOPartitions;
181 unsigned ThinLTOJobs;
183 // The following config options do not directly correspond to any
184 // particualr command line options.
186 // True if we need to pass through relocations in input files to the
187 // output file. Usually false because we consume relocations.
190 // True if the target is ELF64. False if ELF32.
193 // True if the target is little-endian. False if big-endian.
196 // endianness::little if IsLE is true. endianness::big otherwise.
197 llvm::support::endianness Endianness;
199 // True if the target is the little-endian MIPS64.
201 // The reason why we have this variable only for the MIPS is because
202 // we use this often. Some ELF headers for MIPS64EL are in a
203 // mixed-endian (which is horrible and I'd say that's a serious spec
204 // bug), and we need to know whether we are reading MIPS ELF files or
205 // not in various places.
207 // (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
208 // name whatever that means. A fun hypothesis is that "EL" is short for
209 // little-endian written in the little-endian order, but I don't know
213 // Holds set of ELF header flags for the target.
216 // The ELF spec defines two types of relocation table entries, RELA and
217 // REL. RELA is a triplet of (offset, info, addend) while REL is a
218 // tuple of (offset, info). Addends for REL are implicit and read from
219 // the location where the relocations are applied. So, REL is more
220 // compact than RELA but requires a bit of more work to process.
222 // (From the linker writer's view, this distinction is not necessary.
223 // If the ELF had chosen whichever and sticked with it, it would have
224 // been easier to write code to process relocations, but it's too late
225 // to change the spec.)
227 // Each ABI defines its relocation type. IsRela is true if target
228 // uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
229 // few 32-bit ABIs are using RELA too.
232 // True if we are creating position-independent code.
235 // 4 for ELF32, 8 for ELF64.
239 // The only instance of Configuration struct.
240 extern Configuration *Config;