]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/Config.h
Upgrade Unbound to 1.6.0. More to follow.
[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 "llvm/ADT/MapVector.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/StringSet.h"
16 #include "llvm/BinaryFormat/ELF.h"
17 #include "llvm/Support/CachePruning.h"
18 #include "llvm/Support/CodeGen.h"
19 #include "llvm/Support/Endian.h"
20
21 #include <vector>
22
23 namespace lld {
24 namespace elf {
25
26 class InputFile;
27
28 enum ELFKind {
29   ELFNoneKind,
30   ELF32LEKind,
31   ELF32BEKind,
32   ELF64LEKind,
33   ELF64BEKind
34 };
35
36 // For --build-id.
37 enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid };
38
39 // For --discard-{all,locals,none}.
40 enum class DiscardPolicy { Default, All, Locals, None };
41
42 // For --strip-{all,debug}.
43 enum class StripPolicy { None, All, Debug };
44
45 // For --unresolved-symbols.
46 enum class UnresolvedPolicy { ReportError, Warn, Ignore, IgnoreAll };
47
48 // For --orphan-handling.
49 enum class OrphanHandlingPolicy { Place, Warn, Error };
50
51 // For --sort-section and linkerscript sorting rules.
52 enum class SortSectionPolicy { Default, None, Alignment, Name, Priority };
53
54 // For --target2
55 enum class Target2Policy { Abs, Rel, GotRel };
56
57 struct SymbolVersion {
58   llvm::StringRef Name;
59   bool IsExternCpp;
60   bool HasWildcard;
61 };
62
63 // This struct contains symbols version definition that
64 // can be found in version script if it is used for link.
65 struct VersionDefinition {
66   llvm::StringRef Name;
67   uint16_t Id = 0;
68   std::vector<SymbolVersion> Globals;
69   size_t NameOff = 0; // Offset in the string table
70 };
71
72 // This struct contains the global configuration for the linker.
73 // Most fields are direct mapping from the command line options
74 // and such fields have the same name as the corresponding options.
75 // Most fields are initialized by the driver.
76 struct Configuration {
77   uint8_t OSABI = 0;
78   llvm::CachePruningPolicy ThinLTOCachePolicy;
79   llvm::StringMap<uint64_t> SectionStartMap;
80   llvm::StringRef Chroot;
81   llvm::StringRef DynamicLinker;
82   llvm::StringRef Entry;
83   llvm::StringRef Emulation;
84   llvm::StringRef Fini;
85   llvm::StringRef Init;
86   llvm::StringRef LTOAAPipeline;
87   llvm::StringRef LTONewPmPasses;
88   llvm::StringRef MapFile;
89   llvm::StringRef OutputFile;
90   llvm::StringRef OptRemarksFilename;
91   llvm::StringRef SoName;
92   llvm::StringRef Sysroot;
93   llvm::StringRef ThinLTOCacheDir;
94   std::string Rpath;
95   std::vector<VersionDefinition> VersionDefinitions;
96   std::vector<llvm::StringRef> Argv;
97   std::vector<llvm::StringRef> AuxiliaryList;
98   std::vector<llvm::StringRef> FilterList;
99   std::vector<llvm::StringRef> SearchPaths;
100   std::vector<llvm::StringRef> SymbolOrderingFile;
101   std::vector<llvm::StringRef> Undefined;
102   std::vector<SymbolVersion> DynamicList;
103   std::vector<SymbolVersion> VersionScriptGlobals;
104   std::vector<SymbolVersion> VersionScriptLocals;
105   std::vector<uint8_t> BuildIdVector;
106   bool AllowMultipleDefinition;
107   bool AndroidPackDynRelocs = false;
108   bool ARMHasBlx = false;
109   bool ARMHasMovtMovw = false;
110   bool ARMJ1J2BranchEncoding = false;
111   bool AsNeeded = false;
112   bool Bsymbolic;
113   bool BsymbolicFunctions;
114   bool CompressDebugSections;
115   bool DefineCommon;
116   bool Demangle = true;
117   bool DisableVerify;
118   bool EhFrameHdr;
119   bool EmitRelocs;
120   bool EnableNewDtags;
121   bool ExportDynamic;
122   bool FixCortexA53Errata843419;
123   bool GcSections;
124   bool GdbIndex;
125   bool GnuHash = false;
126   bool HasDynamicList = false;
127   bool HasDynSymTab;
128   bool ICF;
129   bool ICFData;
130   bool MergeArmExidx;
131   bool MipsN32Abi = false;
132   bool NoGnuUnique;
133   bool NoUndefinedVersion;
134   bool NoinhibitExec;
135   bool Nostdlib;
136   bool OFormatBinary;
137   bool Omagic;
138   bool OptRemarksWithHotness;
139   bool Pie;
140   bool PrintGcSections;
141   bool Relocatable;
142   bool SaveTemps;
143   bool SingleRoRx;
144   bool Shared;
145   bool Static = false;
146   bool SysvHash = false;
147   bool Target1Rel;
148   bool Trace;
149   bool Verbose;
150   bool WarnCommon;
151   bool WarnMissingEntry;
152   bool ZCombreloc;
153   bool ZExecstack;
154   bool ZNocopyreloc;
155   bool ZNodelete;
156   bool ZNodlopen;
157   bool ZNow;
158   bool ZOrigin;
159   bool ZRelro;
160   bool ZRodynamic;
161   bool ZText;
162   bool ZRetpolineplt;
163   bool ExitEarly;
164   bool ZWxneeded;
165   DiscardPolicy Discard;
166   OrphanHandlingPolicy OrphanHandling;
167   SortSectionPolicy SortSection;
168   StripPolicy Strip;
169   UnresolvedPolicy UnresolvedSymbols;
170   Target2Policy Target2;
171   BuildIdKind BuildId = BuildIdKind::None;
172   ELFKind EKind = ELFNoneKind;
173   uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
174   uint16_t EMachine = llvm::ELF::EM_NONE;
175   llvm::Optional<uint64_t> ImageBase;
176   uint64_t MaxPageSize;
177   uint64_t ZStackSize;
178   unsigned LTOPartitions;
179   unsigned LTOO;
180   unsigned Optimize;
181   unsigned ThinLTOJobs;
182
183   // The following config options do not directly correspond to any
184   // particualr command line options.
185
186   // True if we need to pass through relocations in input files to the
187   // output file. Usually false because we consume relocations.
188   bool CopyRelocs;
189
190   // True if the target is ELF64. False if ELF32.
191   bool Is64;
192
193   // True if the target is little-endian. False if big-endian.
194   bool IsLE;
195
196   // endianness::little if IsLE is true. endianness::big otherwise.
197   llvm::support::endianness Endianness;
198
199   // True if the target is the little-endian MIPS64.
200   //
201   // The reason why we have this variable only for the MIPS is because
202   // we use this often.  Some ELF headers for MIPS64EL are in a
203   // mixed-endian (which is horrible and I'd say that's a serious spec
204   // bug), and we need to know whether we are reading MIPS ELF files or
205   // not in various places.
206   //
207   // (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
208   // name whatever that means. A fun hypothesis is that "EL" is short for
209   // little-endian written in the little-endian order, but I don't know
210   // if that's true.)
211   bool IsMips64EL;
212
213   // Holds set of ELF header flags for the target.
214   uint32_t EFlags = 0;
215
216   // The ELF spec defines two types of relocation table entries, RELA and
217   // REL. RELA is a triplet of (offset, info, addend) while REL is a
218   // tuple of (offset, info). Addends for REL are implicit and read from
219   // the location where the relocations are applied. So, REL is more
220   // compact than RELA but requires a bit of more work to process.
221   //
222   // (From the linker writer's view, this distinction is not necessary.
223   // If the ELF had chosen whichever and sticked with it, it would have
224   // been easier to write code to process relocations, but it's too late
225   // to change the spec.)
226   //
227   // Each ABI defines its relocation type. IsRela is true if target
228   // uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
229   // few 32-bit ABIs are using RELA too.
230   bool IsRela;
231
232   // True if we are creating position-independent code.
233   bool Pic;
234
235   // 4 for ELF32, 8 for ELF64.
236   int Wordsize;
237 };
238
239 // The only instance of Configuration struct.
240 extern Configuration *Config;
241
242 } // namespace elf
243 } // namespace lld
244
245 #endif