• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- Config.h -------------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLD_COFF_CONFIG_H
10 #define LLD_COFF_CONFIG_H
11 
12 #include "llvm/ADT/MapVector.h"
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 class InputFile;
33 class SectionChunk;
34 
35 // Short aliases.
36 static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
37 static const auto ARM64 = llvm::COFF::IMAGE_FILE_MACHINE_ARM64;
38 static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT;
39 static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386;
40 
41 // Represents an /export option.
42 struct Export {
43   StringRef name;       // N in /export:N or /export:E=N
44   StringRef extName;    // E in /export:E=N
45   Symbol *sym = nullptr;
46   uint16_t ordinal = 0;
47   bool noname = false;
48   bool data = false;
49   bool isPrivate = false;
50   bool constant = false;
51 
52   // If an export is a form of /export:foo=dllname.bar, that means
53   // that foo should be exported as an alias to bar in the DLL.
54   // forwardTo is set to "dllname.bar" part. Usually empty.
55   StringRef forwardTo;
56   StringChunk *forwardChunk = nullptr;
57 
58   // True if this /export option was in .drectves section.
59   bool directives = false;
60   StringRef symbolName;
61   StringRef exportName; // Name in DLL
62 
63   bool operator==(const Export &e) {
64     return (name == e.name && extName == e.extName &&
65             ordinal == e.ordinal && noname == e.noname &&
66             data == e.data && isPrivate == e.isPrivate);
67   }
68 };
69 
70 enum class DebugType {
71   None  = 0x0,
72   CV    = 0x1,  /// CodeView
73   PData = 0x2,  /// Procedure Data
74   Fixup = 0x4,  /// Relocation Table
75 };
76 
77 enum class GuardCFLevel {
78   Off,
79   NoLongJmp, // Emit gfids but no longjmp tables
80   Full,      // Enable all protections.
81 };
82 
83 // Global configuration.
84 struct Configuration {
85   enum ManifestKind { SideBySide, Embed, No };
is64Configuration86   bool is64() { return machine == AMD64 || machine == ARM64; }
87 
88   llvm::COFF::MachineTypes machine = IMAGE_FILE_MACHINE_UNKNOWN;
89   size_t wordsize;
90   bool verbose = false;
91   WindowsSubsystem subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;
92   Symbol *entry = nullptr;
93   bool noEntry = false;
94   std::string outputFile;
95   std::string importName;
96   bool demangle = true;
97   bool doGC = true;
98   bool doICF = true;
99   bool tailMerge;
100   bool relocatable = true;
101   bool forceMultiple = false;
102   bool forceMultipleRes = false;
103   bool forceUnresolved = false;
104   bool debug = false;
105   bool debugDwarf = false;
106   bool debugGHashes = false;
107   bool debugSymtab = false;
108   bool driver = false;
109   bool driverUponly = false;
110   bool driverWdm = false;
111   bool showTiming = false;
112   bool showSummary = false;
113   unsigned debugTypes = static_cast<unsigned>(DebugType::None);
114   std::vector<std::string> natvisFiles;
115   llvm::StringMap<std::string> namedStreams;
116   llvm::SmallString<128> pdbAltPath;
117   llvm::SmallString<128> pdbPath;
118   llvm::SmallString<128> pdbSourcePath;
119   std::vector<llvm::StringRef> argv;
120 
121   // Symbols in this set are considered as live by the garbage collector.
122   std::vector<Symbol *> gcroot;
123 
124   std::set<std::string> noDefaultLibs;
125   bool noDefaultLibAll = false;
126 
127   // True if we are creating a DLL.
128   bool dll = false;
129   StringRef implib;
130   std::vector<Export> exports;
131   bool hadExplicitExports;
132   std::set<std::string> delayLoads;
133   std::map<std::string, int> dllOrder;
134   Symbol *delayLoadHelper = nullptr;
135 
136   bool saveTemps = false;
137 
138   // /guard:cf
139   GuardCFLevel guardCF = GuardCFLevel::Off;
140 
141   // Used for SafeSEH.
142   bool safeSEH = false;
143   Symbol *sehTable = nullptr;
144   Symbol *sehCount = nullptr;
145   bool noSEH = false;
146 
147   // Used for /opt:lldlto=N
148   unsigned ltoo = 2;
149 
150   // Used for /opt:lldltojobs=N
151   std::string thinLTOJobs;
152   // Used for /opt:lldltopartitions=N
153   unsigned ltoPartitions = 1;
154 
155   // Used for /opt:lldltocache=path
156   StringRef ltoCache;
157   // Used for /opt:lldltocachepolicy=policy
158   llvm::CachePruningPolicy ltoCachePolicy;
159 
160   // Used for /opt:[no]ltonewpassmanager
161   bool ltoNewPassManager = false;
162   // Used for /opt:[no]ltodebugpassmanager
163   bool ltoDebugPassManager = false;
164 
165   // Used for /merge:from=to (e.g. /merge:.rdata=.text)
166   std::map<StringRef, StringRef> merge;
167 
168   // Used for /section=.name,{DEKPRSW} to set section attributes.
169   std::map<StringRef, uint32_t> section;
170 
171   // Options for manifest files.
172   ManifestKind manifest = No;
173   int manifestID = 1;
174   StringRef manifestDependency;
175   bool manifestUAC = true;
176   std::vector<std::string> manifestInput;
177   StringRef manifestLevel = "'asInvoker'";
178   StringRef manifestUIAccess = "'false'";
179   StringRef manifestFile;
180 
181   // Used for /aligncomm.
182   std::map<std::string, int> alignComm;
183 
184   // Used for /failifmismatch.
185   std::map<StringRef, std::pair<StringRef, InputFile *>> mustMatch;
186 
187   // Used for /alternatename.
188   std::map<StringRef, StringRef> alternateNames;
189 
190   // Used for /order.
191   llvm::StringMap<int> order;
192 
193   // Used for /lldmap.
194   std::string lldmapFile;
195 
196   // Used for /map.
197   std::string mapFile;
198 
199   // Used for /thinlto-index-only:
200   llvm::StringRef thinLTOIndexOnlyArg;
201 
202   // Used for /thinlto-object-prefix-replace:
203   std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace;
204 
205   // Used for /thinlto-object-suffix-replace:
206   std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
207 
208   // Used for /lto-obj-path:
209   llvm::StringRef ltoObjPath;
210 
211   // Used for /call-graph-ordering-file:
212   llvm::MapVector<std::pair<const SectionChunk *, const SectionChunk *>,
213                   uint64_t>
214       callGraphProfile;
215   bool callGraphProfileSort = false;
216 
217   // Used for /print-symbol-order:
218   StringRef printSymbolOrder;
219 
220   uint64_t align = 4096;
221   uint64_t imageBase = -1;
222   uint64_t fileAlign = 512;
223   uint64_t stackReserve = 1024 * 1024;
224   uint64_t stackCommit = 4096;
225   uint64_t heapReserve = 1024 * 1024;
226   uint64_t heapCommit = 4096;
227   uint32_t majorImageVersion = 0;
228   uint32_t minorImageVersion = 0;
229   // If changing the default os/subsys version here, update the default in
230   // the MinGW driver accordingly.
231   uint32_t majorOSVersion = 6;
232   uint32_t minorOSVersion = 0;
233   uint32_t majorSubsystemVersion = 6;
234   uint32_t minorSubsystemVersion = 0;
235   uint32_t timestamp = 0;
236   uint32_t functionPadMin = 0;
237   bool dynamicBase = true;
238   bool allowBind = true;
239   bool cetCompat = false;
240   bool nxCompat = true;
241   bool allowIsolation = true;
242   bool terminalServerAware = true;
243   bool largeAddressAware = false;
244   bool highEntropyVA = false;
245   bool appContainer = false;
246   bool mingw = false;
247   bool warnMissingOrderSymbol = true;
248   bool warnLocallyDefinedImported = true;
249   bool warnDebugInfoUnusable = true;
250   bool warnLongSectionNames = true;
251   bool incremental = true;
252   bool integrityCheck = false;
253   bool killAt = false;
254   bool repro = false;
255   bool swaprunCD = false;
256   bool swaprunNet = false;
257   bool thinLTOEmitImportsFiles;
258   bool thinLTOIndexOnly;
259   bool autoImport = false;
260   bool pseudoRelocs = false;
261 };
262 
263 extern Configuration *config;
264 
265 } // namespace coff
266 } // namespace lld
267 
268 #endif
269