xref: /llvm-project-15.0.7/lld/wasm/Config.h (revision b8f50abd)
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/StringRef.h"
13 #include "llvm/ADT/StringSet.h"
14 #include "llvm/BinaryFormat/Wasm.h"
15 #include "llvm/Support/CachePruning.h"
16 
17 namespace lld {
18 namespace wasm {
19 
20 // For --unresolved-symbols.
21 enum class UnresolvedPolicy { ReportError, Warn, Ignore, ImportDynamic };
22 
23 // This struct contains the global configuration for the linker.
24 // Most fields are direct mapping from the command line options
25 // and such fields have the same name as the corresponding options.
26 // Most fields are initialized by the driver.
27 struct Configuration {
28   bool bsymbolic;
29   bool checkFeatures;
30   bool compressRelocations;
31   bool demangle;
32   bool disableVerify;
33   bool experimentalPic;
34   bool emitRelocs;
35   bool exportAll;
36   bool exportDynamic;
37   bool exportTable;
38   bool extendedConst;
39   bool growableTable;
40   bool gcSections;
41   bool importMemory;
42   bool sharedMemory;
43   bool importTable;
44   bool importUndefined;
45   llvm::Optional<bool> is64;
46   bool mergeDataSegments;
47   bool pie;
48   bool printGcSections;
49   bool relocatable;
50   bool saveTemps;
51   bool shared;
52   bool stripAll;
53   bool stripDebug;
54   bool stackFirst;
55   bool trace;
56   uint64_t globalBase;
57   uint64_t initialMemory;
58   uint64_t maxMemory;
59   uint64_t zStackSize;
60   unsigned ltoPartitions;
61   unsigned ltoo;
62   unsigned optimize;
63   llvm::StringRef thinLTOJobs;
64   bool ltoDebugPassManager;
65   UnresolvedPolicy unresolvedSymbols;
66 
67   llvm::StringRef entry;
68   llvm::StringRef mapFile;
69   llvm::StringRef outputFile;
70   llvm::StringRef thinLTOCacheDir;
71 
72   llvm::StringSet<> allowUndefinedSymbols;
73   llvm::StringSet<> exportedSymbols;
74   std::vector<llvm::StringRef> requiredExports;
75   std::vector<llvm::StringRef> searchPaths;
76   llvm::CachePruningPolicy thinLTOCachePolicy;
77   llvm::Optional<std::vector<std::string>> features;
78 
79   // The following config options do not directly correspond to any
80   // particular command line options.
81 
82   // True if we are creating position-independent code.
83   bool isPic;
84 
85   // True if we have an MVP input that uses __indirect_function_table and which
86   // requires it to be allocated to table number 0.
87   bool legacyFunctionTable = false;
88 
89   // The table offset at which to place function addresses.  We reserve zero
90   // for the null function pointer.  This gets set to 1 for executables and 0
91   // for shared libraries (since they always added to a dynamic offset at
92   // runtime).
93   uint32_t tableBase = 0;
94 
95   // Will be set to true if bss data segments should be emitted. In most cases
96   // this is not necessary.
97   bool emitBssSegments = false;
98 };
99 
100 // The only instance of Configuration struct.
101 extern Configuration *config;
102 
103 } // namespace wasm
104 } // namespace lld
105 
106 #endif
107