1ece8a530Spatrick //===- Config.h -------------------------------------------------*- C++ -*-===// 2ece8a530Spatrick // 3ece8a530Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4ece8a530Spatrick // See https://llvm.org/LICENSE.txt for license information. 5ece8a530Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6ece8a530Spatrick // 7ece8a530Spatrick //===----------------------------------------------------------------------===// 8ece8a530Spatrick 9ece8a530Spatrick #ifndef LLD_WASM_CONFIG_H 10ece8a530Spatrick #define LLD_WASM_CONFIG_H 11ece8a530Spatrick 12*dfe94b16Srobert #include "llvm/ADT/SmallVector.h" 13ece8a530Spatrick #include "llvm/ADT/StringRef.h" 14ece8a530Spatrick #include "llvm/ADT/StringSet.h" 15ece8a530Spatrick #include "llvm/BinaryFormat/Wasm.h" 16ece8a530Spatrick #include "llvm/Support/CachePruning.h" 17*dfe94b16Srobert #include <optional> 18ece8a530Spatrick 19ece8a530Spatrick namespace lld { 20ece8a530Spatrick namespace wasm { 21ece8a530Spatrick 22*dfe94b16Srobert class InputFile; 23*dfe94b16Srobert class Symbol; 24*dfe94b16Srobert 251cf9926bSpatrick // For --unresolved-symbols. 26*dfe94b16Srobert enum class UnresolvedPolicy { ReportError, Warn, Ignore, ImportDynamic }; 271cf9926bSpatrick 28ece8a530Spatrick // This struct contains the global configuration for the linker. 29ece8a530Spatrick // Most fields are direct mapping from the command line options 30ece8a530Spatrick // and such fields have the same name as the corresponding options. 31ece8a530Spatrick // Most fields are initialized by the driver. 32ece8a530Spatrick struct Configuration { 331cf9926bSpatrick bool bsymbolic; 34ece8a530Spatrick bool checkFeatures; 35ece8a530Spatrick bool compressRelocations; 36ece8a530Spatrick bool demangle; 37ece8a530Spatrick bool disableVerify; 38bb684c34Spatrick bool experimentalPic; 39ece8a530Spatrick bool emitRelocs; 40ece8a530Spatrick bool exportAll; 41ece8a530Spatrick bool exportDynamic; 42ece8a530Spatrick bool exportTable; 43*dfe94b16Srobert bool extendedConst; 44ece8a530Spatrick bool growableTable; 45ece8a530Spatrick bool gcSections; 46*dfe94b16Srobert std::optional<std::pair<llvm::StringRef, llvm::StringRef>> memoryImport; 47*dfe94b16Srobert std::optional<llvm::StringRef> memoryExport; 48ece8a530Spatrick bool sharedMemory; 49ece8a530Spatrick bool importTable; 501cf9926bSpatrick bool importUndefined; 51*dfe94b16Srobert std::optional<bool> is64; 52ece8a530Spatrick bool mergeDataSegments; 53ece8a530Spatrick bool pie; 54ece8a530Spatrick bool printGcSections; 55ece8a530Spatrick bool relocatable; 56ece8a530Spatrick bool saveTemps; 57ece8a530Spatrick bool shared; 58ece8a530Spatrick bool stripAll; 59ece8a530Spatrick bool stripDebug; 60ece8a530Spatrick bool stackFirst; 61*dfe94b16Srobert bool isStatic = false; 62ece8a530Spatrick bool trace; 63bb684c34Spatrick uint64_t globalBase; 64bb684c34Spatrick uint64_t initialMemory; 65bb684c34Spatrick uint64_t maxMemory; 66bb684c34Spatrick uint64_t zStackSize; 67ece8a530Spatrick unsigned ltoPartitions; 68ece8a530Spatrick unsigned ltoo; 69ece8a530Spatrick unsigned optimize; 70bb684c34Spatrick llvm::StringRef thinLTOJobs; 711cf9926bSpatrick bool ltoDebugPassManager; 721cf9926bSpatrick UnresolvedPolicy unresolvedSymbols; 73ece8a530Spatrick 74ece8a530Spatrick llvm::StringRef entry; 751cf9926bSpatrick llvm::StringRef mapFile; 76ece8a530Spatrick llvm::StringRef outputFile; 77ece8a530Spatrick llvm::StringRef thinLTOCacheDir; 78*dfe94b16Srobert llvm::StringRef whyExtract; 79ece8a530Spatrick 80ece8a530Spatrick llvm::StringSet<> allowUndefinedSymbols; 81ece8a530Spatrick llvm::StringSet<> exportedSymbols; 821cf9926bSpatrick std::vector<llvm::StringRef> requiredExports; 83*dfe94b16Srobert llvm::SmallVector<llvm::StringRef, 0> searchPaths; 84ece8a530Spatrick llvm::CachePruningPolicy thinLTOCachePolicy; 85*dfe94b16Srobert std::optional<std::vector<std::string>> features; 86*dfe94b16Srobert std::optional<std::vector<std::string>> extraFeatures; 87ece8a530Spatrick 88ece8a530Spatrick // The following config options do not directly correspond to any 89*dfe94b16Srobert // particular command line options, and should probably be moved to seperate 90*dfe94b16Srobert // Ctx struct as in ELF/Config.h 91ece8a530Spatrick 92ece8a530Spatrick // True if we are creating position-independent code. 93ece8a530Spatrick bool isPic; 94ece8a530Spatrick 951cf9926bSpatrick // True if we have an MVP input that uses __indirect_function_table and which 961cf9926bSpatrick // requires it to be allocated to table number 0. 971cf9926bSpatrick bool legacyFunctionTable = false; 981cf9926bSpatrick 99ece8a530Spatrick // The table offset at which to place function addresses. We reserve zero 100ece8a530Spatrick // for the null function pointer. This gets set to 1 for executables and 0 101ece8a530Spatrick // for shared libraries (since they always added to a dynamic offset at 102ece8a530Spatrick // runtime). 103ece8a530Spatrick uint32_t tableBase = 0; 104*dfe94b16Srobert 105*dfe94b16Srobert // Will be set to true if bss data segments should be emitted. In most cases 106*dfe94b16Srobert // this is not necessary. 107*dfe94b16Srobert bool emitBssSegments = false; 108*dfe94b16Srobert 109*dfe94b16Srobert // A tuple of (reference, extractedFile, sym). Used by --why-extract=. 110*dfe94b16Srobert llvm::SmallVector<std::tuple<std::string, const InputFile *, const Symbol &>, 111*dfe94b16Srobert 0> 112*dfe94b16Srobert whyExtractRecords; 113ece8a530Spatrick }; 114ece8a530Spatrick 115ece8a530Spatrick // The only instance of Configuration struct. 116ece8a530Spatrick extern Configuration *config; 117ece8a530Spatrick 118ece8a530Spatrick } // namespace wasm 119ece8a530Spatrick } // namespace lld 120ece8a530Spatrick 121ece8a530Spatrick #endif 122