]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/Config.h
MFC r344444:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / ELF / Config.h
1 //===- Config.h -------------------------------------------------*- C++ -*-===//
2 //
3 //                             The LLVM Linker
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLD_ELF_CONFIG_H
11 #define LLD_ELF_CONFIG_H
12
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"
21 #include <atomic>
22 #include <vector>
23
24 namespace lld {
25 namespace elf {
26
27 class InputFile;
28 class InputSectionBase;
29
30 enum ELFKind {
31   ELFNoneKind,
32   ELF32LEKind,
33   ELF32BEKind,
34   ELF64LEKind,
35   ELF64BEKind
36 };
37
38 // For --build-id.
39 enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid };
40
41 // For --discard-{all,locals,none}.
42 enum class DiscardPolicy { Default, All, Locals, None };
43
44 // For --icf={none,safe,all}.
45 enum class ICFLevel { None, Safe, All };
46
47 // For --strip-{all,debug}.
48 enum class StripPolicy { None, All, Debug };
49
50 // For --unresolved-symbols.
51 enum class UnresolvedPolicy { ReportError, Warn, Ignore, IgnoreAll };
52
53 // For --orphan-handling.
54 enum class OrphanHandlingPolicy { Place, Warn, Error };
55
56 // For --sort-section and linkerscript sorting rules.
57 enum class SortSectionPolicy { Default, None, Alignment, Name, Priority };
58
59 // For --target2
60 enum class Target2Policy { Abs, Rel, GotRel };
61
62 // For tracking ARM Float Argument PCS
63 enum class ARMVFPArgKind { Default, Base, VFP, ToolChain };
64
65 struct SymbolVersion {
66   llvm::StringRef Name;
67   bool IsExternCpp;
68   bool HasWildcard;
69 };
70
71 // This struct contains symbols version definition that
72 // can be found in version script if it is used for link.
73 struct VersionDefinition {
74   llvm::StringRef Name;
75   uint16_t Id = 0;
76   std::vector<SymbolVersion> Globals;
77   size_t NameOff = 0; // Offset in the string table
78 };
79
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};
86   uint8_t OSABI = 0;
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;
94   llvm::StringRef Fini;
95   llvm::StringRef Init;
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;
110   std::string Rpath;
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 *>,
122                   uint64_t>
123       CallGraphProfile;
124   bool AllowMultipleDefinition;
125   bool AndroidPackDynRelocs;
126   bool ARMHasBlx = false;
127   bool ARMHasMovtMovw = false;
128   bool ARMJ1J2BranchEncoding = false;
129   bool AsNeeded = false;
130   bool Bsymbolic;
131   bool BsymbolicFunctions;
132   bool CheckSections;
133   bool CompressDebugSections;
134   bool Cref;
135   bool DefineCommon;
136   bool Demangle = true;
137   bool DisableVerify;
138   bool EhFrameHdr;
139   bool EmitRelocs;
140   bool EnableNewDtags;
141   bool ExecuteOnly;
142   bool ExportDynamic;
143   bool FixCortexA53Errata843419;
144   bool GcSections;
145   bool GdbIndex;
146   bool GnuHash = false;
147   bool GnuUnique;
148   bool HasDynamicList = false;
149   bool HasDynSymTab;
150   bool IgnoreDataAddressEquality;
151   bool IgnoreFunctionAddressEquality;
152   bool LTODebugPassManager;
153   bool LTONewPassManager;
154   bool MergeArmExidx;
155   bool MipsN32Abi = false;
156   bool NoinhibitExec;
157   bool Nostdlib;
158   bool OFormatBinary;
159   bool Omagic;
160   bool OptRemarksWithHotness;
161   bool Pie;
162   bool PrintGcSections;
163   bool PrintIcfSections;
164   bool Relocatable;
165   bool RelrPackDynRelocs;
166   bool SaveTemps;
167   bool SingleRoRx;
168   bool Shared;
169   bool Static = false;
170   bool SysvHash = false;
171   bool Target1Rel;
172   bool Trace;
173   bool ThinLTOEmitImportsFiles;
174   bool ThinLTOIndexOnly;
175   bool UndefinedVersion;
176   bool UseAndroidRelrTags = false;
177   bool WarnBackrefs;
178   bool WarnCommon;
179   bool WarnMissingEntry;
180   bool WarnSymbolOrdering;
181   bool WriteAddends;
182   bool ZCombreloc;
183   bool ZCopyreloc;
184   bool ZExecstack;
185   bool ZHazardplt;
186   bool ZIfuncnoplt;
187   bool ZInitfirst;
188   bool ZInterpose;
189   bool ZKeepTextSectionPrefix;
190   bool ZNodelete;
191   bool ZNodlopen;
192   bool ZNow;
193   bool ZOrigin;
194   bool ZRelro;
195   bool ZRodynamic;
196   bool ZText;
197   bool ZRetpolineplt;
198   bool ZWxneeded;
199   DiscardPolicy Discard;
200   ICFLevel ICF;
201   OrphanHandlingPolicy OrphanHandling;
202   SortSectionPolicy SortSection;
203   StripPolicy Strip;
204   UnresolvedPolicy UnresolvedSymbols;
205   Target2Policy Target2;
206   ARMVFPArgKind ARMVFPArgs = ARMVFPArgKind::Default;
207   BuildIdKind BuildId = BuildIdKind::None;
208   ELFKind EKind = ELFNoneKind;
209   uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
210   uint16_t EMachine = llvm::ELF::EM_NONE;
211   llvm::Optional<uint64_t> ImageBase;
212   uint64_t MaxPageSize;
213   uint64_t MipsGotSize;
214   uint64_t ZStackSize;
215   unsigned LTOPartitions;
216   unsigned LTOO;
217   unsigned Optimize;
218   unsigned ThinLTOJobs;
219
220   // The following config options do not directly correspond to any
221   // particualr command line options.
222
223   // True if we need to pass through relocations in input files to the
224   // output file. Usually false because we consume relocations.
225   bool CopyRelocs;
226
227   // True if the target is ELF64. False if ELF32.
228   bool Is64;
229
230   // True if the target is little-endian. False if big-endian.
231   bool IsLE;
232
233   // endianness::little if IsLE is true. endianness::big otherwise.
234   llvm::support::endianness Endianness;
235
236   // True if the target is the little-endian MIPS64.
237   //
238   // The reason why we have this variable only for the MIPS is because
239   // we use this often.  Some ELF headers for MIPS64EL are in a
240   // mixed-endian (which is horrible and I'd say that's a serious spec
241   // bug), and we need to know whether we are reading MIPS ELF files or
242   // not in various places.
243   //
244   // (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
245   // name whatever that means. A fun hypothesis is that "EL" is short for
246   // little-endian written in the little-endian order, but I don't know
247   // if that's true.)
248   bool IsMips64EL;
249
250   // Holds set of ELF header flags for the target.
251   uint32_t EFlags = 0;
252
253   // The ELF spec defines two types of relocation table entries, RELA and
254   // REL. RELA is a triplet of (offset, info, addend) while REL is a
255   // tuple of (offset, info). Addends for REL are implicit and read from
256   // the location where the relocations are applied. So, REL is more
257   // compact than RELA but requires a bit of more work to process.
258   //
259   // (From the linker writer's view, this distinction is not necessary.
260   // If the ELF had chosen whichever and sticked with it, it would have
261   // been easier to write code to process relocations, but it's too late
262   // to change the spec.)
263   //
264   // Each ABI defines its relocation type. IsRela is true if target
265   // uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
266   // few 32-bit ABIs are using RELA too.
267   bool IsRela;
268
269   // True if we are creating position-independent code.
270   bool Pic;
271
272   // 4 for ELF32, 8 for ELF64.
273   int Wordsize;
274 };
275
276 // The only instance of Configuration struct.
277 extern Configuration *Config;
278
279 static inline void errorOrWarn(const Twine &Msg) {
280   if (!Config->NoinhibitExec)
281     error(Msg);
282   else
283     warn(Msg);
284 }
285 } // namespace elf
286 } // namespace lld
287
288 #endif