-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[EH] Make abort() work with Wasm EH #16910
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
Changes from 6 commits
f650912
a6145eb
a50f2dc
dd74bc5
f4e389a
b6fc45f
9ee27ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
void __trap() { | ||
__builtin_trap(); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1639,6 +1639,20 @@ class Polymorphic {virtual void member(){}}; | |||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
''', 'exception caught: std::bad_typeid') | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
@with_both_eh_sjlj | ||||||||||||||||||||||||||||||||||||||||
def test_terminate_abort(self): | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about renaming this "test_abort_no_dtors" and rewriting it to call C The reason I ask is that this change seem more about the behaviour of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||||||||||||||||||||||||||||||||||
# std::terminate eventually calls abort(). We used to implement abort() with | ||||||||||||||||||||||||||||||||||||||||
# throwing a JS exception, but this can be again caught by std::terminate's | ||||||||||||||||||||||||||||||||||||||||
# cleanup and cause an infinite loop. When Wasm EH is enabled, abort() is | ||||||||||||||||||||||||||||||||||||||||
# implemented by a trap now. | ||||||||||||||||||||||||||||||||||||||||
err = self.do_run(r''' | ||||||||||||||||||||||||||||||||||||||||
#include <exception> | ||||||||||||||||||||||||||||||||||||||||
int main() { | ||||||||||||||||||||||||||||||||||||||||
std::terminate(); | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you just call C abort() here to be more direct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this needs a little more context. try
function body
catch_all
call std::terminate
end
The function body of Lines 605 to 623 in 970998b
This ends up throwing a JS exception. This is basically just a foreign exception from the wasm perspective, and is caught by What #9730 tried to do was throwing a trap, because Wasm So to answer your original question, if we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I understand.. Perhaps a more direct test would be that its not possible to catch exceptions thrown by
Here we are testing that whatever the low level abort does is not catchable.. which I think is important part of this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what I wrote and deleted. Actually I was confused and this is not caught by the So I think removing |
||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
''', assert_returncode=NON_ZERO) | ||||||||||||||||||||||||||||||||||||||||
self.assertNotContained('Maximum call stack size exceeded', err) | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
def test_iostream_ctors(self): | ||||||||||||||||||||||||||||||||||||||||
# iostream stuff must be globally constructed before user global | ||||||||||||||||||||||||||||||||||||||||
# constructors, so iostream works in global constructors | ||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -708,7 +708,8 @@ class libcompiler_rt(MTLibrary, SjLjLibrary): | |
'stack_ops.S', | ||
'stack_limits.S', | ||
'emscripten_setjmp.c', | ||
'emscripten_exception_builtins.c' | ||
'emscripten_exception_builtins.c', | ||
'__trap.c' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a trailing comma.. to make future additions cleaner. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
]) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might make sense to delete this path and just use
__trap
in all cases.. but I guess that can be a followup maybe?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I didn't do that in this PR because
I don't think either of these is an important enough though. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK with landing this now and then looking at possible simplification later.
I think I'm currently a fan of (in release builds) avoiding the JS import of abort completely.. and keeping this fulling native where possible.