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 "lld/Common/ErrorHandler.h"
14 #include "llvm/ADT/MapVector.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/ADT/StringSet.h"
17 #include "llvm/BinaryFormat/ELF.h"
18 #include "llvm/Support/CachePruning.h"
19 #include "llvm/Support/CodeGen.h"
20 #include "llvm/Support/Endian.h"
27 class InputSectionBase;
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 --icf={none,safe,all}.
44 enum class ICFLevel { None, Safe, All };
46 // For --strip-{all,debug}.
47 enum class StripPolicy { None, All, Debug };
49 // For --unresolved-symbols.
50 enum class UnresolvedPolicy { ReportError, Warn, Ignore, IgnoreAll };
52 // For --orphan-handling.
53 enum class OrphanHandlingPolicy { Place, Warn, Error };
55 // For --sort-section and linkerscript sorting rules.
56 enum class SortSectionPolicy { Default, None, Alignment, Name, Priority };
59 enum class Target2Policy { Abs, Rel, GotRel };
61 // For tracking ARM Float Argument PCS
62 enum class ARMVFPArgKind { Default, Base, VFP, ToolChain };
64 struct SymbolVersion {
70 // This struct contains symbols version definition that
71 // can be found in version script if it is used for link.
72 struct VersionDefinition {
75 std::vector<SymbolVersion> Globals;
76 size_t NameOff = 0; // Offset in the string table
79 // This struct contains the global configuration for the linker.
80 // Most fields are direct mapping from the command line options
81 // and such fields have the same name as the corresponding options.
82 // Most fields are initialized by the driver.
83 struct Configuration {
85 llvm::CachePruningPolicy ThinLTOCachePolicy;
86 llvm::StringMap<uint64_t> SectionStartMap;
87 llvm::StringRef Chroot;
88 llvm::StringRef DynamicLinker;
89 llvm::StringRef DwoDir;
90 llvm::StringRef Entry;
91 llvm::StringRef Emulation;
94 llvm::StringRef LTOAAPipeline;
95 llvm::StringRef LTONewPmPasses;
96 llvm::StringRef LTOObjPath;
97 llvm::StringRef LTOSampleProfile;
98 llvm::StringRef MapFile;
99 llvm::StringRef OutputFile;
100 llvm::StringRef OptRemarksFilename;
101 llvm::StringRef ProgName;
102 llvm::StringRef SoName;
103 llvm::StringRef Sysroot;
104 llvm::StringRef ThinLTOCacheDir;
105 llvm::StringRef ThinLTOIndexOnlyArg;
106 std::pair<llvm::StringRef, llvm::StringRef> ThinLTOObjectSuffixReplace;
107 std::pair<llvm::StringRef, llvm::StringRef> ThinLTOPrefixReplace;
109 std::vector<VersionDefinition> VersionDefinitions;
110 std::vector<llvm::StringRef> AuxiliaryList;
111 std::vector<llvm::StringRef> FilterList;
112 std::vector<llvm::StringRef> SearchPaths;
113 std::vector<llvm::StringRef> SymbolOrderingFile;
114 std::vector<llvm::StringRef> Undefined;
115 std::vector<SymbolVersion> DynamicList;
116 std::vector<SymbolVersion> VersionScriptGlobals;
117 std::vector<SymbolVersion> VersionScriptLocals;
118 std::vector<uint8_t> BuildIdVector;
119 llvm::MapVector<std::pair<const InputSectionBase *, const InputSectionBase *>,
122 bool AllowMultipleDefinition;
123 bool AndroidPackDynRelocs;
124 bool ARMHasBlx = false;
125 bool ARMHasMovtMovw = false;
126 bool ARMJ1J2BranchEncoding = false;
127 bool AsNeeded = false;
129 bool BsymbolicFunctions;
131 bool CompressDebugSections;
134 bool Demangle = true;
141 bool FixCortexA53Errata843419;
144 bool GnuHash = false;
146 bool HasDynamicList = false;
148 bool IgnoreDataAddressEquality;
149 bool IgnoreFunctionAddressEquality;
150 bool LTODebugPassManager;
151 bool LTONewPassManager;
153 bool MipsN32Abi = false;
158 bool OptRemarksWithHotness;
160 bool PrintGcSections;
161 bool PrintIcfSections;
163 bool RelrPackDynRelocs;
168 bool SysvHash = false;
171 bool ThinLTOEmitImportsFiles;
172 bool ThinLTOIndexOnly;
173 bool UndefinedVersion;
174 bool UseAndroidRelrTags = false;
177 bool WarnMissingEntry;
178 bool WarnSymbolOrdering;
187 bool ZKeepTextSectionPrefix;
197 DiscardPolicy Discard;
199 OrphanHandlingPolicy OrphanHandling;
200 SortSectionPolicy SortSection;
202 UnresolvedPolicy UnresolvedSymbols;
203 Target2Policy Target2;
204 ARMVFPArgKind ARMVFPArgs = ARMVFPArgKind::Default;
205 BuildIdKind BuildId = BuildIdKind::None;
206 ELFKind EKind = ELFNoneKind;
207 uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
208 uint16_t EMachine = llvm::ELF::EM_NONE;
209 llvm::Optional<uint64_t> ImageBase;
210 uint64_t MaxPageSize;
211 uint64_t MipsGotSize;
213 unsigned LTOPartitions;
216 unsigned ThinLTOJobs;
218 // The following config options do not directly correspond to any
219 // particualr command line options.
221 // True if we need to pass through relocations in input files to the
222 // output file. Usually false because we consume relocations.
225 // True if the target is ELF64. False if ELF32.
228 // True if the target is little-endian. False if big-endian.
231 // endianness::little if IsLE is true. endianness::big otherwise.
232 llvm::support::endianness Endianness;
234 // True if the target is the little-endian MIPS64.
236 // The reason why we have this variable only for the MIPS is because
237 // we use this often. Some ELF headers for MIPS64EL are in a
238 // mixed-endian (which is horrible and I'd say that's a serious spec
239 // bug), and we need to know whether we are reading MIPS ELF files or
240 // not in various places.
242 // (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
243 // name whatever that means. A fun hypothesis is that "EL" is short for
244 // little-endian written in the little-endian order, but I don't know
248 // Holds set of ELF header flags for the target.
251 // The ELF spec defines two types of relocation table entries, RELA and
252 // REL. RELA is a triplet of (offset, info, addend) while REL is a
253 // tuple of (offset, info). Addends for REL are implicit and read from
254 // the location where the relocations are applied. So, REL is more
255 // compact than RELA but requires a bit of more work to process.
257 // (From the linker writer's view, this distinction is not necessary.
258 // If the ELF had chosen whichever and sticked with it, it would have
259 // been easier to write code to process relocations, but it's too late
260 // to change the spec.)
262 // Each ABI defines its relocation type. IsRela is true if target
263 // uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
264 // few 32-bit ABIs are using RELA too.
267 // True if we are creating position-independent code.
270 // 4 for ELF32, 8 for ELF64.
274 // The only instance of Configuration struct.
275 extern Configuration *Config;
277 static inline void errorOrWarn(const Twine &Msg) {
278 if (!Config->NoinhibitExec)