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/ADT/Twine.h" 16 #include "llvm/BinaryFormat/Wasm.h" 17 #include "llvm/Support/CachePruning.h" 18 #include <optional> 19 20 namespace llvm { 21 enum class CodeGenOptLevel; 22 } // namespace llvm 23 24 namespace lld::wasm { 25 26 class InputFile; 27 class StubFile; 28 class ObjFile; 29 class SharedFile; 30 class BitcodeFile; 31 class InputTable; 32 class InputGlobal; 33 class InputFunction; 34 class Symbol; 35 36 // For --unresolved-symbols. 37 enum class UnresolvedPolicy { ReportError, Warn, Ignore, ImportDynamic }; 38 39 // For --build-id. 40 enum class BuildIdKind { None, Fast, Sha1, Hexstring, Uuid }; 41 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 Config { 47 bool allowMultipleDefinition; 48 bool bsymbolic; 49 bool checkFeatures; 50 bool compressRelocations; 51 bool demangle; 52 bool disableVerify; 53 bool experimentalPic; 54 bool emitRelocs; 55 bool exportAll; 56 bool exportDynamic; 57 bool exportTable; 58 bool extendedConst; 59 bool growableTable; 60 bool gcSections; 61 llvm::StringSet<> keepSections; 62 std::optional<std::pair<llvm::StringRef, llvm::StringRef>> memoryImport; 63 std::optional<llvm::StringRef> memoryExport; 64 bool sharedMemory; 65 bool importTable; 66 bool importUndefined; 67 std::optional<bool> is64; 68 bool mergeDataSegments; 69 bool noinhibitExec; 70 bool pie; 71 bool printGcSections; 72 bool relocatable; 73 bool saveTemps; 74 bool shared; 75 bool shlibSigCheck; 76 bool stripAll; 77 bool stripDebug; 78 bool stackFirst; 79 // Because dyamanic linking under Wasm is still experimental we default to 80 // static linking 81 bool isStatic = true; 82 bool thinLTOEmitImportsFiles; 83 bool thinLTOEmitIndexFiles; 84 bool thinLTOIndexOnly; 85 bool trace; 86 uint64_t globalBase; 87 uint64_t initialHeap; 88 uint64_t initialMemory; 89 uint64_t maxMemory; 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 94 // runtime). 95 uint64_t tableBase; 96 uint64_t zStackSize; 97 unsigned ltoPartitions; 98 unsigned ltoo; 99 llvm::CodeGenOptLevel ltoCgo; 100 unsigned optimize; 101 bool ltoDebugPassManager; 102 UnresolvedPolicy unresolvedSymbols; 103 BuildIdKind buildId = BuildIdKind::None; 104 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; 118 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; 127 }; 128 129 // The Ctx object hold all other (non-configuration) global state. 130 struct Ctx { 131 Config arg; 132 133 llvm::SmallVector<ObjFile *, 0> objectFiles; 134 llvm::SmallVector<StubFile *, 0> stubFiles; 135 llvm::SmallVector<SharedFile *, 0> sharedFiles; 136 llvm::SmallVector<BitcodeFile *, 0> bitcodeFiles; 137 llvm::SmallVector<BitcodeFile *, 0> lazyBitcodeFiles; 138 llvm::SmallVector<InputFunction *, 0> syntheticFunctions; 139 llvm::SmallVector<InputGlobal *, 0> syntheticGlobals; 140 llvm::SmallVector<InputTable *, 0> syntheticTables; 141 142 // True if we are creating position-independent code. 143 bool isPic = false; 144 145 // True if we have an MVP input that uses __indirect_function_table and which 146 // requires it to be allocated to table number 0. 147 bool legacyFunctionTable = false; 148 149 // Will be set to true if bss data segments should be emitted. In most cases 150 // this is not necessary. 151 bool emitBssSegments = false; 152 153 // A tuple of (reference, extractedFile, sym). Used by --why-extract=. 154 llvm::SmallVector<std::tuple<std::string, const InputFile *, const Symbol &>, 155 0> 156 whyExtractRecords; 157 158 Ctx(); 159 void reset(); 160 }; 161 162 extern Ctx ctx; 163 164 void errorOrWarn(const llvm::Twine &msg); 165 166 } // namespace lld::wasm 167 168 #endif 169