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/ADT/Twine.h"
16 #include "llvm/BinaryFormat/Wasm.h"
17 #include "llvm/Support/CachePruning.h"
21 enum class CodeGenOptLevel
;
36 // For --unresolved-symbols.
37 enum class UnresolvedPolicy
{ ReportError
, Warn
, Ignore
, ImportDynamic
};
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
;
50 bool compressRelocations
;
61 llvm::StringSet
<> keepSections
;
62 std::optional
<std::pair
<llvm::StringRef
, llvm::StringRef
>> memoryImport
;
63 std::optional
<llvm::StringRef
> memoryExport
;
67 std::optional
<bool> is64
;
68 bool mergeDataSegments
;
79 // Because dyamanic linking under Wasm is still experimental we default to
82 bool thinLTOEmitImportsFiles
;
83 bool thinLTOEmitIndexFiles
;
84 bool thinLTOIndexOnly
;
88 uint64_t initialMemory
;
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
97 unsigned ltoPartitions
;
99 llvm::CodeGenOptLevel ltoCgo
;
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.
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.
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
&>,
164 void errorOrWarn(const llvm::Twine
&msg
);
166 } // namespace lld::wasm