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"
28 class InputSectionBase;
39 enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid };
41 // For --discard-{all,locals,none}.
42 enum class DiscardPolicy { Default, All, Locals, None };
44 // For --icf={none,safe,all}.
45 enum class ICFLevel { None, Safe, All };
47 // For --strip-{all,debug}.
48 enum class StripPolicy { None, All, Debug };
50 // For --unresolved-symbols.
51 enum class UnresolvedPolicy { ReportError, Warn, Ignore };
53 // For --orphan-handling.
54 enum class OrphanHandlingPolicy { Place, Warn, Error };
56 // For --sort-section and linkerscript sorting rules.
57 enum class SortSectionPolicy { Default, None, Alignment, Name, Priority };
60 enum class Target2Policy { Abs, Rel, GotRel };
62 // For tracking ARM Float Argument PCS
63 enum class ARMVFPArgKind { Default, Base, VFP, ToolChain };
65 struct SymbolVersion {
71 // This struct contains symbols version definition that
72 // can be found in version script if it is used for link.
73 struct VersionDefinition {
76 std::vector<SymbolVersion> Globals;
77 size_t NameOff = 0; // Offset in the string table
80 // This struct contains the global configuration for the linker.
81 // Most fields are direct mapping from the command line options
82 // and such fields have the same name as the corresponding options.
83 // Most fields are initialized by the driver.
84 struct Configuration {
85 std::atomic<bool> HasStaticTlsModel{false};
87 llvm::CachePruningPolicy ThinLTOCachePolicy;
88 llvm::StringMap<uint64_t> SectionStartMap;
89 llvm::StringRef Chroot;
90 llvm::StringRef DynamicLinker;
91 llvm::StringRef DwoDir;
92 llvm::StringRef Entry;
93 llvm::StringRef Emulation;
96 llvm::StringRef LTOAAPipeline;
97 llvm::StringRef LTONewPmPasses;
98 llvm::StringRef LTOObjPath;
99 llvm::StringRef LTOSampleProfile;
100 llvm::StringRef MapFile;
101 llvm::StringRef OutputFile;
102 llvm::StringRef OptRemarksFilename;
103 llvm::StringRef ProgName;
104 llvm::StringRef SoName;
105 llvm::StringRef Sysroot;
106 llvm::StringRef ThinLTOCacheDir;
107 llvm::StringRef ThinLTOIndexOnlyArg;
108 std::pair<llvm::StringRef, llvm::StringRef> ThinLTOObjectSuffixReplace;
109 std::pair<llvm::StringRef, llvm::StringRef> ThinLTOPrefixReplace;
111 std::vector<VersionDefinition> VersionDefinitions;
112 std::vector<llvm::StringRef> AuxiliaryList;
113 std::vector<llvm::StringRef> FilterList;
114 std::vector<llvm::StringRef> SearchPaths;
115 std::vector<llvm::StringRef> SymbolOrderingFile;
116 std::vector<llvm::StringRef> Undefined;
117 std::vector<SymbolVersion> DynamicList;
118 std::vector<SymbolVersion> VersionScriptGlobals;
119 std::vector<SymbolVersion> VersionScriptLocals;
120 std::vector<uint8_t> BuildIdVector;
121 llvm::MapVector<std::pair<const InputSectionBase *, const InputSectionBase *>,
124 bool AllowMultipleDefinition;
125 bool AllowShlibUndefined;
126 bool AndroidPackDynRelocs;
127 bool ARMHasBlx = false;
128 bool ARMHasMovtMovw = false;
129 bool ARMJ1J2BranchEncoding = false;
130 bool AsNeeded = false;
132 bool BsymbolicFunctions;
133 bool CallGraphProfileSort;
135 bool CompressDebugSections;
138 bool Demangle = true;
146 bool FixCortexA53Errata843419;
147 bool FormatBinary = false;
150 bool GnuHash = false;
152 bool HasDynamicList = false;
154 bool IgnoreDataAddressEquality;
155 bool IgnoreFunctionAddressEquality;
156 bool LTODebugPassManager;
157 bool LTONewPassManager;
159 bool MipsN32Abi = false;
164 bool OptRemarksWithHotness;
167 bool PrintGcSections;
168 bool PrintIcfSections;
170 bool RelrPackDynRelocs;
175 bool SysvHash = false;
178 bool ThinLTOEmitImportsFiles;
179 bool ThinLTOIndexOnly;
181 bool UndefinedVersion;
182 bool UseAndroidRelrTags = false;
185 bool WarnIfuncTextrel;
186 bool WarnMissingEntry;
187 bool WarnSymbolOrdering;
197 bool ZKeepTextSectionPrefix;
208 DiscardPolicy Discard;
210 OrphanHandlingPolicy OrphanHandling;
211 SortSectionPolicy SortSection;
213 UnresolvedPolicy UnresolvedSymbols;
214 Target2Policy Target2;
215 ARMVFPArgKind ARMVFPArgs = ARMVFPArgKind::Default;
216 BuildIdKind BuildId = BuildIdKind::None;
217 ELFKind EKind = ELFNoneKind;
218 uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
219 uint16_t EMachine = llvm::ELF::EM_NONE;
220 llvm::Optional<uint64_t> ImageBase;
221 uint64_t MaxPageSize;
222 uint64_t MipsGotSize;
224 unsigned LTOPartitions;
227 unsigned ThinLTOJobs;
228 int32_t SplitStackAdjustSize;
230 // The following config options do not directly correspond to any
231 // particualr command line options.
233 // True if we need to pass through relocations in input files to the
234 // output file. Usually false because we consume relocations.
237 // True if the target is ELF64. False if ELF32.
240 // True if the target is little-endian. False if big-endian.
243 // endianness::little if IsLE is true. endianness::big otherwise.
244 llvm::support::endianness Endianness;
246 // True if the target is the little-endian MIPS64.
248 // The reason why we have this variable only for the MIPS is because
249 // we use this often. Some ELF headers for MIPS64EL are in a
250 // mixed-endian (which is horrible and I'd say that's a serious spec
251 // bug), and we need to know whether we are reading MIPS ELF files or
252 // not in various places.
254 // (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
255 // name whatever that means. A fun hypothesis is that "EL" is short for
256 // little-endian written in the little-endian order, but I don't know
260 // Holds set of ELF header flags for the target.
263 // The ELF spec defines two types of relocation table entries, RELA and
264 // REL. RELA is a triplet of (offset, info, addend) while REL is a
265 // tuple of (offset, info). Addends for REL are implicit and read from
266 // the location where the relocations are applied. So, REL is more
267 // compact than RELA but requires a bit of more work to process.
269 // (From the linker writer's view, this distinction is not necessary.
270 // If the ELF had chosen whichever and sticked with it, it would have
271 // been easier to write code to process relocations, but it's too late
272 // to change the spec.)
274 // Each ABI defines its relocation type. IsRela is true if target
275 // uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
276 // few 32-bit ABIs are using RELA too.
279 // True if we are creating position-independent code.
282 // 4 for ELF32, 8 for ELF64.
286 // The only instance of Configuration struct.
287 extern Configuration *Config;
289 static inline void errorOrWarn(const Twine &Msg) {
290 if (!Config->NoinhibitExec)