Commit 1bdbe3a
authored
Rollup merge of #161368 - hsanzg:uw-ex-align, r=bjorn3,tgross35
Double-word align `_Unwind_Exception`
The [Itanium C++ ABI spec](https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html) states that the `_Unwind_Exception` type must be double-word aligned (see Section 1.2). The missing alignment option does not seem to cause problems when a) using Rust's panic mechanism (because the exception object passed to `_Unwind_RaiseException` is [heap-allocated](https://github.com/rust-lang/rust/blob/f7d782a3be46d6bb4b9792fe69a61db389ba1769/library/panic_unwind/src/gcc.rs#L62) and thus double-word aligned by accident---although this is not guaranteed) or b) when linking against libgcc's unwinder.
Most people don't need to unwind stacks themselves, so case (a) usually applies; and case (b) is the default for the `amd64-unknown-linux-gnu` target. Thus, misalignments seem unlikely to cause trouble in practice. However, I recently copied over some of the type definitions in `library/unwind` into a personal project, built `rustc` with `rust.llvm-libunwind = "system"`, and installed LLVM's `libunwind-24-dev`. Calling `_Unwind_RaiseException` with a thread-local `_Unwind_Exception` object led to a segfault due to the too-small default alignment. So `libunwind` seems to depend on the double-word alignment.
N.B.: Both `libunwind` and `libgcc` have comments [1, 2] saying that the "double-word" alignment is a bit ambiguous when interpreted in a target-agnostic sense, and they both add `__attribute__((__aligned__))` to `_Unwind_Exception`, with no specific alignment value (the default is the maximum alignment of any integer type). Rust doesn't have such a "default" alignment, so I interpreted "double-word" in a target-dependent manner via `cfg_attr` + the `target_pointer_width` feature.
\[1]: https://github.com/llvm/llvm-project/blob/196786fa5fe4225539678fc7904a383eca05374e/libunwind/include/unwind_itanium.h#L41
\[2]: https://github.com/gcc-mirror/gcc/blob/50a2eb56b9a350ecced4db4942e92d463dab8d8f/libgcc/unwind-generic.h#L1061 file changed
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
46 | 52 | | |
47 | 53 | | |
48 | 54 | | |
| |||
0 commit comments