Skip to content
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

[EH] Use LLVM implementation for new Wasm EH #23469

Merged
merged 20 commits into from
Jan 29, 2025

Conversation

aheejin
Copy link
Member

@aheejin aheejin commented Jan 22, 2025

This adds a new WASM mode in ExceptionLibrary, which uses the new standard Wasm (exnref) EH, adds a library variant for it, and make the tests use the new LLVM implementation instead of the Binaryen translator.

The CI won't pass until llvm/llvm-project#123915 lands.

This requires adding -wasmexcept and -wasmsjlj variants to MINIMAL_TASKS in embuilder.py
because they are necessary to run coreX tests in CircleCI, because dylink coreX tests in CircleCI rellies on ./embuilder build MINIMAL_PIC --pic, which is the sum of MINIMAL_TASKS and MINIMAL_PIC_TASKS.

Because a new variant is added to ExceptionLibrary, this increases SYSTEM library size from 366M to 400M, roughly by 11%. We discussed about the possibility of not shipping the exnref libraries and let them be built on demand, but given that SYSTEM include all variants, I'm not sure how we are going to do that:

emscripten/embuilder.py

Lines 174 to 177 in 73ebb91

def get_system_tasks():
system_libraries = system_libs.Library.get_all_variations()
system_tasks = list(system_libraries.keys())
return system_libraries, system_tasks

This adds a new `WASM` mode in `ExceptionLibrary`, which uses the new
standard Wasm (exnref) EH, adds a library variant for it, and make the
tests use the new LLVM implementation instead of the Binaryen
translator.

The CI won't pass until llvm/llvm-project#123915
lands.
@aheejin aheejin requested review from sbc100 and dschuff January 22, 2025 10:04
This is an automatic change generated by tools/maint/rebaseline_tests.py.

The following (1) test expectation files were updated by
running the tests with `--rebaseline`:

```
other/codesize/test_codesize_cxx_except_wasm.size: 144708 => 144587 [-121 bytes / -0.08%]

Average change: -0.08% (-0.08% - -0.08%)
```
@@ -431,10 +431,6 @@ def check_human_readable_list(items):
extras = settings.BINARYEN_EXTRA_PASSES.split(',')
passes += [('--' + p) if p[0] != '-' else p for p in extras if p]

# Run the translator to the standardized EH instructions.
if not settings.WASM_LEGACY_EXCEPTIONS:
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it would be worthwhile to keep some way to activate the translator path for a while. Just in case, e.g. someone finds a bug, they can try the other pathway?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what would be a good option for enabling this... Adding one more possible value to WASM_LEGACY_EXCEPTIONS (which sounds weird because LEGACY_EXCEPTIONS option sounds like it should be on or off and not about what kind of non-leagcy exception we choose) or adding another option?

Also I don't have any idea how widely this feature has been adopted in the first place. I haven't received a single bug reports about this feature over the last year... So I guess this is at least not widely used, if ever used anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm sure it's the case that nobody has been using it. I think Firefox is the only runtime that supports it so far, so nobody would really have a good reason to, when everything supports legacy exceptions.
As for options, I don't think it matters much. I'm imagining this would basically be an undocumented debugging option that we'd eventually get rid of once we're confident that LLVM and Binaryen's exnref support both work.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess it's only useful for us Emscripten developers and not much for users. Having an internal option for testing for us sounds fine, but I'm a little hesitant because we already have a messy soup of options for EH/SjLj.. 🥲

Anyway can that be a followup?

Copy link
Member Author

@aheejin aheejin Jan 23, 2025

Choose a reason for hiding this comment

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

Hmm, come to think of it, I don't think it will be very useful after all... We, or more likely I, will be the only one who will run that option (for debugging, in case llvm implementation has bugs or something), and I still can do that with wasm-opt --translate-to-exnref on the legacy Wasm EH result.. It's only one command and it's gonna be needed only when debugging, so I don't feel that's too inconvenient. And I'd like to avoid adding one more option to the soup of EH/SjLj options...

Copy link
Member

Choose a reason for hiding this comment

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

Ah that's a good point that if it's a one-command translation that would be easy enough. Is the wasm/JS interface 100% compatible?

Copy link
Member

Choose a reason for hiding this comment

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

(even if not, if we decide to do it, a followup is fine)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah that's a good point that if it's a one-command translation that would be easy enough. Is the wasm/JS interface 100% compatible?

Yeah I don't see why not. I checked with a simple test case, replacing only the wasm with the translated binary, and it seems to work.

@@ -431,10 +431,6 @@ def check_human_readable_list(items):
extras = settings.BINARYEN_EXTRA_PASSES.split(',')
passes += [('--' + p) if p[0] != '-' else p for p in extras if p]

# Run the translator to the standardized EH instructions.
if not settings.WASM_LEGACY_EXCEPTIONS:
Copy link
Member

Choose a reason for hiding this comment

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

(even if not, if we decide to do it, a followup is fine)

@aheejin aheejin requested a review from kripken January 24, 2025 23:02
@aheejin
Copy link
Member Author

aheejin commented Jan 24, 2025

Because a new variant is added to ExceptionLibrary, this increases SYSTEM library size from 366M to 400M, roughly by 11%. We discussed about the possibility of not shipping the exnref libraries and let them be built on demand, but given that SYSTEM include all variants, I'm not sure how we are going to do that:

emscripten/embuilder.py

Lines 174 to 177 in 73ebb91

def get_system_tasks():
system_libraries = system_libs.Library.get_all_variations()
system_tasks = list(system_libraries.keys())
return system_libraries, system_tasks

(I updated the PR description too)

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Seems ok to me to increase SDK size by a small amount here, given we can't think of a simple way to avoid it. I guess this will make removing old EH modes in the future even nicer...

@aheejin aheejin merged commit 62304e2 into emscripten-core:main Jan 29, 2025
29 checks passed
@aheejin aheejin deleted the lib_wasm_eh branch January 29, 2025 04:02
cwoffenden added a commit to cwoffenden/emscripten that referenced this pull request Jan 29, 2025
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.

3 participants