]> git.lizzy.rs Git - rust.git/commit
rustc: Use C++ personalities on MSVC
authorAlex Crichton <alex@alexcrichton.com>
Tue, 26 Apr 2016 21:30:01 +0000 (14:30 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 10 May 2016 00:28:48 +0000 (17:28 -0700)
commit38e6e5d0a9681b53cb517a3af665059e83988c3d
tree69ae16a49bfaa23613593534466e813a999b3781
parent0ec321f7b541fcbfbf20286beb497e6d9d3352b2
rustc: Use C++ personalities on MSVC

Currently the compiler has two relatively critical bugs in the implementation of
MSVC unwinding:

* #33112 - faults like segfaults and illegal instructions will run destructors
           in Rust, meaning we keep running code after a super-fatal exception
           has happened.

* #33116 - When compiling with LTO plus `-Z no-landing-pads` (or `-C
           panic=abort` with the previous commit) LLVM won't remove all `invoke`
           instructions, meaning that some landing pads stick around and
           cleanups may be run due to the previous bug.

These both stem from the flavor of "personality function" that Rust uses for
unwinding on MSVC. On 32-bit this is `_except_handler3` and on 64-bit this is
`__C_specific_handler`, but they both essentially are the "most generic"
personality functions for catching exceptions and running cleanups. That is,
thse two personalities will run cleanups for all exceptions unconditionally, so
when we use them we run cleanups for **all SEH exceptions** (include things like
segfaults).

Note that this also explains why LLVM won't optimize away `invoke` instructions.
These functions can legitimately still unwind (the `nounwind` attribute only
seems to apply to "C++ exception-like unwining"). Also note that the standard
library only *catches* Rust exceptions, not others like segfaults and illegal
instructions.

LLVM has support for another personality, `__CxxFrameHandler3`, which does not
run cleanups for general exceptions, only C++ exceptions thrown by
`_CxxThrowException`. This essentially ideally matches our use case, so this
commit moves us over to using this well-known personality function as well as
exception-throwing function.

This doesn't *seem* to pull in any extra runtime dependencies just yet, but if
it does we can perhaps try to work out how to implement more of it in Rust
rather than relying on MSVCRT runtime bits.

More details about how this is actually implemented can be found in the changes
itself, but this...

Closes #33112
Closes #33116
src/libpanic_abort/lib.rs
src/libpanic_unwind/seh.rs
src/libpanic_unwind/windows.rs
src/librustc_trans/common.rs
src/librustc_trans/intrinsic.rs
src/libstd/panicking.rs
src/llvm
src/rustllvm/llvm-auto-clean-trigger