Skip to content

Commit faee8d3

Browse files
authored
Use standard named for native manipulation functions. NFC (#21555)
We continue to use the JS names when calling from JS code but use prefixed, native symbol names for the native implementation. I'm hoping we can eventually completely remove the `WASM_SYSTEM_EXPORTS` special casing.
1 parent 89ff6c9 commit faee8d3

File tree

77 files changed

+181
-142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+181
-142
lines changed

ChangeLog.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,22 @@ See docs/process.md for more on how version tagging works.
2222
-----------------------
2323
- In `MODULARIZE` mode we no longer export the module ready promise as `ready`.
2424
This was previously exposed on the Module for historical reasons even though
25-
in `MODULARIZE` mode the only way to get access to the module is to wait on the
26-
promise returned from the factory function. (#21564)
25+
in `MODULARIZE` mode the only way to get access to the module is to wait on
26+
the promise returned from the factory function. (#21564)
2727
- JS library code is now executed in its own context/scope, which limits how
2828
much of the compiler internals are accessible. If there are build time JS
2929
symbols that you are depending on, but that were not added to this scope,
3030
please file a bug and we can add more to this scope. (#21542)
31+
- The JS functions for manipulating the native/shadow stack
32+
(`stackSave`/`stackRestore`/`stackAlloc`) are now just regular JS library
33+
function and as such are only included if you explicitly depend on them. If
34+
you use these functions in your JS code you will need to depend on them via
35+
either:
36+
- The `EM_JS_DEPS` macro for `EM_ASM`/`EM_JS` code.
37+
- The `__deps` attribute for JS library functions
38+
- The `-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE` flag for `--pre-js`/`--post-js`
39+
code
40+
(#21555)
3141

3242
3.1.56 - 03/14/24
3343
-----------------

src/jsifier.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
printErr,
3232
read,
3333
warn,
34+
warnOnce,
3435
warningOccured,
3536
} from './utility.mjs';
3637
import {LibraryManager, librarySymbols} from './modules.mjs';

src/library.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121
// new function with an '_', it will not be found.
2222

2323
addToLibrary({
24+
// JS aliases for native stack manipulation functions
25+
$stackSave__deps: ['emscripten_stack_get_current'],
26+
$stackSave: () => _emscripten_stack_get_current(),
27+
$stackRestore__deps: ['_emscripten_stack_restore'],
28+
$stackRestore: (val) => __emscripten_stack_restore(val),
29+
$stackAlloc__deps: ['_emscripten_stack_alloc'],
30+
$stackAlloc: (sz) => __emscripten_stack_alloc(sz),
31+
32+
// Aliases that allow legacy names (without leading $) for these
33+
// stack functions to continue to work in `__deps` entries.
34+
stackAlloc: '$stackAlloc',
35+
stackSave: '$stackSave',
36+
stackRestore: '$stackSave',
37+
2438
$ptrToString: (ptr) => {
2539
#if ASSERTIONS
2640
assert(typeof ptr === 'number');
@@ -596,7 +610,7 @@ addToLibrary({
596610
#endif
597611

598612
$withStackSave__internal: true,
599-
$withStackSave__deps: ['stackSave', 'stackRestore'],
613+
$withStackSave__deps: ['$stackSave', '$stackRestore'],
600614
$withStackSave: (f) => {
601615
var stack = stackSave();
602616
var ret = f();

src/library_async.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ addToLibrary({
541541
});
542542
},
543543

544-
$Fibers__deps: ['$Asyncify', 'emscripten_stack_set_limits', 'stackRestore'],
544+
$Fibers__deps: ['$Asyncify', 'emscripten_stack_set_limits', '$stackRestore'],
545545
$Fibers: {
546546
nextFiber: 0,
547547
trampolineRunning: false,
@@ -601,7 +601,7 @@ addToLibrary({
601601
},
602602
},
603603

604-
emscripten_fiber_swap__deps: ["$Asyncify", "$Fibers", 'stackSave'],
604+
emscripten_fiber_swap__deps: ["$Asyncify", "$Fibers", '$stackSave'],
605605
emscripten_fiber_swap__async: true,
606606
emscripten_fiber_swap: (oldFiber, newFiber) => {
607607
if (ABORT) return;

src/library_ccall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ addToLibrary({
1515
},
1616

1717
// C calling interface.
18-
$ccall__deps: ['$getCFunc', '$writeArrayToMemory', '$stringToUTF8OnStack', 'stackSave', 'stackRestore', 'stackAlloc'],
18+
$ccall__deps: ['$getCFunc', '$writeArrayToMemory', '$stringToUTF8OnStack', '$stackSave', '$stackRestore', '$stackAlloc'],
1919
$ccall__docs: `
2020
/**
2121
* @param {string|null=} returnType

src/library_dylink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ var LibraryDylink = {
7272
// generation time.
7373
#if !DISABLE_EXCEPTION_CATCHING || SUPPORT_LONGJMP == 'emscripten'
7474
$createInvokeFunction__internal: true,
75-
$createInvokeFunction__deps: ['$dynCall', 'setThrew', 'stackSave', 'stackRestore'],
75+
$createInvokeFunction__deps: ['$dynCall', 'setThrew', '$stackSave', '$stackRestore'],
7676
$createInvokeFunction: (sig) => {
7777
return function() {
7878
var sp = stackSave();

src/library_exceptions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ var LibraryExceptions = {
287287

288288
#endif
289289
#if WASM_EXCEPTIONS || !DISABLE_EXCEPTION_CATCHING
290-
$getExceptionMessageCommon__deps: ['__get_exception_message', 'free', '$withStackSave', 'stackAlloc'],
290+
$getExceptionMessageCommon__deps: ['__get_exception_message', 'free', '$withStackSave', '$stackAlloc'],
291291
$getExceptionMessageCommon: (ptr) => withStackSave(() => {
292292
var type_addr_addr = stackAlloc({{{ POINTER_SIZE }}});
293293
var message_addr_addr = stackAlloc({{{ POINTER_SIZE }}});

src/library_legacy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ legacyFuncs = {
1717
* @param {(Uint8Array|Array<number>)} slab: An array of data.
1818
* @param {number=} allocator : How to allocate memory, see ALLOC_*
1919
*/
20-
$allocate__deps: ['$ALLOC_NORMAL', '$ALLOC_STACK', 'malloc', 'stackAlloc'],
20+
$allocate__deps: ['$ALLOC_NORMAL', '$ALLOC_STACK', 'malloc', '$stackAlloc'],
2121
$allocate: (slab, allocator) => {
2222
var ret;
2323
#if ASSERTIONS

src/library_promise.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ addToLibrary({
7777
$makePromiseCallback__deps: ['$getPromise',
7878
'$POINTER_SIZE',
7979
'emscripten_promise_destroy',
80-
'stackAlloc',
81-
'stackRestore',
82-
'stackSave'],
80+
'$stackAlloc',
81+
'$stackRestore',
82+
'$stackSave'],
8383
$makePromiseCallback: (callback, userData) => {
8484
return (value) => {
8585
#if RUNTIME_DEBUG

src/library_pthread.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ var LibraryPThread = {
960960
$proxyToMainThreadPtr: (...args) => BigInt(proxyToMainThread(...args)),
961961
#endif
962962
963-
$proxyToMainThread__deps: ['$withStackSave', '_emscripten_run_on_main_thread_js'].concat(i53ConversionDeps),
963+
$proxyToMainThread__deps: ['$withStackSave', '$stackAlloc', '_emscripten_run_on_main_thread_js'].concat(i53ConversionDeps),
964964
$proxyToMainThread__docs: '/** @type{function(number, (number|boolean), ...number)} */',
965965
$proxyToMainThread: (funcIndex, emAsmAddr, sync, ...callArgs) => {
966966
// EM_ASM proxying is done by passing a pointer to the address of the EM_ASM
@@ -1065,7 +1065,7 @@ var LibraryPThread = {
10651065
},
10661066
10671067
$establishStackSpace__internal: true,
1068-
$establishStackSpace__deps: ['stackRestore'],
1068+
$establishStackSpace__deps: ['$stackRestore'],
10691069
$establishStackSpace: () => {
10701070
var pthread_ptr = _pthread_self();
10711071
var stackHigh = {{{ makeGetValue('pthread_ptr', C_STRUCTS.pthread.stack, '*') }}};

src/library_sdl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2157,7 +2157,7 @@ var LibrarySDL = {
21572157
// We support JPG, PNG, TIF because browsers do
21582158
IMG_Init: (flags) => flags,
21592159

2160-
IMG_Load_RW__deps: ['SDL_LockSurface', 'SDL_FreeRW', '$PATH_FS', '$withStackSave', '$stringToUTF8OnStack', 'stackAlloc'],
2160+
IMG_Load_RW__deps: ['SDL_LockSurface', 'SDL_FreeRW', '$PATH_FS', '$withStackSave', '$stringToUTF8OnStack', '$stackAlloc'],
21612161
IMG_Load_RW__proxy: 'sync',
21622162
IMG_Load_RW: (rwopsID, freeSrc) => {
21632163
try {

src/library_strings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ addToLibrary({
484484
},
485485

486486
// Allocate stack space for a JS string, and write it there.
487-
$stringToUTF8OnStack__deps: ['$lengthBytesUTF8', '$stringToUTF8'],
487+
$stringToUTF8OnStack__deps: ['$lengthBytesUTF8', '$stringToUTF8', '$stackAlloc'],
488488
$stringToUTF8OnStack: (str) => {
489489
var size = lengthBytesUTF8(str) + 1;
490490
var ret = stackAlloc(size);

src/library_webgl.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3942,6 +3942,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
39423942
#if MEMORY64
39433943
// Convert an array of i64 offsets to an array of i32 offsets returning a
39443944
// pointer to the new (stack allocated) array.
3945+
$convertOffsets__deps: ['$stackAlloc'],
39453946
$convertOffsets__internal: true,
39463947
$convertOffsets: (offsets, count) => {
39473948
var offsets32 = stackAlloc(count * 4);
@@ -3960,7 +3961,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
39603961
glMultiDrawElements: 'glMultiDrawElementsWEBGL',
39613962
glMultiDrawElementsANGLE: 'glMultiDrawElementsWEBGL',
39623963
#if MEMORY64
3963-
glMultiDrawElementsWEBGL__deps: ['$convertOffsets', 'stackSave', 'stackRestore'],
3964+
glMultiDrawElementsWEBGL__deps: ['$convertOffsets', '$stackSave', '$stackRestore'],
39643965
#endif
39653966
glMultiDrawElementsWEBGL: (mode, counts, type, offsets, drawcount) => {
39663967
#if MEMORY64
@@ -3983,7 +3984,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
39833984
glMultiDrawElementsInstancedWEBGL__sig: 'vipippi',
39843985
glMultiDrawElementsInstancedANGLE: 'glMultiDrawElementsInstancedWEBGL',
39853986
#if MEMORY64
3986-
glMultiDrawElementsInstancedWEBGL__deps: ['$convertOffsets', 'stackSave', 'stackRestore'],
3987+
glMultiDrawElementsInstancedWEBGL__deps: ['$convertOffsets', '$stackSave', '$stackRestore'],
39873988
#endif
39883989
glMultiDrawElementsInstancedWEBGL: (mode, counts, type, offsets, instanceCounts, drawcount) => {
39893990
#if MEMORY64

src/settings_internal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ var SUPPORTS_PROMISE_ANY = false;
173173
// Wasm backend symbols that are considered system symbols and don't
174174
// have the normal C symbol name mangled applied (== prefix with an underscore)
175175
// (Also implicily on this list is any function that starts with string "dynCall_")
176-
var WASM_SYSTEM_EXPORTS = ['stackAlloc', 'stackSave', 'stackRestore', 'getTempRet0', 'setTempRet0'];
176+
var WASM_SYSTEM_EXPORTS = ['getTempRet0', 'setTempRet0'];
177177

178178
// Internal: value of -flto argument (either full or thin)
179179
var LTO = 0;

system/lib/compiler-rt/stack_ops.S

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
.globl stackSave
2-
.globl stackRestore
3-
.globl stackAlloc
1+
.globl _emscripten_stack_restore
2+
.globl _emscripten_stack_alloc
43
.globl emscripten_stack_get_current
54

65
#ifdef __wasm64__
@@ -13,19 +12,14 @@
1312

1413
.globaltype __stack_pointer, PTR
1514

16-
stackSave:
17-
.functype stackSave() -> (PTR)
18-
global.get __stack_pointer
19-
end_function
20-
21-
stackRestore:
22-
.functype stackRestore(PTR) -> ()
15+
_emscripten_stack_restore:
16+
.functype _emscripten_stack_restore(PTR) -> ()
2317
local.get 0
2418
global.set __stack_pointer
2519
end_function
2620

27-
stackAlloc:
28-
.functype stackAlloc(PTR) -> (PTR)
21+
_emscripten_stack_alloc:
22+
.functype _emscripten_stack_alloc(PTR) -> (PTR)
2923
.local PTR, PTR
3024
global.get __stack_pointer
3125
# Get arg 0 -> number of bytes to allocate
@@ -44,4 +38,3 @@ emscripten_stack_get_current:
4438
.functype emscripten_stack_get_current () -> (PTR)
4539
global.get __stack_pointer
4640
end_function
47-

test/core/stackAlloc.cpp renamed to test/core/test_stackAlloc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include <emscripten.h>
77

8+
EM_JS_DEPS(deps, "$stackSave,$stackAlloc");
9+
810
int main() {
911
EM_ASM({
1012
var size = 128;
File renamed without changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
__cxa_is_pointer_type
22
__indirect_function_table
33
__wasm_call_ctors
4+
_emscripten_stack_alloc
5+
_emscripten_stack_restore
46
dynCall_iiiiiijj
57
dynCall_iiiiij
68
dynCall_iiiiijj
79
dynCall_jiji
810
dynCall_viijii
11+
emscripten_stack_get_current
912
main
1013
memory
11-
stackAlloc
12-
stackRestore
13-
stackSave
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
125815
1+
125860
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
__cxa_is_pointer_type
22
__indirect_function_table
3+
_emscripten_stack_alloc
4+
_emscripten_stack_restore
35
dynCall_iiiiiijj
46
dynCall_iiiiij
57
dynCall_iiiiijj
68
dynCall_jiji
79
dynCall_viijii
10+
emscripten_stack_get_current
811
main
912
memory
10-
stackAlloc
11-
stackRestore
12-
stackSave
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
125274
1+
125319

test/other/metadce/test_metadce_cxx_except.exports

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ __cxa_increment_exception_refcount
55
__cxa_is_pointer_type
66
__indirect_function_table
77
__wasm_call_ctors
8+
_emscripten_stack_alloc
9+
_emscripten_stack_restore
810
dynCall_iiiiiijj
911
dynCall_iiiiij
1012
dynCall_iiiiijj
1113
dynCall_jiiii
1214
dynCall_jiji
1315
dynCall_viijii
16+
emscripten_stack_get_current
1417
main
1518
memory
1619
setTempRet0
1720
setThrew
18-
stackAlloc
19-
stackRestore
20-
stackSave
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10931
1+
10942
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
28115
1+
28148
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
168051
1+
168096
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
__indirect_function_table
22
__trap
33
__wasm_call_ctors
4+
_emscripten_stack_alloc
45
dynCall_iiiiiijj
56
dynCall_iiiiij
67
dynCall_iiiiijj
78
dynCall_jiji
89
dynCall_viijii
910
main
1011
memory
11-
stackAlloc
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
139189
1+
139202

test/other/metadce/test_metadce_cxx_mangle.exports

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ __cxa_increment_exception_refcount
66
__cxa_is_pointer_type
77
__indirect_function_table
88
__wasm_call_ctors
9+
_emscripten_stack_alloc
10+
_emscripten_stack_restore
911
dynCall_iiiiiijj
1012
dynCall_iiiiij
1113
dynCall_iiiiijj
1214
dynCall_jiiii
1315
dynCall_jiji
1416
dynCall_viijii
17+
emscripten_stack_get_current
1518
free
1619
main
1720
memory
1821
setTempRet0
1922
setThrew
20-
stackAlloc
21-
stackRestore
22-
stackSave
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10939
1+
10949
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
28116
1+
28149
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
223535
1+
223580
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
__cxa_is_pointer_type
22
__indirect_function_table
33
__wasm_call_ctors
4+
_emscripten_stack_alloc
5+
_emscripten_stack_restore
46
dynCall_iiiiiijj
57
dynCall_iiiiij
68
dynCall_iiiiijj
79
dynCall_jiji
810
dynCall_viijii
11+
emscripten_stack_get_current
912
main
1013
memory
11-
stackAlloc
12-
stackRestore
13-
stackSave
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
128612
1+
128657

0 commit comments

Comments
 (0)