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
;
28 // For --unresolved-symbols.
29 enum class UnresolvedPolicy
{ ReportError
, Warn
, Ignore
, ImportDynamic
};
32 enum class BuildIdKind
{ None
, Fast
, Sha1
, Hexstring
, Uuid
};
34 // This struct contains the global configuration for the linker.
35 // Most fields are direct mapping from the command line options
36 // and such fields have the same name as the corresponding options.
37 // Most fields are initialized by the driver.
38 struct Configuration
{
41 bool compressRelocations
;
52 std::optional
<std::pair
<llvm::StringRef
, llvm::StringRef
>> memoryImport
;
53 std::optional
<llvm::StringRef
> memoryExport
;
57 std::optional
<bool> is64
;
58 bool mergeDataSegments
;
67 bool isStatic
= false;
70 uint64_t initialMemory
;
73 unsigned ltoPartitions
;
75 llvm::CodeGenOptLevel ltoCgo
;
77 llvm::StringRef thinLTOJobs
;
78 bool ltoDebugPassManager
;
79 UnresolvedPolicy unresolvedSymbols
;
80 BuildIdKind buildId
= BuildIdKind::None
;
82 llvm::StringRef entry
;
83 llvm::StringRef mapFile
;
84 llvm::StringRef outputFile
;
85 llvm::StringRef soName
;
86 llvm::StringRef thinLTOCacheDir
;
87 llvm::StringRef whyExtract
;
89 llvm::StringSet
<> allowUndefinedSymbols
;
90 llvm::StringSet
<> exportedSymbols
;
91 std::vector
<llvm::StringRef
> requiredExports
;
92 llvm::SmallVector
<llvm::StringRef
, 0> searchPaths
;
93 llvm::CachePruningPolicy thinLTOCachePolicy
;
94 std::optional
<std::vector
<std::string
>> features
;
95 std::optional
<std::vector
<std::string
>> extraFeatures
;
96 llvm::SmallVector
<uint8_t, 0> buildIdVector
;
98 // The following config options do not directly correspond to any
99 // particular command line options, and should probably be moved to separate
100 // Ctx struct as in ELF/Config.h
102 // True if we are creating position-independent code.
105 // True if we have an MVP input that uses __indirect_function_table and which
106 // requires it to be allocated to table number 0.
107 bool legacyFunctionTable
= false;
109 // The table offset at which to place function addresses. We reserve zero
110 // for the null function pointer. This gets set to 1 for executables and 0
111 // for shared libraries (since they always added to a dynamic offset at
113 uint32_t tableBase
= 0;
115 // Will be set to true if bss data segments should be emitted. In most cases
116 // this is not necessary.
117 bool emitBssSegments
= false;
119 // A tuple of (reference, extractedFile, sym). Used by --why-extract=.
120 llvm::SmallVector
<std::tuple
<std::string
, const InputFile
*, const Symbol
&>,
125 // The only instance of Configuration struct.
126 extern Configuration
*config
;
128 } // namespace lld::wasm