Skip to content

Commit c4f8021

Browse files
committed
Replicate framework as per elf
1 parent 6deb848 commit c4f8021

File tree

2 files changed

+109
-106
lines changed

2 files changed

+109
-106
lines changed

lld/wasm/Config.h

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ class InputTable;
3232
class InputGlobal;
3333
class InputFunction;
3434
class Symbol;
35-
struct WasmSym;
35+
class DefinedData;
36+
class GlobalSymbol;
37+
class DefinedFunction;
38+
class UndefinedGlobal;
39+
class TableSymbol;
3640

3741
// For --unresolved-symbols.
3842
enum class UnresolvedPolicy { ReportError, Warn, Ignore, ImportDynamic };
@@ -142,8 +146,110 @@ struct Ctx {
142146
llvm::SmallVector<InputGlobal *, 0> syntheticGlobals;
143147
llvm::SmallVector<InputTable *, 0> syntheticTables;
144148

145-
// Linker-generated symbols like __wasm_init_memory, __heap_base, etc.
146-
WasmSym sym{};
149+
// linker-generated symbols
150+
struct WasmSym {
151+
// __global_base
152+
// Symbol marking the start of the global section.
153+
DefinedData *globalBase;
154+
155+
// __stack_pointer/__stack_low/__stack_high
156+
// Global that holds current value of stack pointer and data symbols marking
157+
// the start and end of the stack region. stackPointer is initialized to
158+
// stackHigh and grows downwards towards stackLow
159+
GlobalSymbol *stackPointer;
160+
DefinedData *stackLow;
161+
DefinedData *stackHigh;
162+
163+
// __tls_base
164+
// Global that holds the address of the base of the current thread's
165+
// TLS block.
166+
GlobalSymbol *tlsBase;
167+
168+
// __tls_size
169+
// Symbol whose value is the size of the TLS block.
170+
GlobalSymbol *tlsSize;
171+
172+
// __tls_size
173+
// Symbol whose value is the alignment of the TLS block.
174+
GlobalSymbol *tlsAlign;
175+
176+
// __data_end
177+
// Symbol marking the end of the data and bss.
178+
DefinedData *dataEnd;
179+
180+
// __heap_base/__heap_end
181+
// Symbols marking the beginning and end of the "heap". It starts at the end
182+
// of the data, bss and explicit stack, and extends to the end of the linear
183+
// memory allocated by wasm-ld. This region of memory is not used by the
184+
// linked code, so it may be used as a backing store for `sbrk` or `malloc`
185+
// implementations.
186+
DefinedData *heapBase;
187+
DefinedData *heapEnd;
188+
189+
// __wasm_first_page_end
190+
// A symbol whose address is the end of the first page in memory (if any).
191+
DefinedData *firstPageEnd;
192+
193+
// __wasm_init_memory_flag
194+
// Symbol whose contents are nonzero iff memory has already been
195+
// initialized.
196+
DefinedData *initMemoryFlag;
197+
198+
// __wasm_init_memory
199+
// Function that initializes passive data segments during instantiation.
200+
DefinedFunction *initMemory;
201+
202+
// __wasm_call_ctors
203+
// Function that directly calls all ctors in priority order.
204+
DefinedFunction *callCtors;
205+
206+
// __wasm_call_dtors
207+
// Function that calls the libc/etc. cleanup function.
208+
DefinedFunction *callDtors;
209+
210+
// __wasm_apply_global_relocs
211+
// Function that applies relocations to wasm globals post-instantiation.
212+
// Unlike __wasm_apply_data_relocs this needs to run on every thread.
213+
DefinedFunction *applyGlobalRelocs;
214+
215+
// __wasm_apply_tls_relocs
216+
// Like __wasm_apply_data_relocs but for TLS section. These must be
217+
// delayed until __wasm_init_tls.
218+
DefinedFunction *applyTLSRelocs;
219+
220+
// __wasm_apply_global_tls_relocs
221+
// Like applyGlobalRelocs but for globals that hold TLS addresses. These
222+
// must be delayed until __wasm_init_tls.
223+
DefinedFunction *applyGlobalTLSRelocs;
224+
225+
// __wasm_init_tls
226+
// Function that allocates thread-local storage and initializes it.
227+
DefinedFunction *initTLS;
228+
229+
// Pointer to the function that is to be used in the start section.
230+
// (normally an alias of initMemory, or applyGlobalRelocs).
231+
DefinedFunction *startFunction;
232+
233+
// __dso_handle
234+
// Symbol used in calls to __cxa_atexit to determine current DLL
235+
DefinedData *dsoHandle;
236+
237+
// __table_base
238+
// Used in PIC code for offset of indirect function table
239+
UndefinedGlobal *tableBase;
240+
DefinedData *definedTableBase;
241+
242+
// __memory_base
243+
// Used in PIC code for offset of global data
244+
UndefinedGlobal *memoryBase;
245+
DefinedData *definedMemoryBase;
246+
247+
// __indirect_function_table
248+
// Used as an address space for function pointers, with each function that
249+
// is used as a function pointer being allocated a slot.
250+
TableSymbol *indirectFunctionTable;
251+
};
252+
WasmSym sym;
147253

148254
// True if we are creating position-independent code.
149255
bool isPic = false;

lld/wasm/Symbols.h

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -537,109 +537,6 @@ class LazySymbol : public Symbol {
537537
const WasmSignature *signature = nullptr;
538538
};
539539

540-
// linker-generated symbols
541-
struct WasmSym {
542-
// __global_base
543-
// Symbol marking the start of the global section.
544-
DefinedData *globalBase;
545-
546-
// __stack_pointer/__stack_low/__stack_high
547-
// Global that holds current value of stack pointer and data symbols marking
548-
// the start and end of the stack region. stackPointer is initialized to
549-
// stackHigh and grows downwards towards stackLow
550-
GlobalSymbol *stackPointer;
551-
DefinedData *stackLow;
552-
DefinedData *stackHigh;
553-
554-
// __tls_base
555-
// Global that holds the address of the base of the current thread's
556-
// TLS block.
557-
GlobalSymbol *tlsBase;
558-
559-
// __tls_size
560-
// Symbol whose value is the size of the TLS block.
561-
GlobalSymbol *tlsSize;
562-
563-
// __tls_size
564-
// Symbol whose value is the alignment of the TLS block.
565-
GlobalSymbol *tlsAlign;
566-
567-
// __data_end
568-
// Symbol marking the end of the data and bss.
569-
DefinedData *dataEnd;
570-
571-
// __heap_base/__heap_end
572-
// Symbols marking the beginning and end of the "heap". It starts at the end
573-
// of the data, bss and explicit stack, and extends to the end of the linear
574-
// memory allocated by wasm-ld. This region of memory is not used by the
575-
// linked code, so it may be used as a backing store for `sbrk` or `malloc`
576-
// implementations.
577-
DefinedData *heapBase;
578-
DefinedData *heapEnd;
579-
580-
// __wasm_first_page_end
581-
// A symbol whose address is the end of the first page in memory (if any).
582-
DefinedData *firstPageEnd;
583-
584-
// __wasm_init_memory_flag
585-
// Symbol whose contents are nonzero iff memory has already been initialized.
586-
DefinedData *initMemoryFlag;
587-
588-
// __wasm_init_memory
589-
// Function that initializes passive data segments during instantiation.
590-
DefinedFunction *initMemory;
591-
592-
// __wasm_call_ctors
593-
// Function that directly calls all ctors in priority order.
594-
DefinedFunction *callCtors;
595-
596-
// __wasm_call_dtors
597-
// Function that calls the libc/etc. cleanup function.
598-
DefinedFunction *callDtors;
599-
600-
// __wasm_apply_global_relocs
601-
// Function that applies relocations to wasm globals post-instantiation.
602-
// Unlike __wasm_apply_data_relocs this needs to run on every thread.
603-
DefinedFunction *applyGlobalRelocs;
604-
605-
// __wasm_apply_tls_relocs
606-
// Like __wasm_apply_data_relocs but for TLS section. These must be
607-
// delayed until __wasm_init_tls.
608-
DefinedFunction *applyTLSRelocs;
609-
610-
// __wasm_apply_global_tls_relocs
611-
// Like applyGlobalRelocs but for globals that hold TLS addresses. These
612-
// must be delayed until __wasm_init_tls.
613-
DefinedFunction *applyGlobalTLSRelocs;
614-
615-
// __wasm_init_tls
616-
// Function that allocates thread-local storage and initializes it.
617-
DefinedFunction *initTLS;
618-
619-
// Pointer to the function that is to be used in the start section.
620-
// (normally an alias of initMemory, or applyGlobalRelocs).
621-
DefinedFunction *startFunction;
622-
623-
// __dso_handle
624-
// Symbol used in calls to __cxa_atexit to determine current DLL
625-
DefinedData *dsoHandle;
626-
627-
// __table_base
628-
// Used in PIC code for offset of indirect function table
629-
UndefinedGlobal *tableBase;
630-
DefinedData *definedTableBase;
631-
632-
// __memory_base
633-
// Used in PIC code for offset of global data
634-
UndefinedGlobal *memoryBase;
635-
DefinedData *definedMemoryBase;
636-
637-
// __indirect_function_table
638-
// Used as an address space for function pointers, with each function that is
639-
// used as a function pointer being allocated a slot.
640-
TableSymbol *indirectFunctionTable;
641-
};
642-
643540
// A buffer class that is large enough to hold any Symbol-derived
644541
// object. We allocate memory using this class and instantiate a symbol
645542
// using the placement new.

0 commit comments

Comments
 (0)