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