]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - ELF/Config.h
Vendor import of lld trunk r338150:
[FreeBSD/FreeBSD.git] / 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 <vector>
22
23 namespace lld {
24 namespace elf {
25
26 class InputFile;
27 class InputSectionBase;
28
29 enum ELFKind {
30   ELFNoneKind,
31   ELF32LEKind,
32   ELF32BEKind,
33   ELF64LEKind,
34   ELF64BEKind
35 };
36
37 // For --build-id.
38 enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid };
39
40 // For --discard-{all,locals,none}.
41 enum class DiscardPolicy { Default, All, Locals, None };
42
43 // For --icf={none,safe,all}.
44 enum class ICFLevel { None, Safe, All };
45
46 // For --strip-{all,debug}.
47 enum class StripPolicy { None, All, Debug };
48
49 // For --unresolved-symbols.
50 enum class UnresolvedPolicy { ReportError, Warn, Ignore, IgnoreAll };
51
52 // For --orphan-handling.
53 enum class OrphanHandlingPolicy { Place, Warn, Error };
54
55 // For --sort-section and linkerscript sorting rules.
56 enum class SortSectionPolicy { Default, None, Alignment, Name, Priority };
57
58 // For --target2
59 enum class Target2Policy { Abs, Rel, GotRel };
60
61 struct SymbolVersion {
62   llvm::StringRef Name;
63   bool IsExternCpp;
64   bool HasWildcard;
65 };
66
67 // This struct contains symbols version definition that
68 // can be found in version script if it is used for link.
69 struct VersionDefinition {
70   llvm::StringRef Name;
71   uint16_t Id = 0;
72   std::vector<SymbolVersion> Globals;
73   size_t NameOff = 0; // Offset in the string table
74 };
75
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 {
81   uint8_t OSABI = 0;
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;
89   llvm::StringRef Fini;
90   llvm::StringRef Init;
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;
105   std::string Rpath;
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 *>,
117                   uint64_t>
118       CallGraphProfile;
119   bool AllowMultipleDefinition;
120   bool AndroidPackDynRelocs;
121   bool ARMHasBlx = false;
122   bool ARMHasMovtMovw = false;
123   bool ARMJ1J2BranchEncoding = false;
124   bool AsNeeded = false;
125   bool Bsymbolic;
126   bool BsymbolicFunctions;
127   bool CheckSections;
128   bool CompressDebugSections;
129   bool Cref;
130   bool DefineCommon;
131   bool Demangle = true;
132   bool DisableVerify;
133   bool EhFrameHdr;
134   bool EmitRelocs;
135   bool EnableNewDtags;
136   bool ExportDynamic;
137   bool FixCortexA53Errata843419;
138   bool GcSections;
139   bool GdbIndex;
140   bool GnuHash = false;
141   bool GnuUnique;
142   bool HasDynamicList = false;
143   bool HasDynSymTab;
144   bool IgnoreDataAddressEquality;
145   bool IgnoreFunctionAddressEquality;
146   bool LTODebugPassManager;
147   bool LTONewPassManager;
148   bool MergeArmExidx;
149   bool MipsN32Abi = false;
150   bool NoinhibitExec;
151   bool Nostdlib;
152   bool OFormatBinary;
153   bool Omagic;
154   bool OptRemarksWithHotness;
155   bool Pie;
156   bool PrintGcSections;
157   bool PrintIcfSections;
158   bool Relocatable;
159   bool RelrPackDynRelocs;
160   bool SaveTemps;
161   bool SingleRoRx;
162   bool Shared;
163   bool Static = false;
164   bool SysvHash = false;
165   bool Target1Rel;
166   bool Trace;
167   bool ThinLTOEmitImportsFiles;
168   bool ThinLTOIndexOnly;
169   bool UndefinedVersion;
170   bool UseAndroidRelrTags = false;
171   bool WarnBackrefs;
172   bool WarnCommon;
173   bool WarnMissingEntry;
174   bool WarnSymbolOrdering;
175   bool WriteAddends;
176   bool ZCombreloc;
177   bool ZCopyreloc;
178   bool ZExecstack;
179   bool ZHazardplt;
180   bool ZInitfirst;
181   bool ZKeepTextSectionPrefix;
182   bool ZNodelete;
183   bool ZNodlopen;
184   bool ZNow;
185   bool ZOrigin;
186   bool ZRelro;
187   bool ZRodynamic;
188   bool ZText;
189   bool ZRetpolineplt;
190   bool ZWxneeded;
191   DiscardPolicy Discard;
192   ICFLevel ICF;
193   OrphanHandlingPolicy OrphanHandling;
194   SortSectionPolicy SortSection;
195   StripPolicy Strip;
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;
205   uint64_t ZStackSize;
206   unsigned LTOPartitions;
207   unsigned LTOO;
208   unsigned Optimize;
209   unsigned ThinLTOJobs;
210
211   // The following config options do not directly correspond to any
212   // particualr command line options.
213
214   // True if we need to pass through relocations in input files to the
215   // output file. Usually false because we consume relocations.
216   bool CopyRelocs;
217
218   // True if the target is ELF64. False if ELF32.
219   bool Is64;
220
221   // True if the target is little-endian. False if big-endian.
222   bool IsLE;
223
224   // endianness::little if IsLE is true. endianness::big otherwise.
225   llvm::support::endianness Endianness;
226
227   // True if the target is the little-endian MIPS64.
228   //
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.
234   //
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
238   // if that's true.)
239   bool IsMips64EL;
240
241   // Holds set of ELF header flags for the target.
242   uint32_t EFlags = 0;
243
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.
249   //
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.)
254   //
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.
258   bool IsRela;
259
260   // True if we are creating position-independent code.
261   bool Pic;
262
263   // 4 for ELF32, 8 for ELF64.
264   int Wordsize;
265 };
266
267 // The only instance of Configuration struct.
268 extern Configuration *Config;
269
270 static inline void errorOrWarn(const Twine &Msg) {
271   if (!Config->NoinhibitExec)
272     error(Msg);
273   else
274     warn(Msg);
275 }
276 } // namespace elf
277 } // namespace lld
278
279 #endif