Skip to content

Avoid unconditionally exporting stack functions #21075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ See docs/process.md for more on how version tagging works.

3.1.52 (in development)
-----------------------
- The core stack manipulation functions (`stackSave`, `stackRestore`,
`stackAlloc`) are no longer exported by default. Users of these function
now need to depend on them explictly (either via `__deps` attributes or via
`-sEXPORTED_FUNCTIONS`). (#21075)
- Building with `pthreads+EXPORT_ES6` will now emit the worker file as
`NAME.worker.mjs` rather than `.js`. This is a necessary breaking change to
resolve other `pthreads+EXPORT_ES6` issues in Node.js (because Node.js is
Expand Down
1 change: 1 addition & 0 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ addToLibrary({
#endif

$withStackSave__internal: true,
$withStackSave__deps: ['stackSave', 'stackRestore'],
$withStackSave: (f) => {
var stack = stackSave();
var ret = f();
Expand Down
4 changes: 2 additions & 2 deletions src/library_async.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ addToLibrary({
});
},

$Fibers__deps: ['$Asyncify', 'emscripten_stack_set_limits'],
$Fibers__deps: ['$Asyncify', 'emscripten_stack_set_limits', 'stackRestore'],
$Fibers: {
nextFiber: 0,
trampolineRunning: false,
Expand Down Expand Up @@ -598,7 +598,7 @@ addToLibrary({
},
},

emscripten_fiber_swap__deps: ["$Asyncify", "$Fibers"],
emscripten_fiber_swap__deps: ["$Asyncify", "$Fibers", 'stackSave'],
emscripten_fiber_swap__async: true,
emscripten_fiber_swap: (oldFiber, newFiber) => {
if (ABORT) return;
Expand Down
2 changes: 1 addition & 1 deletion src/library_ccall.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ addToLibrary({
},

// C calling interface.
$ccall__deps: ['$getCFunc', '$writeArrayToMemory', '$stringToUTF8OnStack'],
$ccall__deps: ['$getCFunc', '$writeArrayToMemory', '$stringToUTF8OnStack', 'stackSave', 'stackRestore', 'stackAlloc'],
$ccall__docs: `
/**
* @param {string|null=} returnType
Expand Down
2 changes: 1 addition & 1 deletion src/library_dylink.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var LibraryDylink = {
// generation time.
#if !DISABLE_EXCEPTION_CATCHING || SUPPORT_LONGJMP == 'emscripten'
$createInvokeFunction__internal: true,
$createInvokeFunction__deps: ['$dynCall', 'setThrew'],
$createInvokeFunction__deps: ['$dynCall', 'setThrew', 'stackSave', 'stackRestore'],
$createInvokeFunction: (sig) => {
return function() {
var sp = stackSave();
Expand Down
2 changes: 1 addition & 1 deletion src/library_exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ var LibraryExceptions = {

#endif
#if WASM_EXCEPTIONS || !DISABLE_EXCEPTION_CATCHING
$getExceptionMessageCommon__deps: ['__get_exception_message', 'free', '$withStackSave'],
$getExceptionMessageCommon__deps: ['__get_exception_message', 'free', '$withStackSave', 'stackAlloc'],
$getExceptionMessageCommon: (ptr) => withStackSave(() => {
var type_addr_addr = stackAlloc({{{ POINTER_SIZE }}});
var message_addr_addr = stackAlloc({{{ POINTER_SIZE }}});
Expand Down
2 changes: 1 addition & 1 deletion src/library_legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ addToLibrary({
* @param {(Uint8Array|Array<number>)} slab: An array of data.
* @param {number=} allocator : How to allocate memory, see ALLOC_*
*/
$allocate__deps: ['$ALLOC_NORMAL', '$ALLOC_STACK', 'malloc'],
$allocate__deps: ['$ALLOC_NORMAL', '$ALLOC_STACK', 'malloc', 'stackAlloc'],
$allocate: (slab, allocator) => {
var ret;
#if ASSERTIONS
Expand Down
5 changes: 4 additions & 1 deletion src/library_promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ addToLibrary({

$makePromiseCallback__deps: ['$getPromise',
'$POINTER_SIZE',
'emscripten_promise_destroy'],
'emscripten_promise_destroy',
'stackAlloc',
'stackRestore',
'stackSave'],
$makePromiseCallback: (callback, userData) => {
return (value) => {
#if RUNTIME_DEBUG
Expand Down
1 change: 1 addition & 0 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@ var LibraryPThread = {
},

$establishStackSpace__internal: true,
$establishStackSpace__deps: ['stackRestore'],
$establishStackSpace: () => {
var pthread_ptr = _pthread_self();
var stackHigh = {{{ makeGetValue('pthread_ptr', C_STRUCTS.pthread.stack, '*') }}};
Expand Down
2 changes: 1 addition & 1 deletion src/library_sdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2144,7 +2144,7 @@ var LibrarySDL = {
// We support JPG, PNG, TIF because browsers do
IMG_Init: (flags) => flags,

IMG_Load_RW__deps: ['SDL_LockSurface', 'SDL_FreeRW', '$PATH_FS', '$withStackSave', '$stringToUTF8OnStack'],
IMG_Load_RW__deps: ['SDL_LockSurface', 'SDL_FreeRW', '$PATH_FS', '$withStackSave', '$stringToUTF8OnStack', 'stackAlloc'],
IMG_Load_RW__proxy: 'sync',
IMG_Load_RW: (rwopsID, freeSrc) => {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/library_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4003,7 +4003,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
glMultiDrawElements: 'glMultiDrawElementsWEBGL',
glMultiDrawElementsANGLE: 'glMultiDrawElementsWEBGL',
#if MEMORY64
glMultiDrawElementsWEBGL__deps: ['$convertOffsets'],
glMultiDrawElementsWEBGL__deps: ['$convertOffsets', 'stackSave', 'stackRestore'],
#endif
glMultiDrawElementsWEBGL: (mode, counts, type, offsets, drawcount) => {
#if MEMORY64
Expand All @@ -4026,7 +4026,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
glMultiDrawElementsInstancedWEBGL__sig: 'vipippi',
glMultiDrawElementsInstancedANGLE: 'glMultiDrawElementsInstancedWEBGL',
#if MEMORY64
glMultiDrawElementsInstancedWEBGL__deps: ['$convertOffsets'],
glMultiDrawElementsInstancedWEBGL__deps: ['$convertOffsets', 'stackSave', 'stackRestore'],
#endif
glMultiDrawElementsInstancedWEBGL: (mode, counts, type, offsets, instanceCounts, drawcount) => {
#if MEMORY64
Expand Down
2 changes: 0 additions & 2 deletions test/other/metadce/test_metadce_cxx_except_wasm.exports
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ dynCall_viijii
main
memory
stackAlloc
stackRestore
stackSave
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_cxx_except_wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
139264
139221
8 changes: 7 additions & 1 deletion tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,13 @@ def phase_linker_setup(options, state, newargs):
if sym in settings.EXPORTED_RUNTIME_METHODS:
settings.REQUIRED_EXPORTS.append(sym)

settings.REQUIRED_EXPORTS += ['stackSave', 'stackRestore', 'stackAlloc']
if settings.MAIN_READS_PARAMS and not settings.STANDALONE_WASM:
# callMain depends on stackAlloc
settings.REQUIRED_EXPORTS += ['stackAlloc']

if settings.SUPPORT_LONGJMP == 'emscripten' or not settings.DISABLE_EXCEPTION_CATCHING:
# make_invoke depends on stackSave and stackRestore
settings.REQUIRED_EXPORTS += ['stackSave', 'stackRestore']

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