Skip to content

Remove assert for __get_temp_ret() and __set_temp_ret() after Binaryen JS FFI legalizer pass#26791

Open
juj wants to merge 1 commit intoemscripten-core:mainfrom
juj:fix_wasm2js0_test_autodebug_wasm
Open

Remove assert for __get_temp_ret() and __set_temp_ret() after Binaryen JS FFI legalizer pass#26791
juj wants to merge 1 commit intoemscripten-core:mainfrom
juj:fix_wasm2js0_test_autodebug_wasm

Conversation

@juj
Copy link
Copy Markdown
Collaborator

@juj juj commented Apr 26, 2026

Binaryen JS FFI legalizer pass seems to be dropping __get_temp_ret() and __set_temp_ret() if they are unused, so do not emit assert() for their existence. Fixes #25549.

I am not 100% sure about this, but this did fix the test wasm2js0.test_autodebug_wasm to pass.

@juj juj force-pushed the fix_wasm2js0_test_autodebug_wasm branch from da647ad to 9fd8bab Compare April 26, 2026 13:20
@sbc100
Copy link
Copy Markdown
Collaborator

sbc100 commented Apr 26, 2026

Can you add wasm2js0.test_autodebug_wasm to the core3+extras list in .circleci/config.yml?

We run all the tests in wasm2js1 mode in CI.. i wonder why opt level zero would mean these exports don't exist but they do exist at opt level 1 and above? I would imagine it would be other way around.

Comment thread tools/building.py
flags += ['--pass-arg=legalize-js-interface-exported-helpers']
# Ensure that the legalizer pass does not erase debug info
if settings.DEBUG_LEVEL:
flags += ['-g']
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the run_binaryen_command wrapper is supposed to take are of adding this (or not) at the appropriate times.

Copy link
Copy Markdown
Collaborator Author

@juj juj Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is/was not happening at least for this FFI JS run pass. Adding -g manually here does help the output retain debug info.

…and __set_temp_ret() if they are unused, so do not emit assert() for their existence. Fixes emscripten-core#25549.
@juj
Copy link
Copy Markdown
Collaborator Author

juj commented Apr 26, 2026

Can you add wasm2js0.test_autodebug_wasm to the core3+extras list in .circleci/config.yml?

Check.

i wonder why opt level zero would mean these exports don't exist but they do exist at opt level 1 and above? I would imagine it would be other way around.

I don't think they exist in any wasm2js* level after the JS FFI legalization wasm-opt pass runs (they exist in the output before the legalization wasm-opt run, but not after). But wasm2js0 is the only build that has assert()s that the exports would exist. Which is why it only trips up in debug builds.

@juj juj force-pushed the fix_wasm2js0_test_autodebug_wasm branch from 9fd8bab to d9eb90c Compare April 26, 2026 18:21
Comment thread tools/emscripten.py
# are created by binaryen will be missing.
continue
if settings.LEGALIZE_JS_FFI and sym in {'__get_temp_ret', '__set_temp_ret'}:
# The Binaryen legalizer pass will drop exports of __get_temp_ret() and __set_temp_ret()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this code elsewhere:

  if settings.LEGALIZE_JS_FFI:                                                                            
    settings.REQUIRED_EXPORTS += ['__get_temp_ret', '__set_temp_ret']  

Which means wasm-ld will always export them when LEGALIZE_JS_FFI.

If they are then removed at some point (for example by DCE) then that should be not different any other removed exports. i.e. the list of exports here should already take into account any DCE.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then that should be not different any other removed exports

They still go to the list of exports to generate assert()s for, which is why the test case fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wasm2js0.test_autodebug_wasm regression

2 participants