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, '*') }}};

0 commit comments

Comments
 (0)