@@ -32,7 +32,11 @@ class InputTable;
32
32
class InputGlobal ;
33
33
class InputFunction ;
34
34
class Symbol ;
35
- struct WasmSym ;
35
+ class DefinedData ;
36
+ class GlobalSymbol ;
37
+ class DefinedFunction ;
38
+ class UndefinedGlobal ;
39
+ class TableSymbol ;
36
40
37
41
// For --unresolved-symbols.
38
42
enum class UnresolvedPolicy { ReportError, Warn, Ignore, ImportDynamic };
@@ -142,8 +146,109 @@ struct Ctx {
142
146
llvm::SmallVector<InputGlobal *, 0 > syntheticGlobals;
143
147
llvm::SmallVector<InputTable *, 0 > syntheticTables;
144
148
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 initialized.
195
+ DefinedData *initMemoryFlag;
196
+
197
+ // __wasm_init_memory
198
+ // Function that initializes passive data segments during instantiation.
199
+ DefinedFunction *initMemory;
200
+
201
+ // __wasm_call_ctors
202
+ // Function that directly calls all ctors in priority order.
203
+ DefinedFunction *callCtors;
204
+
205
+ // __wasm_call_dtors
206
+ // Function that calls the libc/etc. cleanup function.
207
+ DefinedFunction *callDtors;
208
+
209
+ // __wasm_apply_global_relocs
210
+ // Function that applies relocations to wasm globals post-instantiation.
211
+ // Unlike __wasm_apply_data_relocs this needs to run on every thread.
212
+ DefinedFunction *applyGlobalRelocs;
213
+
214
+ // __wasm_apply_tls_relocs
215
+ // Like __wasm_apply_data_relocs but for TLS section. These must be
216
+ // delayed until __wasm_init_tls.
217
+ DefinedFunction *applyTLSRelocs;
218
+
219
+ // __wasm_apply_global_tls_relocs
220
+ // Like applyGlobalRelocs but for globals that hold TLS addresses. These
221
+ // must be delayed until __wasm_init_tls.
222
+ DefinedFunction *applyGlobalTLSRelocs;
223
+
224
+ // __wasm_init_tls
225
+ // Function that allocates thread-local storage and initializes it.
226
+ DefinedFunction *initTLS;
227
+
228
+ // Pointer to the function that is to be used in the start section.
229
+ // (normally an alias of initMemory, or applyGlobalRelocs).
230
+ DefinedFunction *startFunction;
231
+
232
+ // __dso_handle
233
+ // Symbol used in calls to __cxa_atexit to determine current DLL
234
+ DefinedData *dsoHandle;
235
+
236
+ // __table_base
237
+ // Used in PIC code for offset of indirect function table
238
+ UndefinedGlobal *tableBase;
239
+ DefinedData *definedTableBase;
240
+
241
+ // __memory_base
242
+ // Used in PIC code for offset of global data
243
+ UndefinedGlobal *memoryBase;
244
+ DefinedData *definedMemoryBase;
245
+
246
+ // __indirect_function_table
247
+ // Used as an address space for function pointers, with each function that is
248
+ // used as a function pointer being allocated a slot.
249
+ TableSymbol *indirectFunctionTable;
250
+ };
251
+ WasmSym sym;
147
252
148
253
// True if we are creating position-independent code.
149
254
bool isPic = false ;
0 commit comments