xref: /llvm-project-15.0.7/lld/ELF/Config.h (revision bb8fe317)
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/Support/ELF.h"
16 
17 #include <vector>
18 
19 namespace lld {
20 namespace elf {
21 
22 class InputFile;
23 struct Symbol;
24 
25 enum ELFKind {
26   ELFNoneKind,
27   ELF32LEKind,
28   ELF32BEKind,
29   ELF64LEKind,
30   ELF64BEKind
31 };
32 
33 // For --build-id.
34 enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid };
35 
36 // For --discard-{all,locals,none}.
37 enum class DiscardPolicy { Default, All, Locals, None };
38 
39 // For --strip-{all,debug}.
40 enum class StripPolicy { None, All, Debug };
41 
42 // For --unresolved-symbols.
43 enum class UnresolvedPolicy { NoUndef, ReportError, Warn, Ignore };
44 
45 // For --sort-section and linkerscript sorting rules.
46 enum class SortSectionPolicy { Default, None, Alignment, Name, Priority };
47 
48 struct SymbolVersion {
49   llvm::StringRef Name;
50   bool IsExternCpp;
51   bool HasWildcards;
52 };
53 
54 // This struct contains symbols version definition that
55 // can be found in version script if it is used for link.
56 struct VersionDefinition {
57   VersionDefinition(llvm::StringRef Name, size_t Id) : Name(Name), Id(Id) {}
58   llvm::StringRef Name;
59   size_t Id;
60   std::vector<SymbolVersion> Globals;
61   size_t NameOff; // Offset in string table.
62 };
63 
64 // This struct contains the global configuration for the linker.
65 // Most fields are direct mapping from the command line options
66 // and such fields have the same name as the corresponding options.
67 // Most fields are initialized by the driver.
68 struct Configuration {
69   Symbol *EntrySym = nullptr;
70   InputFile *FirstElf = nullptr;
71   llvm::StringMap<uint64_t> SectionStartMap;
72   llvm::StringRef DynamicLinker;
73   llvm::StringRef Entry;
74   llvm::StringRef Emulation;
75   llvm::StringRef Fini;
76   llvm::StringRef Init;
77   llvm::StringRef LtoAAPipeline;
78   llvm::StringRef LtoNewPmPasses;
79   llvm::StringRef OutputFile;
80   llvm::StringRef SoName;
81   llvm::StringRef Sysroot;
82   std::string RPath;
83   std::vector<VersionDefinition> VersionDefinitions;
84   std::vector<llvm::StringRef> AuxiliaryList;
85   std::vector<llvm::StringRef> DynamicList;
86   std::vector<llvm::StringRef> SearchPaths;
87   std::vector<llvm::StringRef> Undefined;
88   std::vector<SymbolVersion> VersionScriptGlobals;
89   std::vector<uint8_t> BuildIdVector;
90   bool AllowMultipleDefinition;
91   bool AsNeeded = false;
92   bool Binary = false;
93   bool Bsymbolic;
94   bool BsymbolicFunctions;
95   bool Demangle = true;
96   bool DisableVerify;
97   bool EhFrameHdr;
98   bool EnableNewDtags;
99   bool ExportDynamic;
100   bool FatalWarnings;
101   bool GcSections;
102   bool GnuHash = false;
103   bool ICF;
104   bool Mips64EL = false;
105   bool NoGnuUnique;
106   bool NoUndefinedVersion;
107   bool Nostdlib;
108   bool OFormatBinary;
109   bool Pic;
110   bool Pie;
111   bool PrintGcSections;
112   bool Rela;
113   bool Relocatable;
114   bool SaveTemps;
115   bool Shared;
116   bool Static = false;
117   bool SysvHash = true;
118   bool Target1Rel;
119   bool Threads;
120   bool Trace;
121   bool Verbose;
122   bool WarnCommon;
123   bool ZCombreloc;
124   bool ZExecstack;
125   bool ZNodelete;
126   bool ZNow;
127   bool ZOrigin;
128   bool ZRelro;
129   DiscardPolicy Discard;
130   SortSectionPolicy SortSection;
131   StripPolicy Strip = StripPolicy::None;
132   UnresolvedPolicy UnresolvedSymbols;
133   BuildIdKind BuildId = BuildIdKind::None;
134   ELFKind EKind = ELFNoneKind;
135   uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
136   uint16_t EMachine = llvm::ELF::EM_NONE;
137   uint64_t EntryAddr = 0;
138   uint64_t ImageBase;
139   uint64_t MaxPageSize;
140   uint64_t ZStackSize;
141   unsigned LtoPartitions;
142   unsigned LtoO;
143   unsigned Optimize;
144   unsigned ThinLtoJobs;
145 };
146 
147 // The only instance of Configuration struct.
148 extern Configuration *Config;
149 
150 } // namespace elf
151 } // namespace lld
152 
153 #endif
154