]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/Config.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r307894, and update
[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 struct Symbol;
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 --strip-{all,debug}.
44 enum class StripPolicy { None, All, Debug };
45
46 // For --unresolved-symbols.
47 enum class UnresolvedPolicy { ReportError, Warn, WarnAll, Ignore, IgnoreAll };
48
49 // For --sort-section and linkerscript sorting rules.
50 enum class SortSectionPolicy { Default, None, Alignment, Name, Priority };
51
52 // For --target2
53 enum class Target2Policy { Abs, Rel, GotRel };
54
55 struct SymbolVersion {
56   llvm::StringRef Name;
57   bool IsExternCpp;
58   bool HasWildcard;
59 };
60
61 // This struct contains symbols version definition that
62 // can be found in version script if it is used for link.
63 struct VersionDefinition {
64   llvm::StringRef Name;
65   uint16_t Id = 0;
66   std::vector<SymbolVersion> Globals;
67   size_t NameOff = 0; // Offset in the string table
68 };
69
70 // Structure for mapping renamed symbols
71 struct RenamedSymbol {
72   Symbol *Target;
73   uint8_t OriginalBinding;
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   InputFile *FirstElf = nullptr;
82   uint8_t OSABI = 0;
83   llvm::CachePruningPolicy ThinLTOCachePolicy;
84   llvm::StringMap<uint64_t> SectionStartMap;
85   llvm::StringRef DynamicLinker;
86   llvm::StringRef Entry;
87   llvm::StringRef Emulation;
88   llvm::StringRef Fini;
89   llvm::StringRef Init;
90   llvm::StringRef LTOAAPipeline;
91   llvm::StringRef LTONewPmPasses;
92   llvm::StringRef MapFile;
93   llvm::StringRef OutputFile;
94   llvm::StringRef OptRemarksFilename;
95   llvm::StringRef SoName;
96   llvm::StringRef Sysroot;
97   llvm::StringRef ThinLTOCacheDir;
98   std::string Rpath;
99   std::vector<VersionDefinition> VersionDefinitions;
100   std::vector<llvm::StringRef> Argv;
101   std::vector<llvm::StringRef> AuxiliaryList;
102   std::vector<llvm::StringRef> SearchPaths;
103   std::vector<llvm::StringRef> SymbolOrderingFile;
104   std::vector<llvm::StringRef> Undefined;
105   std::vector<SymbolVersion> VersionScriptGlobals;
106   std::vector<SymbolVersion> VersionScriptLocals;
107   std::vector<uint8_t> BuildIdVector;
108   llvm::MapVector<Symbol *, RenamedSymbol> RenamedSymbols;
109   bool AllowMultipleDefinition;
110   bool AsNeeded = false;
111   bool Bsymbolic;
112   bool BsymbolicFunctions;
113   bool ColorDiagnostics = false;
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 FatalWarnings;
123   bool GcSections;
124   bool GdbIndex;
125   bool GnuHash;
126   bool ICF;
127   bool MipsN32Abi = false;
128   bool NoGnuUnique;
129   bool NoUndefinedVersion;
130   bool Nostdlib;
131   bool OFormatBinary;
132   bool Omagic;
133   bool OptRemarksWithHotness;
134   bool Pie;
135   bool PrintGcSections;
136   bool Relocatable;
137   bool SaveTemps;
138   bool SingleRoRx;
139   bool Shared;
140   bool Static = false;
141   bool SysvHash;
142   bool Target1Rel;
143   bool Threads;
144   bool Trace;
145   bool Verbose;
146   bool WarnCommon;
147   bool WarnMissingEntry;
148   bool ZCombreloc;
149   bool ZExecstack;
150   bool ZNocopyreloc;
151   bool ZNodelete;
152   bool ZNodlopen;
153   bool ZNow;
154   bool ZOrigin;
155   bool ZRelro;
156   bool ZRodynamic;
157   bool ZText;
158   bool ExitEarly;
159   bool ZWxneeded;
160   DiscardPolicy Discard;
161   SortSectionPolicy SortSection;
162   StripPolicy Strip;
163   UnresolvedPolicy UnresolvedSymbols;
164   Target2Policy Target2;
165   BuildIdKind BuildId = BuildIdKind::None;
166   ELFKind EKind = ELFNoneKind;
167   uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
168   uint16_t EMachine = llvm::ELF::EM_NONE;
169   uint64_t ErrorLimit = 20;
170   uint64_t ImageBase;
171   uint64_t MaxPageSize;
172   uint64_t ZStackSize;
173   unsigned LTOPartitions;
174   unsigned LTOO;
175   unsigned Optimize;
176   unsigned ThinLTOJobs;
177
178   // The following config options do not directly correspond to any
179   // particualr command line options.
180
181   // True if we need to pass through relocations in input files to the
182   // output file. Usually false because we consume relocations.
183   bool CopyRelocs;
184
185   // True if the target is ELF64. False if ELF32.
186   bool Is64;
187
188   // True if the target is little-endian. False if big-endian.
189   bool IsLE;
190
191   // endianness::little if IsLE is true. endianness::big otherwise.
192   llvm::support::endianness Endianness;
193
194   // True if the target is the little-endian MIPS64.
195   //
196   // The reason why we have this variable only for the MIPS is because
197   // we use this often.  Some ELF headers for MIPS64EL are in a
198   // mixed-endian (which is horrible and I'd say that's a serious spec
199   // bug), and we need to know whether we are reading MIPS ELF files or
200   // not in various places.
201   //
202   // (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
203   // name whatever that means. A fun hypothesis is that "EL" is short for
204   // little-endian written in the little-endian order, but I don't know
205   // if that's true.)
206   bool IsMips64EL;
207
208   // The ELF spec defines two types of relocation table entries, RELA and
209   // REL. RELA is a triplet of (offset, info, addend) while REL is a
210   // tuple of (offset, info). Addends for REL are implicit and read from
211   // the location where the relocations are applied. So, REL is more
212   // compact than RELA but requires a bit of more work to process.
213   //
214   // (From the linker writer's view, this distinction is not necessary.
215   // If the ELF had chosen whichever and sticked with it, it would have
216   // been easier to write code to process relocations, but it's too late
217   // to change the spec.)
218   //
219   // Each ABI defines its relocation type. IsRela is true if target
220   // uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
221   // few 32-bit ABIs are using RELA too.
222   bool IsRela;
223
224   // True if we are creating position-independent code.
225   bool Pic;
226
227   // 4 for ELF32, 8 for ELF64.
228   int Wordsize;
229 };
230
231 // The only instance of Configuration struct.
232 extern Configuration *Config;
233
234 } // namespace elf
235 } // namespace lld
236
237 #endif