1 //===- Config.h -------------------------------------------------*- C++ -*-===//
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
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/BinaryFormat/Wasm.h"
16 #include "llvm/Support/CachePruning.h"
20 enum class CodeGenOptLevel
;
35 // For --unresolved-symbols.
36 enum class UnresolvedPolicy
{ ReportError
, Warn
, Ignore
, ImportDynamic
};
39 enum class BuildIdKind
{ None
, Fast
, Sha1
, Hexstring
, Uuid
};
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.
45 struct Configuration
{
48 bool compressRelocations
;
59 llvm::StringSet
<> keepSections
;
60 std::optional
<std::pair
<llvm::StringRef
, llvm::StringRef
>> memoryImport
;
61 std::optional
<llvm::StringRef
> memoryExport
;
65 std::optional
<bool> is64
;
66 bool mergeDataSegments
;
76 // Because dyamanic linking under Wasm is still experimental we default to
82 uint64_t initialMemory
;
84 bool noGrowableMemory
;
85 // The table offset at which to place function addresses. We reserve zero
86 // for the null function pointer. This gets set to 1 for executables and 0
87 // for shared libraries (since they always added to a dynamic offset at
91 unsigned ltoPartitions
;
93 llvm::CodeGenOptLevel ltoCgo
;
95 llvm::StringRef thinLTOJobs
;
96 bool ltoDebugPassManager
;
97 UnresolvedPolicy unresolvedSymbols
;
98 BuildIdKind buildId
= BuildIdKind::None
;
100 llvm::StringRef entry
;
101 llvm::StringRef mapFile
;
102 llvm::StringRef outputFile
;
103 llvm::StringRef soName
;
104 llvm::StringRef thinLTOCacheDir
;
105 llvm::StringRef whyExtract
;
107 llvm::StringSet
<> allowUndefinedSymbols
;
108 llvm::StringSet
<> exportedSymbols
;
109 std::vector
<llvm::StringRef
> requiredExports
;
110 llvm::SmallVector
<llvm::StringRef
, 0> searchPaths
;
111 llvm::CachePruningPolicy thinLTOCachePolicy
;
112 std::optional
<std::vector
<std::string
>> features
;
113 std::optional
<std::vector
<std::string
>> extraFeatures
;
114 llvm::SmallVector
<uint8_t, 0> buildIdVector
;
117 // The only instance of Configuration struct.
118 extern Configuration
*config
;
120 // The Ctx object hold all other (non-configuration) global state.
122 llvm::SmallVector
<ObjFile
*, 0> objectFiles
;
123 llvm::SmallVector
<StubFile
*, 0> stubFiles
;
124 llvm::SmallVector
<SharedFile
*, 0> sharedFiles
;
125 llvm::SmallVector
<BitcodeFile
*, 0> bitcodeFiles
;
126 llvm::SmallVector
<InputFunction
*, 0> syntheticFunctions
;
127 llvm::SmallVector
<InputGlobal
*, 0> syntheticGlobals
;
128 llvm::SmallVector
<InputTable
*, 0> syntheticTables
;
130 // True if we are creating position-independent code.
133 // True if we have an MVP input that uses __indirect_function_table and which
134 // requires it to be allocated to table number 0.
135 bool legacyFunctionTable
= false;
137 // Will be set to true if bss data segments should be emitted. In most cases
138 // this is not necessary.
139 bool emitBssSegments
= false;
141 // A tuple of (reference, extractedFile, sym). Used by --why-extract=.
142 llvm::SmallVector
<std::tuple
<std::string
, const InputFile
*, const Symbol
&>,
151 } // namespace lld::wasm