Skip to content

Commit 12e5069

Browse files
authored
Avoid unconditionally exporting stack functions (#21075)
See #11898
1 parent 29b0eaa commit 12e5069

14 files changed

+27
-14
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.52 (in development)
2222
-----------------------
23+
- The core stack manipulation functions (`stackSave`, `stackRestore`,
24+
`stackAlloc`) are no longer exported by default. Users of these function
25+
now need to depend on them explictly (either via `__deps` attributes or via
26+
`-sEXPORTED_FUNCTIONS`). (#21075)
2327
- Building with `pthreads+EXPORT_ES6` will now emit the worker file as
2428
`NAME.worker.mjs` rather than `.js`. This is a necessary breaking change to
2529
resolve other `pthreads+EXPORT_ES6` issues in Node.js (because Node.js is

src/library.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ addToLibrary({
594594
#endif
595595

596596
$withStackSave__internal: true,
597+
$withStackSave__deps: ['stackSave', 'stackRestore'],
597598
$withStackSave: (f) => {
598599
var stack = stackSave();
599600
var ret = f();

src/library_async.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ addToLibrary({
538538
});
539539
},
540540

541-
$Fibers__deps: ['$Asyncify', 'emscripten_stack_set_limits'],
541+
$Fibers__deps: ['$Asyncify', 'emscripten_stack_set_limits', 'stackRestore'],
542542
$Fibers: {
543543
nextFiber: 0,
544544
trampolineRunning: false,
@@ -598,7 +598,7 @@ addToLibrary({
598598
},
599599
},
600600

601-
emscripten_fiber_swap__deps: ["$Asyncify", "$Fibers"],
601+
emscripten_fiber_swap__deps: ["$Asyncify", "$Fibers", 'stackSave'],
602602
emscripten_fiber_swap__async: true,
603603
emscripten_fiber_swap: (oldFiber, newFiber) => {
604604
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'],
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'],
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'],
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 @@ addToLibrary({
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'],
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ addToLibrary({
7676

7777
$makePromiseCallback__deps: ['$getPromise',
7878
'$POINTER_SIZE',
79-
'emscripten_promise_destroy'],
79+
'emscripten_promise_destroy',
80+
'stackAlloc',
81+
'stackRestore',
82+
'stackSave'],
8083
$makePromiseCallback: (callback, userData) => {
8184
return (value) => {
8285
#if RUNTIME_DEBUG

src/library_pthread.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,7 @@ var LibraryPThread = {
10631063
},
10641064
10651065
$establishStackSpace__internal: true,
1066+
$establishStackSpace__deps: ['stackRestore'],
10661067
$establishStackSpace: () => {
10671068
var pthread_ptr = _pthread_self();
10681069
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
@@ -2144,7 +2144,7 @@ var LibrarySDL = {
21442144
// We support JPG, PNG, TIF because browsers do
21452145
IMG_Init: (flags) => flags,
21462146

2147-
IMG_Load_RW__deps: ['SDL_LockSurface', 'SDL_FreeRW', '$PATH_FS', '$withStackSave', '$stringToUTF8OnStack'],
2147+
IMG_Load_RW__deps: ['SDL_LockSurface', 'SDL_FreeRW', '$PATH_FS', '$withStackSave', '$stringToUTF8OnStack', 'stackAlloc'],
21482148
IMG_Load_RW__proxy: 'sync',
21492149
IMG_Load_RW: (rwopsID, freeSrc) => {
21502150
try {

src/library_webgl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4003,7 +4003,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
40034003
glMultiDrawElements: 'glMultiDrawElementsWEBGL',
40044004
glMultiDrawElementsANGLE: 'glMultiDrawElementsWEBGL',
40054005
#if MEMORY64
4006-
glMultiDrawElementsWEBGL__deps: ['$convertOffsets'],
4006+
glMultiDrawElementsWEBGL__deps: ['$convertOffsets', 'stackSave', 'stackRestore'],
40074007
#endif
40084008
glMultiDrawElementsWEBGL: (mode, counts, type, offsets, drawcount) => {
40094009
#if MEMORY64
@@ -4026,7 +4026,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
40264026
glMultiDrawElementsInstancedWEBGL__sig: 'vipippi',
40274027
glMultiDrawElementsInstancedANGLE: 'glMultiDrawElementsInstancedWEBGL',
40284028
#if MEMORY64
4029-
glMultiDrawElementsInstancedWEBGL__deps: ['$convertOffsets'],
4029+
glMultiDrawElementsInstancedWEBGL__deps: ['$convertOffsets', 'stackSave', 'stackRestore'],
40304030
#endif
40314031
glMultiDrawElementsInstancedWEBGL: (mode, counts, type, offsets, instanceCounts, drawcount) => {
40324032
#if MEMORY64

test/other/metadce/test_metadce_cxx_except_wasm.exports

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@ dynCall_viijii
99
main
1010
memory
1111
stackAlloc
12-
stackRestore
13-
stackSave
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
139264
1+
139221

tools/link.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,13 @@ def phase_linker_setup(options, state, newargs):
12791279
if sym in settings.EXPORTED_RUNTIME_METHODS:
12801280
settings.REQUIRED_EXPORTS.append(sym)
12811281

1282-
settings.REQUIRED_EXPORTS += ['stackSave', 'stackRestore', 'stackAlloc']
1282+
if settings.MAIN_READS_PARAMS and not settings.STANDALONE_WASM:
1283+
# callMain depends on stackAlloc
1284+
settings.REQUIRED_EXPORTS += ['stackAlloc']
1285+
1286+
if settings.SUPPORT_LONGJMP == 'emscripten' or not settings.DISABLE_EXCEPTION_CATCHING:
1287+
# make_invoke depends on stackSave and stackRestore
1288+
settings.REQUIRED_EXPORTS += ['stackSave', 'stackRestore']
12831289

12841290
if settings.RELOCATABLE:
12851291
# TODO(https://reviews.llvm.org/D128515): Make this mandatory once

0 commit comments

Comments
 (0)