1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
//===- Config.h -------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_WASM_CONFIG_H
#define LLD_WASM_CONFIG_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/Support/CachePruning.h"
#include <optional>
namespace llvm {
enum class CodeGenOptLevel;
} // namespace llvm
namespace lld::wasm {
class InputFile;
class StubFile;
class ObjFile;
class SharedFile;
class BitcodeFile;
class InputTable;
class InputGlobal;
class InputFunction;
class Symbol;
class DefinedData;
class GlobalSymbol;
class DefinedFunction;
class UndefinedGlobal;
class TableSymbol;
// For --unresolved-symbols.
enum class UnresolvedPolicy { ReportError, Warn, Ignore, ImportDynamic };
// For --build-id.
enum class BuildIdKind { None, Fast, Sha1, Hexstring, Uuid };
// This struct contains the global configuration for the linker.
// Most fields are direct mapping from the command line options
// and such fields have the same name as the corresponding options.
// Most fields are initialized by the driver.
struct Config {
bool allowMultipleDefinition;
bool bsymbolic;
bool checkFeatures;
bool compressRelocations;
bool demangle;
bool disableVerify;
bool experimentalPic;
bool emitRelocs;
bool exportAll;
bool exportDynamic;
bool exportTable;
bool extendedConst;
bool growableTable;
bool gcSections;
llvm::StringSet<> keepSections;
std::optional<std::pair<llvm::StringRef, llvm::StringRef>> memoryImport;
std::optional<llvm::StringRef> memoryExport;
bool sharedMemory;
bool importTable;
bool importUndefined;
std::optional<bool> is64;
bool mergeDataSegments;
bool noinhibitExec;
bool pie;
bool printGcSections;
bool relocatable;
bool saveTemps;
bool shared;
bool shlibSigCheck;
bool stripAll;
bool stripDebug;
bool stackFirst;
// Because dyamanic linking under Wasm is still experimental we default to
// static linking
bool isStatic = true;
bool thinLTOEmitImportsFiles;
bool thinLTOEmitIndexFiles;
bool thinLTOIndexOnly;
bool trace;
uint64_t globalBase;
uint64_t initialHeap;
uint64_t initialMemory;
uint64_t maxMemory;
bool noGrowableMemory;
// The table offset at which to place function addresses. We reserve zero
// for the null function pointer. This gets set to 1 for executables and 0
// for shared libraries (since they always added to a dynamic offset at
// runtime).
uint64_t tableBase;
uint64_t zStackSize;
unsigned ltoPartitions;
unsigned ltoo;
llvm::CodeGenOptLevel ltoCgo;
unsigned optimize;
bool ltoDebugPassManager;
UnresolvedPolicy unresolvedSymbols;
BuildIdKind buildId = BuildIdKind::None;
llvm::StringRef entry;
llvm::StringRef ltoObjPath;
llvm::StringRef mapFile;
llvm::StringRef outputFile;
llvm::StringRef soName;
llvm::StringRef thinLTOCacheDir;
llvm::StringRef thinLTOJobs;
llvm::StringRef thinLTOIndexOnlyArg;
std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
llvm::StringRef thinLTOPrefixReplaceOld;
llvm::StringRef thinLTOPrefixReplaceNew;
llvm::StringRef thinLTOPrefixReplaceNativeObject;
llvm::StringRef whyExtract;
llvm::StringSet<> allowUndefinedSymbols;
llvm::StringSet<> exportedSymbols;
std::vector<llvm::StringRef> requiredExports;
llvm::SmallVector<llvm::StringRef, 0> searchPaths;
llvm::CachePruningPolicy thinLTOCachePolicy;
std::optional<std::vector<std::string>> features;
std::optional<std::vector<std::string>> extraFeatures;
llvm::SmallVector<uint8_t, 0> buildIdVector;
};
// The Ctx object hold all other (non-configuration) global state.
struct Ctx {
Config arg;
llvm::SmallVector<ObjFile *, 0> objectFiles;
llvm::SmallVector<StubFile *, 0> stubFiles;
llvm::SmallVector<SharedFile *, 0> sharedFiles;
llvm::SmallVector<BitcodeFile *, 0> bitcodeFiles;
llvm::SmallVector<BitcodeFile *, 0> lazyBitcodeFiles;
llvm::SmallVector<InputFunction *, 0> syntheticFunctions;
llvm::SmallVector<InputGlobal *, 0> syntheticGlobals;
llvm::SmallVector<InputTable *, 0> syntheticTables;
// linker-generated symbols
struct WasmSym {
// __global_base
// Symbol marking the start of the global section.
DefinedData *globalBase;
// __stack_pointer/__stack_low/__stack_high
// Global that holds current value of stack pointer and data symbols marking
// the start and end of the stack region. stackPointer is initialized to
// stackHigh and grows downwards towards stackLow
GlobalSymbol *stackPointer;
DefinedData *stackLow;
DefinedData *stackHigh;
// __tls_base
// Global that holds the address of the base of the current thread's
// TLS block.
GlobalSymbol *tlsBase;
// __tls_size
// Symbol whose value is the size of the TLS block.
GlobalSymbol *tlsSize;
// __tls_size
// Symbol whose value is the alignment of the TLS block.
GlobalSymbol *tlsAlign;
// __data_end
// Symbol marking the end of the data and bss.
DefinedData *dataEnd;
// __heap_base/__heap_end
// Symbols marking the beginning and end of the "heap". It starts at the end
// of the data, bss and explicit stack, and extends to the end of the linear
// memory allocated by wasm-ld. This region of memory is not used by the
// linked code, so it may be used as a backing store for `sbrk` or `malloc`
// implementations.
DefinedData *heapBase;
DefinedData *heapEnd;
// __wasm_init_memory_flag
// Symbol whose contents are nonzero iff memory has already been
// initialized.
DefinedData *initMemoryFlag;
// __wasm_init_memory
// Function that initializes passive data segments during instantiation.
DefinedFunction *initMemory;
// __wasm_call_ctors
// Function that directly calls all ctors in priority order.
DefinedFunction *callCtors;
// __wasm_call_dtors
// Function that calls the libc/etc. cleanup function.
DefinedFunction *callDtors;
// __wasm_apply_global_relocs
// Function that applies relocations to wasm globals post-instantiation.
// Unlike __wasm_apply_data_relocs this needs to run on every thread.
DefinedFunction *applyGlobalRelocs;
// __wasm_apply_tls_relocs
// Like __wasm_apply_data_relocs but for TLS section. These must be
// delayed until __wasm_init_tls.
DefinedFunction *applyTLSRelocs;
// __wasm_apply_global_tls_relocs
// Like applyGlobalRelocs but for globals that hold TLS addresses. These
// must be delayed until __wasm_init_tls.
DefinedFunction *applyGlobalTLSRelocs;
// __wasm_init_tls
// Function that allocates thread-local storage and initializes it.
DefinedFunction *initTLS;
// Pointer to the function that is to be used in the start section.
// (normally an alias of initMemory, or applyGlobalRelocs).
DefinedFunction *startFunction;
// __dso_handle
// Symbol used in calls to __cxa_atexit to determine current DLL
DefinedData *dsoHandle;
// __table_base
// Used in PIC code for offset of indirect function table
UndefinedGlobal *tableBase;
DefinedData *definedTableBase;
// __memory_base
// Used in PIC code for offset of global data
UndefinedGlobal *memoryBase;
DefinedData *definedMemoryBase;
// __indirect_function_table
// Used as an address space for function pointers, with each function that
// is used as a function pointer being allocated a slot.
TableSymbol *indirectFunctionTable;
};
WasmSym sym;
// True if we are creating position-independent code.
bool isPic = false;
// True if we have an MVP input that uses __indirect_function_table and which
// requires it to be allocated to table number 0.
bool legacyFunctionTable = false;
// Will be set to true if bss data segments should be emitted. In most cases
// this is not necessary.
bool emitBssSegments = false;
// A tuple of (reference, extractedFile, sym). Used by --why-extract=.
llvm::SmallVector<std::tuple<std::string, const InputFile *, const Symbol &>,
0>
whyExtractRecords;
Ctx();
void reset();
};
extern Ctx ctx;
void errorOrWarn(const llvm::Twine &msg);
} // namespace lld::wasm
#endif
|