The dynamic linking code will generate a stub if it's not resolved when first imported:
// Return a stub function that will resolve the symbol
// when first called.
if (!(prop in stubs)) {
var resolved;
stubs[prop] = (...args) => {
resolved ||= resolveSymbol(prop);
return resolved(...args);
};
}
https://github.com/emscripten-core/emscripten/blob/main/src/library_dylink.js?plain=1#L724-L727
This causes trouble when mixed with stack switching. Working around it will be a bit convoluted, but it should be possible with a little helper wasm module.