Skip to content

Commit ac83519

Browse files
authored
Use emscripten_stack_set_limits in wasm_worker_initialize.S (#22755)
Followup to #22683. This change avoids making __stack_base and __stack_end into public/external symbols and avoids reimplementing `emscripten_stack_set_limits`. This is a minor code size win too.
1 parent f6ed386 commit ac83519

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
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 /*base*/, PTR /*end*/) -> ()
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

test/code_size/hello_wasm_worker_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"a.js.gz": 455,
66
"a.ww.js": 115,
77
"a.ww.js.gz": 127,
8-
"a.wasm": 1894,
9-
"a.wasm.gz": 1077,
10-
"total": 3292,
11-
"total_gz": 2043
8+
"a.wasm": 1879,
9+
"a.wasm.gz": 1066,
10+
"total": 3277,
11+
"total_gz": 2032
1212
}

test/core/test_dlfcn_self.exports

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ __progname_full
99
__sig_actions
1010
__sig_pending
1111
__signgam
12-
__stack_base
1312
__stack_chk_guard
14-
__stack_end
1513
__threwValue
1614
__timezone
1715
__tzname

0 commit comments

Comments
 (0)