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

source code of lld/wasm/Config.h