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 // For tracking ARM Float Argument PCS
58 enum class ARMVFPArgKind { Default, Base, VFP, ToolChain };
60 struct SymbolVersion {
66 // This struct contains symbols version definition that
67 // can be found in version script if it is used for link.
68 struct VersionDefinition {
71 std::vector<SymbolVersion> Globals;
72 size_t NameOff = 0; // Offset in the string table
75 // This struct contains the global configuration for the linker.
76 // Most fields are direct mapping from the command line options
77 // and such fields have the same name as the corresponding options.
78 // Most fields are initialized by the driver.
79 struct Configuration {
81 llvm::CachePruningPolicy ThinLTOCachePolicy;
82 llvm::StringMap<uint64_t> SectionStartMap;
83 llvm::StringRef Chroot;
84 llvm::StringRef DynamicLinker;
85 llvm::StringRef Entry;
86 llvm::StringRef Emulation;
89 llvm::StringRef LTOAAPipeline;
90 llvm::StringRef LTONewPmPasses;
91 llvm::StringRef MapFile;
92 llvm::StringRef OutputFile;
93 llvm::StringRef OptRemarksFilename;
94 llvm::StringRef SoName;
95 llvm::StringRef Sysroot;
96 llvm::StringRef ThinLTOCacheDir;
98 std::vector<VersionDefinition> VersionDefinitions;
99 std::vector<llvm::StringRef> Argv;
100 std::vector<llvm::StringRef> AuxiliaryList;
101 std::vector<llvm::StringRef> FilterList;
102 std::vector<llvm::StringRef> SearchPaths;
103 std::vector<llvm::StringRef> SymbolOrderingFile;
104 std::vector<llvm::StringRef> Undefined;
105 std::vector<SymbolVersion> DynamicList;
106 std::vector<SymbolVersion> VersionScriptGlobals;
107 std::vector<SymbolVersion> VersionScriptLocals;
108 std::vector<uint8_t> BuildIdVector;
109 bool AllowMultipleDefinition;
110 bool AndroidPackDynRelocs = false;
111 bool ARMHasBlx = false;
112 bool ARMHasMovtMovw = false;
113 bool ARMJ1J2BranchEncoding = false;
114 bool AsNeeded = false;
116 bool BsymbolicFunctions;
117 bool CompressDebugSections;
119 bool Demangle = true;
125 bool FixCortexA53Errata843419;
128 bool GnuHash = false;
129 bool HasDynamicList = false;
134 bool MipsN32Abi = false;
136 bool NoUndefinedVersion;
141 bool OptRemarksWithHotness;
143 bool PrintGcSections;
149 bool SysvHash = false;
154 bool WarnMissingEntry;
169 DiscardPolicy Discard;
170 OrphanHandlingPolicy OrphanHandling;
171 SortSectionPolicy SortSection;
173 UnresolvedPolicy UnresolvedSymbols;
174 Target2Policy Target2;
175 ARMVFPArgKind ARMVFPArgs = ARMVFPArgKind::Default;
176 BuildIdKind BuildId = BuildIdKind::None;
177 ELFKind EKind = ELFNoneKind;
178 uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
179 uint16_t EMachine = llvm::ELF::EM_NONE;
180 llvm::Optional<uint64_t> ImageBase;
181 uint64_t MaxPageSize;
183 unsigned LTOPartitions;
186 unsigned ThinLTOJobs;
188 // The following config options do not directly correspond to any
189 // particualr command line options.
191 // True if we need to pass through relocations in input files to the
192 // output file. Usually false because we consume relocations.
195 // True if the target is ELF64. False if ELF32.
198 // True if the target is little-endian. False if big-endian.
201 // endianness::little if IsLE is true. endianness::big otherwise.
202 llvm::support::endianness Endianness;
204 // True if the target is the little-endian MIPS64.
206 // The reason why we have this variable only for the MIPS is because
207 // we use this often. Some ELF headers for MIPS64EL are in a
208 // mixed-endian (which is horrible and I'd say that's a serious spec
209 // bug), and we need to know whether we are reading MIPS ELF files or
210 // not in various places.
212 // (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
213 // name whatever that means. A fun hypothesis is that "EL" is short for
214 // little-endian written in the little-endian order, but I don't know
218 // Holds set of ELF header flags for the target.
221 // The ELF spec defines two types of relocation table entries, RELA and
222 // REL. RELA is a triplet of (offset, info, addend) while REL is a
223 // tuple of (offset, info). Addends for REL are implicit and read from
224 // the location where the relocations are applied. So, REL is more
225 // compact than RELA but requires a bit of more work to process.
227 // (From the linker writer's view, this distinction is not necessary.
228 // If the ELF had chosen whichever and sticked with it, it would have
229 // been easier to write code to process relocations, but it's too late
230 // to change the spec.)
232 // Each ABI defines its relocation type. IsRela is true if target
233 // uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
234 // few 32-bit ABIs are using RELA too.
237 // True if we are creating position-independent code.
240 // 4 for ELF32, 8 for ELF64.
244 // The only instance of Configuration struct.
245 extern Configuration *Config;