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 struct SymbolVersion {
67 // This struct contains symbols version definition that
68 // can be found in version script if it is used for link.
69 struct VersionDefinition {
72 std::vector<SymbolVersion> Globals;
73 size_t NameOff = 0; // Offset in the string table
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 {
82 llvm::CachePruningPolicy ThinLTOCachePolicy;
83 llvm::StringMap<uint64_t> SectionStartMap;
84 llvm::StringRef Chroot;
85 llvm::StringRef DynamicLinker;
86 llvm::StringRef DwoDir;
87 llvm::StringRef Entry;
88 llvm::StringRef Emulation;
91 llvm::StringRef LTOAAPipeline;
92 llvm::StringRef LTONewPmPasses;
93 llvm::StringRef LTOObjPath;
94 llvm::StringRef LTOSampleProfile;
95 llvm::StringRef MapFile;
96 llvm::StringRef OutputFile;
97 llvm::StringRef OptRemarksFilename;
98 llvm::StringRef ProgName;
99 llvm::StringRef SoName;
100 llvm::StringRef Sysroot;
101 llvm::StringRef ThinLTOCacheDir;
102 llvm::StringRef ThinLTOIndexOnlyArg;
103 std::pair<llvm::StringRef, llvm::StringRef> ThinLTOObjectSuffixReplace;
104 std::pair<llvm::StringRef, llvm::StringRef> ThinLTOPrefixReplace;
106 std::vector<VersionDefinition> VersionDefinitions;
107 std::vector<llvm::StringRef> AuxiliaryList;
108 std::vector<llvm::StringRef> FilterList;
109 std::vector<llvm::StringRef> SearchPaths;
110 std::vector<llvm::StringRef> SymbolOrderingFile;
111 std::vector<llvm::StringRef> Undefined;
112 std::vector<SymbolVersion> DynamicList;
113 std::vector<SymbolVersion> VersionScriptGlobals;
114 std::vector<SymbolVersion> VersionScriptLocals;
115 std::vector<uint8_t> BuildIdVector;
116 llvm::MapVector<std::pair<const InputSectionBase *, const InputSectionBase *>,
119 bool AllowMultipleDefinition;
120 bool AndroidPackDynRelocs;
121 bool ARMHasBlx = false;
122 bool ARMHasMovtMovw = false;
123 bool ARMJ1J2BranchEncoding = false;
124 bool AsNeeded = false;
126 bool BsymbolicFunctions;
128 bool CompressDebugSections;
131 bool Demangle = true;
137 bool FixCortexA53Errata843419;
140 bool GnuHash = false;
142 bool HasDynamicList = false;
144 bool IgnoreDataAddressEquality;
145 bool IgnoreFunctionAddressEquality;
146 bool LTODebugPassManager;
147 bool LTONewPassManager;
149 bool MipsN32Abi = false;
154 bool OptRemarksWithHotness;
156 bool PrintGcSections;
157 bool PrintIcfSections;
159 bool RelrPackDynRelocs;
164 bool SysvHash = false;
167 bool ThinLTOEmitImportsFiles;
168 bool ThinLTOIndexOnly;
169 bool UndefinedVersion;
170 bool UseAndroidRelrTags = false;
173 bool WarnMissingEntry;
174 bool WarnSymbolOrdering;
181 bool ZKeepTextSectionPrefix;
191 DiscardPolicy Discard;
193 OrphanHandlingPolicy OrphanHandling;
194 SortSectionPolicy SortSection;
196 UnresolvedPolicy UnresolvedSymbols;
197 Target2Policy Target2;
198 BuildIdKind BuildId = BuildIdKind::None;
199 ELFKind EKind = ELFNoneKind;
200 uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
201 uint16_t EMachine = llvm::ELF::EM_NONE;
202 llvm::Optional<uint64_t> ImageBase;
203 uint64_t MaxPageSize;
204 uint64_t MipsGotSize;
206 unsigned LTOPartitions;
209 unsigned ThinLTOJobs;
211 // The following config options do not directly correspond to any
212 // particualr command line options.
214 // True if we need to pass through relocations in input files to the
215 // output file. Usually false because we consume relocations.
218 // True if the target is ELF64. False if ELF32.
221 // True if the target is little-endian. False if big-endian.
224 // endianness::little if IsLE is true. endianness::big otherwise.
225 llvm::support::endianness Endianness;
227 // True if the target is the little-endian MIPS64.
229 // The reason why we have this variable only for the MIPS is because
230 // we use this often. Some ELF headers for MIPS64EL are in a
231 // mixed-endian (which is horrible and I'd say that's a serious spec
232 // bug), and we need to know whether we are reading MIPS ELF files or
233 // not in various places.
235 // (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
236 // name whatever that means. A fun hypothesis is that "EL" is short for
237 // little-endian written in the little-endian order, but I don't know
241 // Holds set of ELF header flags for the target.
244 // The ELF spec defines two types of relocation table entries, RELA and
245 // REL. RELA is a triplet of (offset, info, addend) while REL is a
246 // tuple of (offset, info). Addends for REL are implicit and read from
247 // the location where the relocations are applied. So, REL is more
248 // compact than RELA but requires a bit of more work to process.
250 // (From the linker writer's view, this distinction is not necessary.
251 // If the ELF had chosen whichever and sticked with it, it would have
252 // been easier to write code to process relocations, but it's too late
253 // to change the spec.)
255 // Each ABI defines its relocation type. IsRela is true if target
256 // uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
257 // few 32-bit ABIs are using RELA too.
260 // True if we are creating position-independent code.
263 // 4 for ELF32, 8 for ELF64.
267 // The only instance of Configuration struct.
268 extern Configuration *Config;
270 static inline void errorOrWarn(const Twine &Msg) {
271 if (!Config->NoinhibitExec)