[lld] [wasm-ld] Refactor WasmSym from static globals to per-link context (PR #134970)

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 9 10:55:12 PDT 2025


================
@@ -541,103 +541,103 @@ class LazySymbol : public Symbol {
 struct WasmSym {
   // __global_base
   // Symbol marking the start of the global section.
-  static DefinedData *globalBase;
+  DefinedData *globalBase = nullptr;
 
   // __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
-  static GlobalSymbol *stackPointer;
-  static DefinedData *stackLow;
-  static DefinedData *stackHigh;
+  GlobalSymbol *stackPointer = nullptr;
+  DefinedData *stackLow = nullptr;
+  DefinedData *stackHigh = nullptr;
 
   // __tls_base
   // Global that holds the address of the base of the current thread's
   // TLS block.
-  static GlobalSymbol *tlsBase;
+  GlobalSymbol *tlsBase = nullptr;
 
   // __tls_size
   // Symbol whose value is the size of the TLS block.
-  static GlobalSymbol *tlsSize;
+  GlobalSymbol *tlsSize = nullptr;
 
   // __tls_size
   // Symbol whose value is the alignment of the TLS block.
-  static GlobalSymbol *tlsAlign;
+  GlobalSymbol *tlsAlign = nullptr;
 
   // __data_end
   // Symbol marking the end of the data and bss.
-  static DefinedData *dataEnd;
+  DefinedData *dataEnd = nullptr;
 
   // __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.
-  static DefinedData *heapBase;
-  static DefinedData *heapEnd;
+  DefinedData *heapBase = nullptr;
+  DefinedData *heapEnd = nullptr;
 
   // __wasm_first_page_end
   // A symbol whose address is the end of the first page in memory (if any).
-  static DefinedData *firstPageEnd;
+  DefinedData *firstPageEnd = nullptr;
 
   // __wasm_init_memory_flag
   // Symbol whose contents are nonzero iff memory has already been initialized.
-  static DefinedData *initMemoryFlag;
+  DefinedData *initMemoryFlag = nullptr;
 
   // __wasm_init_memory
   // Function that initializes passive data segments during instantiation.
-  static DefinedFunction *initMemory;
+  DefinedFunction *initMemory = nullptr;
 
   // __wasm_call_ctors
   // Function that directly calls all ctors in priority order.
-  static DefinedFunction *callCtors;
+  DefinedFunction *callCtors = nullptr;
 
   // __wasm_call_dtors
   // Function that calls the libc/etc. cleanup function.
-  static DefinedFunction *callDtors;
+  DefinedFunction *callDtors = nullptr;
 
   // __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.
-  static DefinedFunction *applyGlobalRelocs;
+  DefinedFunction *applyGlobalRelocs = nullptr;
 
   // __wasm_apply_tls_relocs
   // Like __wasm_apply_data_relocs but for TLS section.  These must be
   // delayed until __wasm_init_tls.
-  static DefinedFunction *applyTLSRelocs;
+  DefinedFunction *applyTLSRelocs = nullptr;
 
   // __wasm_apply_global_tls_relocs
   // Like applyGlobalRelocs but for globals that hold TLS addresses.  These
   // must be delayed until __wasm_init_tls.
-  static DefinedFunction *applyGlobalTLSRelocs;
+  DefinedFunction *applyGlobalTLSRelocs = nullptr;
 
   // __wasm_init_tls
   // Function that allocates thread-local storage and initializes it.
-  static DefinedFunction *initTLS;
+  DefinedFunction *initTLS = nullptr;
 
   // Pointer to the function that is to be used in the start section.
   // (normally an alias of initMemory, or applyGlobalRelocs).
-  static DefinedFunction *startFunction;
+  DefinedFunction *startFunction = nullptr;
 
   // __dso_handle
   // Symbol used in calls to __cxa_atexit to determine current DLL
-  static DefinedData *dsoHandle;
+  DefinedData *dsoHandle = nullptr;
 
   // __table_base
   // Used in PIC code for offset of indirect function table
-  static UndefinedGlobal *tableBase;
-  static DefinedData *definedTableBase;
+  UndefinedGlobal *tableBase = nullptr;
+  DefinedData *definedTableBase = nullptr;
 
   // __memory_base
   // Used in PIC code for offset of global data
-  static UndefinedGlobal *memoryBase;
-  static DefinedData *definedMemoryBase;
+  UndefinedGlobal *memoryBase = nullptr;
+  DefinedData *definedMemoryBase = nullptr;
 
   // __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.
-  static TableSymbol *indirectFunctionTable;
+  TableSymbol *indirectFunctionTable = nullptr;
----------------
sbc100 wrote:

The ELF linker does use `= nullptr` for these, but it does `ElfSym sym{};` which I guess handles the zero init.    Lets the same there.

https://github.com/llvm/llvm-project/pull/134970


More information about the llvm-commits mailing list