]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lld/COFF/Config.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lld / COFF / Config.h
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/StringMap.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Object/COFF.h"
15 #include "llvm/Support/CachePruning.h"
16 #include <cstdint>
17 #include <map>
18 #include <set>
19 #include <string>
20
21 namespace lld {
22 namespace coff {
23
24 using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
25 using llvm::COFF::WindowsSubsystem;
26 using llvm::StringRef;
27 class DefinedAbsolute;
28 class DefinedRelative;
29 class StringChunk;
30 class Symbol;
31 class InputFile;
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 isPrivate = 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 && isPrivate == e.isPrivate);
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 };
84   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 demangle = true;
95   bool doGC = true;
96   bool doICF = true;
97   bool tailMerge;
98   bool relocatable = true;
99   bool forceMultiple = false;
100   bool forceMultipleRes = false;
101   bool forceUnresolved = false;
102   bool debug = false;
103   bool debugDwarf = false;
104   bool debugGHashes = false;
105   bool debugSymtab = false;
106   bool driver = false;
107   bool driverUponly = false;
108   bool driverWdm = false;
109   bool showTiming = false;
110   bool showSummary = false;
111   unsigned debugTypes = static_cast<unsigned>(DebugType::None);
112   std::vector<std::string> natvisFiles;
113   llvm::StringMap<std::string> namedStreams;
114   llvm::SmallString<128> pdbAltPath;
115   llvm::SmallString<128> pdbPath;
116   llvm::SmallString<128> pdbSourcePath;
117   std::vector<llvm::StringRef> argv;
118
119   // Symbols in this set are considered as live by the garbage collector.
120   std::vector<Symbol *> gcroot;
121
122   std::set<std::string> noDefaultLibs;
123   bool noDefaultLibAll = false;
124
125   // True if we are creating a DLL.
126   bool dll = false;
127   StringRef implib;
128   std::vector<Export> exports;
129   bool hadExplicitExports;
130   std::set<std::string> delayLoads;
131   std::map<std::string, int> dllOrder;
132   Symbol *delayLoadHelper = nullptr;
133
134   bool saveTemps = false;
135
136   // /guard:cf
137   GuardCFLevel guardCF = GuardCFLevel::Off;
138
139   // Used for SafeSEH.
140   bool safeSEH = false;
141   Symbol *sehTable = nullptr;
142   Symbol *sehCount = nullptr;
143   bool noSEH = false;
144
145   // Used for /opt:lldlto=N
146   unsigned ltoo = 2;
147
148   // Used for /opt:lldltojobs=N
149   std::string thinLTOJobs;
150   // Used for /opt:lldltopartitions=N
151   unsigned ltoPartitions = 1;
152
153   // Used for /opt:lldltocache=path
154   StringRef ltoCache;
155   // Used for /opt:lldltocachepolicy=policy
156   llvm::CachePruningPolicy ltoCachePolicy;
157
158   // Used for /merge:from=to (e.g. /merge:.rdata=.text)
159   std::map<StringRef, StringRef> merge;
160
161   // Used for /section=.name,{DEKPRSW} to set section attributes.
162   std::map<StringRef, uint32_t> section;
163
164   // Options for manifest files.
165   ManifestKind manifest = No;
166   int manifestID = 1;
167   StringRef manifestDependency;
168   bool manifestUAC = true;
169   std::vector<std::string> manifestInput;
170   StringRef manifestLevel = "'asInvoker'";
171   StringRef manifestUIAccess = "'false'";
172   StringRef manifestFile;
173
174   // Used for /aligncomm.
175   std::map<std::string, int> alignComm;
176
177   // Used for /failifmismatch.
178   std::map<StringRef, std::pair<StringRef, InputFile *>> mustMatch;
179
180   // Used for /alternatename.
181   std::map<StringRef, StringRef> alternateNames;
182
183   // Used for /order.
184   llvm::StringMap<int> order;
185
186   // Used for /lldmap.
187   std::string lldmapFile;
188
189   // Used for /map.
190   std::string mapFile;
191
192   // Used for /thinlto-index-only:
193   llvm::StringRef thinLTOIndexOnlyArg;
194
195   // Used for /thinlto-object-prefix-replace:
196   std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace;
197
198   // Used for /thinlto-object-suffix-replace:
199   std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
200
201   // Used for /lto-obj-path:
202   llvm::StringRef ltoObjPath;
203
204   uint64_t align = 4096;
205   uint64_t imageBase = -1;
206   uint64_t fileAlign = 512;
207   uint64_t stackReserve = 1024 * 1024;
208   uint64_t stackCommit = 4096;
209   uint64_t heapReserve = 1024 * 1024;
210   uint64_t heapCommit = 4096;
211   uint32_t majorImageVersion = 0;
212   uint32_t minorImageVersion = 0;
213   uint32_t majorOSVersion = 6;
214   uint32_t minorOSVersion = 0;
215   uint32_t timestamp = 0;
216   uint32_t functionPadMin = 0;
217   bool dynamicBase = true;
218   bool allowBind = true;
219   bool cetCompat = false;
220   bool nxCompat = true;
221   bool allowIsolation = true;
222   bool terminalServerAware = true;
223   bool largeAddressAware = false;
224   bool highEntropyVA = false;
225   bool appContainer = false;
226   bool mingw = false;
227   bool warnMissingOrderSymbol = true;
228   bool warnLocallyDefinedImported = true;
229   bool warnDebugInfoUnusable = true;
230   bool warnLongSectionNames = true;
231   bool incremental = true;
232   bool integrityCheck = false;
233   bool killAt = false;
234   bool repro = false;
235   bool swaprunCD = false;
236   bool swaprunNet = false;
237   bool thinLTOEmitImportsFiles;
238   bool thinLTOIndexOnly;
239   bool autoImport = false;
240   bool pseudoRelocs = false;
241 };
242
243 extern Configuration *config;
244
245 } // namespace coff
246 } // namespace lld
247
248 #endif