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

Fixup block-nested pops even when EH is not enabled #7130

Merged
merged 2 commits into from
Dec 3, 2024

Conversation

tlively
Copy link
Member

@tlively tlively commented Dec 2, 2024

While parsing a binary file, there may be pops that need to be fixed up
even if EH is not (yet) enabled because the target features section has
not been parsed yet. Previously EHUtils::handleBlockNestedPops did not
do anything if EH was not enabled, so the binary parser would fail to
fix up pops in that case. Add an optional parameter to override this
behavior so the parser can fix up pops unconditionally.

Fixes #7127.

While parsing a binary file, there may be pops that need to be fixed up
even if EH is not (yet) enabled because the target features section has
not been parsed yet. Previously `EHUtils::handleBlockNestedPops` did not
do anything if EH was not enabled, so the binary parser would fail to
fix up pops in that case. Fix the utility to run no matter what features
are enabled and fix up its users so it is only called from optimization
passes when EH is enabled.

Fixes #7127.
@tlively tlively requested a review from kripken December 2, 2024 22:33
@@ -149,9 +149,6 @@ void handleBlockNestedPop(Try* try_, Function* func, Module& wasm) {
}

void handleBlockNestedPops(Function* func, Module& wasm) {
if (!wasm.features.hasExceptionHandling()) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

I worry this is a significant regression. Before this PR, many passes would skip this pop handling in e.g. normal Emscripten output, just because the feature was not present. That is, this fixes parsing, but it is slowing down optimizations IIUC.

If the parsing issue is that we haven't seen the features section yet, perhaps we can fix that by doing what we now do with names - scan ahead for the features section first?

Copy link
Member

Choose a reason for hiding this comment

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

We can do the check in those passes too, as the code here does, I guess - but if that's the best option, perhaps we can avoid the code duplication by adding handleBlockNestedPopsAfterParse (or a much better name hopefully) that does the feature check?

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you think about adding an extra optional parameter bool ignoreFeatures = false that would only be used by the parser code?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. Maybe an enum?

@tlively
Copy link
Member Author

tlively commented Dec 2, 2024

Done!

@@ -35,15 +35,15 @@
;; The fixup will hoist the 'pop' and create another local to store it right
;; after 'catch'.

;; RUN: wasm-opt -all %s.wasm -S -o - | filecheck %s
;; RUN: wasm-opt %s.wasm -S -o - | filecheck %s
Copy link
Member

Choose a reason for hiding this comment

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

How does this command not error in the validator, as the wasm uses EH?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, the features section? Which is the binary change I guess.

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 added a target features section enabling EH to the binary, so this test now reflects what happens in practice when Emscripten first parses a binary.

@tlively tlively enabled auto-merge (squash) December 2, 2024 23:42
@tlively tlively merged commit f331120 into main Dec 3, 2024
13 checks passed
@tlively tlively deleted the eh-fixup-all-features branch December 3, 2024 00:03
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.

[Old EH] "pop's location is not valid"-error since Emscripten 3.1.73
2 participants