]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/Config.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r304149, 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/Support/CachePruning.h"
17 #include "llvm/Support/CodeGen.h"
18 #include "llvm/Support/ELF.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 // This struct contains the global configuration for the linker.
71 // Most fields are direct mapping from the command line options
72 // and such fields have the same name as the corresponding options.
73 // Most fields are initialized by the driver.
74 struct Configuration {
75   InputFile *FirstElf = nullptr;
76   uint8_t OSABI = 0;
77   llvm::CachePruningPolicy ThinLTOCachePolicy;
78   llvm::StringMap<uint64_t> SectionStartMap;
79   llvm::StringRef DynamicLinker;
80   llvm::StringRef Entry;
81   llvm::StringRef Emulation;
82   llvm::StringRef Fini;
83   llvm::StringRef Init;
84   llvm::StringRef LTOAAPipeline;
85   llvm::StringRef LTONewPmPasses;
86   llvm::StringRef MapFile;
87   llvm::StringRef OutputFile;
88   llvm::StringRef OptRemarksFilename;
89   llvm::StringRef SoName;
90   llvm::StringRef Sysroot;
91   llvm::StringRef ThinLTOCacheDir;
92   std::string Rpath;
93   std::vector<VersionDefinition> VersionDefinitions;
94   std::vector<llvm::StringRef> AuxiliaryList;
95   std::vector<llvm::StringRef> SearchPaths;
96   std::vector<llvm::StringRef> SymbolOrderingFile;
97   std::vector<llvm::StringRef> Undefined;
98   std::vector<SymbolVersion> VersionScriptGlobals;
99   std::vector<SymbolVersion> VersionScriptLocals;
100   std::vector<uint8_t> BuildIdVector;
101   bool AllowMultipleDefinition;
102   bool AsNeeded = false;
103   bool Bsymbolic;
104   bool BsymbolicFunctions;
105   bool ColorDiagnostics = false;
106   bool CompressDebugSections;
107   bool DefineCommon;
108   bool Demangle = true;
109   bool DisableVerify;
110   bool EhFrameHdr;
111   bool EmitRelocs;
112   bool EnableNewDtags;
113   bool ExportDynamic;
114   bool FatalWarnings;
115   bool GcSections;
116   bool GdbIndex;
117   bool GnuHash;
118   bool ICF;
119   bool MipsN32Abi = false;
120   bool NoGnuUnique;
121   bool NoUndefinedVersion;
122   bool Nostdlib;
123   bool OFormatBinary;
124   bool Omagic;
125   bool OptRemarksWithHotness;
126   bool Pie;
127   bool PrintGcSections;
128   bool Relocatable;
129   bool SaveTemps;
130   bool SingleRoRx;
131   bool Shared;
132   bool Static = false;
133   bool SysvHash;
134   bool Target1Rel;
135   bool Threads;
136   bool Trace;
137   bool Verbose;
138   bool WarnCommon;
139   bool WarnMissingEntry;
140   bool ZCombreloc;
141   bool ZExecstack;
142   bool ZNocopyreloc;
143   bool ZNodelete;
144   bool ZNodlopen;
145   bool ZNow;
146   bool ZOrigin;
147   bool ZRelro;
148   bool ZRodynamic;
149   bool ZText;
150   bool ExitEarly;
151   bool ZWxneeded;
152   DiscardPolicy Discard;
153   SortSectionPolicy SortSection;
154   StripPolicy Strip;
155   UnresolvedPolicy UnresolvedSymbols;
156   Target2Policy Target2;
157   BuildIdKind BuildId = BuildIdKind::None;
158   ELFKind EKind = ELFNoneKind;
159   uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
160   uint16_t EMachine = llvm::ELF::EM_NONE;
161   uint64_t ErrorLimit = 20;
162   uint64_t ImageBase;
163   uint64_t MaxPageSize;
164   uint64_t ZStackSize;
165   unsigned LTOPartitions;
166   unsigned LTOO;
167   unsigned Optimize;
168   unsigned ThinLTOJobs;
169
170   // The following config options do not directly correspond to any
171   // particualr command line options.
172
173   // True if we need to pass through relocations in input files to the
174   // output file. Usually false because we consume relocations.
175   bool CopyRelocs;
176
177   // True if the target is ELF64. False if ELF32.
178   bool Is64;
179
180   // True if the target is little-endian. False if big-endian.
181   bool IsLE;
182
183   // endianness::little if IsLE is true. endianness::big otherwise.
184   llvm::support::endianness Endianness;
185
186   // True if the target is the little-endian MIPS64.
187   //
188   // The reason why we have this variable only for the MIPS is because
189   // we use this often.  Some ELF headers for MIPS64EL are in a
190   // mixed-endian (which is horrible and I'd say that's a serious spec
191   // bug), and we need to know whether we are reading MIPS ELF files or
192   // not in various places.
193   //
194   // (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
195   // name whatever that means. A fun hypothesis is that "EL" is short for
196   // little-endian written in the little-endian order, but I don't know
197   // if that's true.)
198   bool IsMips64EL;
199
200   // The ELF spec defines two types of relocation table entries, RELA and
201   // REL. RELA is a triplet of (offset, info, addend) while REL is a
202   // tuple of (offset, info). Addends for REL are implicit and read from
203   // the location where the relocations are applied. So, REL is more
204   // compact than RELA but requires a bit of more work to process.
205   //
206   // (From the linker writer's view, this distinction is not necessary.
207   // If the ELF had chosen whichever and sticked with it, it would have
208   // been easier to write code to process relocations, but it's too late
209   // to change the spec.)
210   //
211   // Each ABI defines its relocation type. IsRela is true if target
212   // uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
213   // few 32-bit ABIs are using RELA too.
214   bool IsRela;
215
216   // True if we are creating position-independent code.
217   bool Pic;
218
219   // 4 for ELF32, 8 for ELF64.
220   int Wordsize;
221 };
222
223 // The only instance of Configuration struct.
224 extern Configuration *Config;
225
226 } // namespace elf
227 } // namespace lld
228
229 #endif