Skip to content

Commit 416dc5c

Browse files
committed
Use emscripten_stack_set_limits in wasm_worker_initialize.S
Followup to emscripten-core#22683. This change avoids making __stack_base and __stack_end into public/external symbols and avoids reimplementing `emscripten_stack_set_limits`.
1 parent 18321c5 commit 416dc5c

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

system/lib/compiler-rt/stack_limits.S

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@
1515
#endif
1616

1717
.globaltype __stack_pointer, PTR
18-
.globl __stack_pointer
1918

2019
.section .globals,"",@
2120

2221
# TODO(sbc): It would be nice if these we initialized directly
2322
# using PTR.const rather than using the `emscripten_stack_init`
2423
.globaltype __stack_end, PTR
2524
__stack_end:
26-
.globl __stack_end
2725
.globaltype __stack_base, PTR
28-
.globl __stack_base
2926
__stack_base:
3027

3128
.section .text,"",@
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
.extern __stack_pointer
2-
.extern __stack_base
3-
.extern __stack_end
42

53
#ifdef __wasm64__
64
#define PTR i64
@@ -13,32 +11,37 @@
1311
#endif
1412

1513
.globaltype __stack_pointer, PTR
16-
.globaltype __stack_end, PTR
17-
.globaltype __stack_base, PTR
14+
.globaltype __tls_size, PTR, immutable
15+
.functype emscripten_stack_set_limits (PTR /*__stack_base*/, PTR /*__stack_base*/) -> ()
1816

1917
.globl _emscripten_wasm_worker_initialize
2018
_emscripten_wasm_worker_initialize:
2119
.functype _emscripten_wasm_worker_initialize (PTR /*stackLowestAddress*/, i32 /*stackSize*/) -> ()
20+
.local PTR, PTR
2221

23-
// __stack_end = stackLowestAddress + (__builtin_wasm_tls_size() + 15) & -16;
22+
// stack_end = stackLowestAddress + (__builtin_wasm_tls_size() + 15) & -16;
2423
local.get 0
25-
.globaltype __tls_size, PTR, immutable
2624
global.get __tls_size
2725
PTR.add
2826
PTR.const 0xf
2927
PTR.add
3028
PTR.const -0x10
3129
PTR.and
32-
global.set __stack_end
30+
local.set 2
3331

34-
// __stack_base = stackLowestAddress + stackSize;
32+
// stack_base = stackLowestAddress + stackSize;
3533
local.get 0
3634
local.get 1
3735
#ifdef __wasm64__
3836
i64.extend_i32_u
3937
#endif
4038
PTR.add
41-
global.set __stack_base
39+
local.set 3
40+
41+
local.get 3
42+
local.get 2
43+
// emscripten_stack_set_limits(stack_base, stack_end);
44+
call emscripten_stack_set_limits
4245

4346
// TODO: We'd like to do this here to avoid JS side calls to __set_stack_limits.
4447
// (or even better, we'd like to avoid duplicate versions of the stack variables)
@@ -48,6 +51,7 @@ _emscripten_wasm_worker_initialize:
4851
// .functype __set_stack_limits (PTR, PTR) -> ()
4952
// call __set_stack_limits
5053

54+
5155
// __wasm_init_tls(stackLowestAddress);
5256
local.get 0
5357
.functype __wasm_init_tls (PTR) -> ()
@@ -57,8 +61,8 @@ _emscripten_wasm_worker_initialize:
5761
// __stack_pointer initialized, and it destroys the value it was set to.
5862
// So we must initialize __stack_pointer only *after* completing __wasm_init_tls:
5963

60-
// __stack_pointer = __stack_base;
61-
global.get __stack_base
64+
// __stack_pointer = stack_base;
65+
local.get 3
6266
global.set __stack_pointer
6367

6468
end_function

0 commit comments

Comments
 (0)