[NFC][Coroutines] Use structured binding with llvm::enumerate in CoroSplit (#116879)
[llvm-project.git] / lld / wasm / Config.h
blobeb32ce80f4a3d923266010c3c8456144d748a201
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 //===----------------------------------------------------------------------===//
9 #ifndef LLD_WASM_CONFIG_H
10 #define LLD_WASM_CONFIG_H
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/StringSet.h"
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/BinaryFormat/Wasm.h"
17 #include "llvm/Support/CachePruning.h"
18 #include <optional>
20 namespace llvm {
21 enum class CodeGenOptLevel;
22 } // namespace llvm
24 namespace lld::wasm {
26 class InputFile;
27 class StubFile;
28 class ObjFile;
29 class SharedFile;
30 class BitcodeFile;
31 class InputTable;
32 class InputGlobal;
33 class InputFunction;
34 class Symbol;
36 // For --unresolved-symbols.
37 enum class UnresolvedPolicy { ReportError, Warn, Ignore, ImportDynamic };
39 // For --build-id.
40 enum class BuildIdKind { None, Fast, Sha1, Hexstring, Uuid };
42 // This struct contains the global configuration for the linker.
43 // Most fields are direct mapping from the command line options
44 // and such fields have the same name as the corresponding options.
45 // Most fields are initialized by the driver.
46 struct Configuration {
47 bool allowMultipleDefinition;
48 bool bsymbolic;
49 bool checkFeatures;
50 bool compressRelocations;
51 bool demangle;
52 bool disableVerify;
53 bool experimentalPic;
54 bool emitRelocs;
55 bool exportAll;
56 bool exportDynamic;
57 bool exportTable;
58 bool extendedConst;
59 bool growableTable;
60 bool gcSections;
61 llvm::StringSet<> keepSections;
62 std::optional<std::pair<llvm::StringRef, llvm::StringRef>> memoryImport;
63 std::optional<llvm::StringRef> memoryExport;
64 bool sharedMemory;
65 bool importTable;
66 bool importUndefined;
67 std::optional<bool> is64;
68 bool mergeDataSegments;
69 bool noinhibitExec;
70 bool pie;
71 bool printGcSections;
72 bool relocatable;
73 bool saveTemps;
74 bool shared;
75 bool shlibSigCheck;
76 bool stripAll;
77 bool stripDebug;
78 bool stackFirst;
79 // Because dyamanic linking under Wasm is still experimental we default to
80 // static linking
81 bool isStatic = true;
82 bool thinLTOEmitImportsFiles;
83 bool thinLTOEmitIndexFiles;
84 bool thinLTOIndexOnly;
85 bool trace;
86 uint64_t globalBase;
87 uint64_t initialHeap;
88 uint64_t initialMemory;
89 uint64_t maxMemory;
90 bool noGrowableMemory;
91 // The table offset at which to place function addresses. We reserve zero
92 // for the null function pointer. This gets set to 1 for executables and 0
93 // for shared libraries (since they always added to a dynamic offset at
94 // runtime).
95 uint64_t tableBase;
96 uint64_t zStackSize;
97 unsigned ltoPartitions;
98 unsigned ltoo;
99 llvm::CodeGenOptLevel ltoCgo;
100 unsigned optimize;
101 bool ltoDebugPassManager;
102 UnresolvedPolicy unresolvedSymbols;
103 BuildIdKind buildId = BuildIdKind::None;
105 llvm::StringRef entry;
106 llvm::StringRef ltoObjPath;
107 llvm::StringRef mapFile;
108 llvm::StringRef outputFile;
109 llvm::StringRef soName;
110 llvm::StringRef thinLTOCacheDir;
111 llvm::StringRef thinLTOJobs;
112 llvm::StringRef thinLTOIndexOnlyArg;
113 std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
114 llvm::StringRef thinLTOPrefixReplaceOld;
115 llvm::StringRef thinLTOPrefixReplaceNew;
116 llvm::StringRef thinLTOPrefixReplaceNativeObject;
117 llvm::StringRef whyExtract;
119 llvm::StringSet<> allowUndefinedSymbols;
120 llvm::StringSet<> exportedSymbols;
121 std::vector<llvm::StringRef> requiredExports;
122 llvm::SmallVector<llvm::StringRef, 0> searchPaths;
123 llvm::CachePruningPolicy thinLTOCachePolicy;
124 std::optional<std::vector<std::string>> features;
125 std::optional<std::vector<std::string>> extraFeatures;
126 llvm::SmallVector<uint8_t, 0> buildIdVector;
129 // The only instance of Configuration struct.
130 extern Configuration *config;
132 // The Ctx object hold all other (non-configuration) global state.
133 struct Ctx {
134 llvm::SmallVector<ObjFile *, 0> objectFiles;
135 llvm::SmallVector<StubFile *, 0> stubFiles;
136 llvm::SmallVector<SharedFile *, 0> sharedFiles;
137 llvm::SmallVector<BitcodeFile *, 0> bitcodeFiles;
138 llvm::SmallVector<BitcodeFile *, 0> lazyBitcodeFiles;
139 llvm::SmallVector<InputFunction *, 0> syntheticFunctions;
140 llvm::SmallVector<InputGlobal *, 0> syntheticGlobals;
141 llvm::SmallVector<InputTable *, 0> syntheticTables;
143 // True if we are creating position-independent code.
144 bool isPic = false;
146 // True if we have an MVP input that uses __indirect_function_table and which
147 // requires it to be allocated to table number 0.
148 bool legacyFunctionTable = false;
150 // Will be set to true if bss data segments should be emitted. In most cases
151 // this is not necessary.
152 bool emitBssSegments = false;
154 // A tuple of (reference, extractedFile, sym). Used by --why-extract=.
155 llvm::SmallVector<std::tuple<std::string, const InputFile *, const Symbol &>,
157 whyExtractRecords;
159 void reset();
162 extern Ctx ctx;
164 void errorOrWarn(const llvm::Twine &msg);
166 } // namespace lld::wasm
168 #endif