-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Runtime][IRGen] Trap C++ exceptions on *throw*, not catch. #71056
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
Conversation
We might need to do something to make sure that the Linux build still works for people while we're landing this — building with host tools is probably going to cause a problem because of the extra API that the compiler is using. |
@swift-ci Please test |
Someday, can we emit this unconditionally to prevent people trying to throw through Swift frames and catch them on the other side? |
@swift-ci Please test |
24a2031
to
3e2b018
Compare
There's also an issue in that gating on availability means the test needs to pass the availability flags. I'm going to fix the availability situation on Linux and then come back to this PR. |
3e2b018
to
c7e74d7
Compare
@swift-ci Please smoke test |
c7e74d7
to
ec01501
Compare
@swift-ci Please smoke test |
89ee1f5
to
16f27d6
Compare
@swift-ci Please smoke test |
The previous approach was effectively to catch the exception and then run a trap instruction. That has the unfortunate feature that we end up with a crash at the catch site, not at the throw site, which leaves us with very little information about which exception was thrown or where from. (Strictly we do have the exception pointer and could obtain exception information, but it still won't tell us what threw it.) Instead of that, set a personality function for Swift functions that call potentially throwing code, and have that personality function trap the exception during phase 1 (i.e. *before* the original stack has been unwound). rdar://120952971
The exception handling tests should check for the new personality, and the ABI check needs to know about the new entry point in the runtime. rdar://120952971
The other new runtime functions appear to have a leading underscore. It makes sense in this case because we don't expect anything to call this directly (other than the unwinder). rdar://120952971
We need to only generate references to `_swift_exceptionPersonality` if we're building for a new enough runtime. The previous code was good on Darwin, but would have resulted in build problems on Linux. rdar://120952971
16f27d6
to
76f2389
Compare
Rebased. |
@swift-ci Please smoke test |
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.
Thanks, that should be fine
The previous approach was effectively to catch the exception and then run a trap instruction. That has the unfortunate feature that we end up with a crash at the catch site, not at the throw site, which leaves us with very little information about which exception was thrown or where from.
(Strictly we do have the exception pointer and could obtain exception information, but it still won't tell us what threw it.)
Instead of that, set a personality function for Swift functions that call potentially throwing code, and have that personality function trap the exception during phase 1 (i.e. before the original stack has been unwound).
rdar://120952971