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_COFF_CONFIG_H
11 #define LLD_COFF_CONFIG_H
12 
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Object/COFF.h"
16 #include "llvm/Support/CachePruning.h"
17 #include <cstdint>
18 #include <map>
19 #include <set>
20 #include <string>
21 
22 namespace lld {
23 namespace coff {
24 
25 using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
26 using llvm::COFF::WindowsSubsystem;
27 using llvm::StringRef;
28 class DefinedAbsolute;
29 class DefinedRelative;
30 class StringChunk;
31 class Symbol;
32 
33 // Short aliases.
34 static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
35 static const auto ARM64 = llvm::COFF::IMAGE_FILE_MACHINE_ARM64;
36 static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT;
37 static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386;
38 
39 // Represents an /export option.
40 struct Export {
41   StringRef Name;       // N in /export:N or /export:E=N
42   StringRef ExtName;    // E in /export:E=N
43   Symbol *Sym = nullptr;
44   uint16_t Ordinal = 0;
45   bool Noname = false;
46   bool Data = false;
47   bool Private = false;
48   bool Constant = false;
49 
50   // If an export is a form of /export:foo=dllname.bar, that means
51   // that foo should be exported as an alias to bar in the DLL.
52   // ForwardTo is set to "dllname.bar" part. Usually empty.
53   StringRef ForwardTo;
54   StringChunk *ForwardChunk = nullptr;
55 
56   // True if this /export option was in .drectves section.
57   bool Directives = false;
58   StringRef SymbolName;
59   StringRef ExportName; // Name in DLL
60 
61   bool operator==(const Export &E) {
62     return (Name == E.Name && ExtName == E.ExtName &&
63             Ordinal == E.Ordinal && Noname == E.Noname &&
64             Data == E.Data && Private == E.Private);
65   }
66 };
67 
68 enum class DebugType {
69   None  = 0x0,
70   CV    = 0x1,  /// CodeView
71   PData = 0x2,  /// Procedure Data
72   Fixup = 0x4,  /// Relocation Table
73 };
74 
75 enum class GuardCFLevel {
76   Off,
77   NoLongJmp, // Emit gfids but no longjmp tables
78   Full,      // Enable all protections.
79 };
80 
81 // Global configuration.
82 struct Configuration {
83   enum ManifestKind { SideBySide, Embed, No };
is64Configuration84   bool is64() { return Machine == AMD64 || Machine == ARM64; }
85 
86   llvm::COFF::MachineTypes Machine = IMAGE_FILE_MACHINE_UNKNOWN;
87   size_t Wordsize;
88   bool Verbose = false;
89   WindowsSubsystem Subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;
90   Symbol *Entry = nullptr;
91   bool NoEntry = false;
92   std::string OutputFile;
93   std::string ImportName;
94   bool DoGC = true;
95   bool DoICF = true;
96   bool TailMerge;
97   bool Relocatable = true;
98   bool ForceMultiple = false;
99   bool ForceUnresolved = false;
100   bool Debug = false;
101   bool DebugDwarf = false;
102   bool DebugGHashes = false;
103   bool DebugSymtab = false;
104   bool ShowTiming = false;
105   unsigned DebugTypes = static_cast<unsigned>(DebugType::None);
106   std::vector<std::string> NatvisFiles;
107   llvm::SmallString<128> PDBAltPath;
108   llvm::SmallString<128> PDBPath;
109   llvm::SmallString<128> PDBSourcePath;
110   std::vector<llvm::StringRef> Argv;
111 
112   // Symbols in this set are considered as live by the garbage collector.
113   std::vector<Symbol *> GCRoot;
114 
115   std::set<StringRef> NoDefaultLibs;
116   bool NoDefaultLibAll = false;
117 
118   // True if we are creating a DLL.
119   bool DLL = false;
120   StringRef Implib;
121   std::vector<Export> Exports;
122   std::set<std::string> DelayLoads;
123   std::map<std::string, int> DLLOrder;
124   Symbol *DelayLoadHelper = nullptr;
125 
126   bool SaveTemps = false;
127 
128   // /guard:cf
129   GuardCFLevel GuardCF = GuardCFLevel::Off;
130 
131   // Used for SafeSEH.
132   Symbol *SEHTable = nullptr;
133   Symbol *SEHCount = nullptr;
134 
135   // Used for /opt:lldlto=N
136   unsigned LTOO = 2;
137 
138   // Used for /opt:lldltojobs=N
139   unsigned ThinLTOJobs = 0;
140   // Used for /opt:lldltopartitions=N
141   unsigned LTOPartitions = 1;
142 
143   // Used for /opt:lldltocache=path
144   StringRef LTOCache;
145   // Used for /opt:lldltocachepolicy=policy
146   llvm::CachePruningPolicy LTOCachePolicy;
147 
148   // Used for /merge:from=to (e.g. /merge:.rdata=.text)
149   std::map<StringRef, StringRef> Merge;
150 
151   // Used for /section=.name,{DEKPRSW} to set section attributes.
152   std::map<StringRef, uint32_t> Section;
153 
154   // Options for manifest files.
155   ManifestKind Manifest = No;
156   int ManifestID = 1;
157   StringRef ManifestDependency;
158   bool ManifestUAC = true;
159   std::vector<std::string> ManifestInput;
160   StringRef ManifestLevel = "'asInvoker'";
161   StringRef ManifestUIAccess = "'false'";
162   StringRef ManifestFile;
163 
164   // Used for /aligncomm.
165   std::map<std::string, int> AlignComm;
166 
167   // Used for /failifmismatch.
168   std::map<StringRef, StringRef> MustMatch;
169 
170   // Used for /alternatename.
171   std::map<StringRef, StringRef> AlternateNames;
172 
173   // Used for /order.
174   llvm::StringMap<int> Order;
175 
176   // Used for /lldmap.
177   std::string MapFile;
178 
179   uint64_t ImageBase = -1;
180   uint64_t StackReserve = 1024 * 1024;
181   uint64_t StackCommit = 4096;
182   uint64_t HeapReserve = 1024 * 1024;
183   uint64_t HeapCommit = 4096;
184   uint32_t MajorImageVersion = 0;
185   uint32_t MinorImageVersion = 0;
186   uint32_t MajorOSVersion = 6;
187   uint32_t MinorOSVersion = 0;
188   uint32_t Timestamp = 0;
189   bool DynamicBase = true;
190   bool AllowBind = true;
191   bool NxCompat = true;
192   bool AllowIsolation = true;
193   bool TerminalServerAware = true;
194   bool LargeAddressAware = false;
195   bool HighEntropyVA = false;
196   bool AppContainer = false;
197   bool MinGW = false;
198   bool WarnMissingOrderSymbol = true;
199   bool WarnLocallyDefinedImported = true;
200   bool WarnDebugInfoUnusable = true;
201   bool Incremental = true;
202   bool IntegrityCheck = false;
203   bool KillAt = false;
204   bool Repro = false;
205 };
206 
207 extern Configuration *Config;
208 
209 } // namespace coff
210 } // namespace lld
211 
212 #endif
213