]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/Config.h
Add LLVM openmp trunk r351319 (just before the release_80 branch point)
[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 };
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 CallGraphProfileSort;
133   bool CheckSections;
134   bool CompressDebugSections;
135   bool Cref;
136   bool DefineCommon;
137   bool Demangle = true;
138   bool DisableVerify;
139   bool EhFrameHdr;
140   bool EmitLLVM;
141   bool EmitRelocs;
142   bool EnableNewDtags;
143   bool ExecuteOnly;
144   bool ExportDynamic;
145   bool FixCortexA53Errata843419;
146   bool FormatBinary = false;
147   bool GcSections;
148   bool GdbIndex;
149   bool GnuHash = false;
150   bool GnuUnique;
151   bool HasDynamicList = false;
152   bool HasDynSymTab;
153   bool IgnoreDataAddressEquality;
154   bool IgnoreFunctionAddressEquality;
155   bool LTODebugPassManager;
156   bool LTONewPassManager;
157   bool MergeArmExidx;
158   bool MipsN32Abi = false;
159   bool NoinhibitExec;
160   bool Nostdlib;
161   bool OFormatBinary;
162   bool Omagic;
163   bool OptRemarksWithHotness;
164   bool PicThunk;
165   bool Pie;
166   bool PrintGcSections;
167   bool PrintIcfSections;
168   bool Relocatable;
169   bool RelrPackDynRelocs;
170   bool SaveTemps;
171   bool SingleRoRx;
172   bool Shared;
173   bool Static = false;
174   bool SysvHash = false;
175   bool Target1Rel;
176   bool Trace;
177   bool ThinLTOEmitImportsFiles;
178   bool ThinLTOIndexOnly;
179   bool TocOptimize;
180   bool UndefinedVersion;
181   bool UseAndroidRelrTags = false;
182   bool WarnBackrefs;
183   bool WarnCommon;
184   bool WarnIfuncTextrel;
185   bool WarnMissingEntry;
186   bool WarnSymbolOrdering;
187   bool WriteAddends;
188   bool ZCombreloc;
189   bool ZCopyreloc;
190   bool ZExecstack;
191   bool ZGlobal;
192   bool ZHazardplt;
193   bool ZIfuncnoplt;
194   bool ZInitfirst;
195   bool ZInterpose;
196   bool ZKeepTextSectionPrefix;
197   bool ZNodefaultlib;
198   bool ZNodelete;
199   bool ZNodlopen;
200   bool ZNow;
201   bool ZOrigin;
202   bool ZRelro;
203   bool ZRodynamic;
204   bool ZText;
205   bool ZRetpolineplt;
206   bool ZWxneeded;
207   DiscardPolicy Discard;
208   ICFLevel ICF;
209   OrphanHandlingPolicy OrphanHandling;
210   SortSectionPolicy SortSection;
211   StripPolicy Strip;
212   UnresolvedPolicy UnresolvedSymbols;
213   Target2Policy Target2;
214   ARMVFPArgKind ARMVFPArgs = ARMVFPArgKind::Default;
215   BuildIdKind BuildId = BuildIdKind::None;
216   ELFKind EKind = ELFNoneKind;
217   uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
218   uint16_t EMachine = llvm::ELF::EM_NONE;
219   llvm::Optional<uint64_t> ImageBase;
220   uint64_t MaxPageSize;
221   uint64_t MipsGotSize;
222   uint64_t ZStackSize;
223   unsigned LTOPartitions;
224   unsigned LTOO;
225   unsigned Optimize;
226   unsigned ThinLTOJobs;
227   int32_t SplitStackAdjustSize;
228
229   // The following config options do not directly correspond to any
230   // particualr command line options.
231
232   // True if we need to pass through relocations in input files to the
233   // output file. Usually false because we consume relocations.
234   bool CopyRelocs;
235
236   // True if the target is ELF64. False if ELF32.
237   bool Is64;
238
239   // True if the target is little-endian. False if big-endian.
240   bool IsLE;
241
242   // endianness::little if IsLE is true. endianness::big otherwise.
243   llvm::support::endianness Endianness;
244
245   // True if the target is the little-endian MIPS64.
246   //
247   // The reason why we have this variable only for the MIPS is because
248   // we use this often.  Some ELF headers for MIPS64EL are in a
249   // mixed-endian (which is horrible and I'd say that's a serious spec
250   // bug), and we need to know whether we are reading MIPS ELF files or
251   // not in various places.
252   //
253   // (Note that MIPS64EL is not a typo for MIPS64LE. This is the official
254   // name whatever that means. A fun hypothesis is that "EL" is short for
255   // little-endian written in the little-endian order, but I don't know
256   // if that's true.)
257   bool IsMips64EL;
258
259   // Holds set of ELF header flags for the target.
260   uint32_t EFlags = 0;
261
262   // The ELF spec defines two types of relocation table entries, RELA and
263   // REL. RELA is a triplet of (offset, info, addend) while REL is a
264   // tuple of (offset, info). Addends for REL are implicit and read from
265   // the location where the relocations are applied. So, REL is more
266   // compact than RELA but requires a bit of more work to process.
267   //
268   // (From the linker writer's view, this distinction is not necessary.
269   // If the ELF had chosen whichever and sticked with it, it would have
270   // been easier to write code to process relocations, but it's too late
271   // to change the spec.)
272   //
273   // Each ABI defines its relocation type. IsRela is true if target
274   // uses RELA. As far as we know, all 64-bit ABIs are using RELA. A
275   // few 32-bit ABIs are using RELA too.
276   bool IsRela;
277
278   // True if we are creating position-independent code.
279   bool Pic;
280
281   // 4 for ELF32, 8 for ELF64.
282   int Wordsize;
283 };
284
285 // The only instance of Configuration struct.
286 extern Configuration *Config;
287
288 static inline void errorOrWarn(const Twine &Msg) {
289   if (!Config->NoinhibitExec)
290     error(Msg);
291   else
292     warn(Msg);
293 }
294 } // namespace elf
295 } // namespace lld
296
297 #endif