Skip to content

Conversation

@sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Mar 22, 2024

wasm-emscripten-finalize will always performs some amount of type legalization unless WASM_BIGINT is enabled. The logic in finalize_wasm was getting this wrong.

I'm not sure exactly what the side effects of this are today but I'm working on change to getTempRet0/setTempRet0 handling where this becomes a problem because js_legalization_pass_flags was not being passed to wasm-emscripten-finalize even though some amount of legalization was happening. This was only effecting the WASM_BIGINT=0 + LEGALIZE_JS_FFI=0 case in which partial legalization occurs.

See: #21579

@sbc100 sbc100 force-pushed the type_legalization branch from 662f137 to 4ca347d Compare March 22, 2024 03:14
`wasm-emscripten-finalize` will always performs some amount of type
legalization unless WASM_BIGINT is enabled.  The logic in
`finalize_wasm` was getting this wrong.

I'm not sure exactly what the side effects of this are today but I'm
working on change to `getTempRet0`/`setTempRet0` handling where this
becomes a problem because `js_legalization_pass_flags` was not being
passed to `wasm-emscripten-finalize` even though some amount of
legalization was happening.  This was only effecting the `WASM_BIGINT=0`
+ `LEGALIZE_JS_FFI=0` case in which partial legalization occurs.

See: emscripten-core#21579
@sbc100 sbc100 force-pushed the type_legalization branch from 4ca347d to 3b23828 Compare March 22, 2024 03:14
args.append('--bigint')
else:
if settings.LEGALIZE_JS_FFI:
# When we dynamically link our JS loader adds functions from wasm modules to
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This comment was removed becasue it basically duplicate of the one in js_legalization_pass_flags

@sbc100 sbc100 changed the title JS type legalized is still performed regardless of LEGALIZE_JS_FFI JS type legalization is still performed regardless of LEGALIZE_JS_FFI Mar 22, 2024
@sbc100 sbc100 requested a review from kripken March 22, 2024 03:15
@sbc100
Copy link
Collaborator Author

sbc100 commented Mar 22, 2024

Going forward I wonder if we still want the LEGALIZE_JS_FFI setting at all?

Do we have users who would want to set -sLEGALIZE_JS_FFI=0 but not -sWASM_BIGINT and thus get partial legalization?

@sbc100 sbc100 enabled auto-merge (squash) March 22, 2024 16:32
args.append('--no-legalize-javascript-ffi')
legalizing = False

if not settings.LEGALIZE_JS_FFI:
Copy link
Member

Choose a reason for hiding this comment

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

Can we not use settings.LEGALIZE_JS_FFI where the new legalizing variable is set? That is, I'm not sure why a new variable is needed here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reason is that LEGALIZE_JS_FFI does not mean "don't do any legalization at all", it just means "do partial legalization".

See https://github.com/WebAssembly/binaryen/blob/2471301a5209724b1ea32fab36b13410e96c0af9/src/tools/wasm-emscripten-finalize.cpp#L262-L267

At least today.

We could change that but I think we can/should consider that separately.

@kripken
Copy link
Member

kripken commented Mar 22, 2024

Good question about the setting. I think I remember we wanted the option to disable legalization for certain standalone cases, where the user wants the ABI to not be modified by legalization, and they handle things themselves.

I agree it would be nice to have fewer settings here. Maybe once WASM_BIGINT is on by default, at which time we do no legalization by default, we can remove LEGALIZE_JS_FFI.

@sbc100 sbc100 requested a review from kripken March 22, 2024 21:24
@sbc100
Copy link
Collaborator Author

sbc100 commented Mar 23, 2024

Closing in favor of binaryen change plus #21599

@sbc100 sbc100 closed this Mar 23, 2024
auto-merge was automatically disabled March 23, 2024 23:11

Pull request was closed

@sbc100 sbc100 deleted the type_legalization branch March 23, 2024 23:11
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.

2 participants