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