panic_unwind: Use global_asm! for IMGREL relocations - #160183
Conversation
|
r? @LawnGnome rustbot has assigned @LawnGnome. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| // offsets from the `__ImageBase` symbol. It's not currently possible to create | ||
| // a offset that is `__ImageBase` relative in Rust code, so this is done using |
There was a problem hiding this comment.
(Nitpick: I'd clarify that they're offsets from the image base and not __ImageBase, even if that's the exact same address.)
|
Re-rolling, as my asm is absolutely not good enough for this. @rustbot reroll |
|
@bors try jobs=msvc |
This comment has been minimized.
This comment has been minimized.
panic_unwind: Use global_asm! for IMGREL relocations try-job: *msvc*
This comment has been minimized.
This comment has been minimized.
|
💔 Test for ee5da48 failed: CI. Failed jobs:
|
|
@bors try jobs=msvc |
This comment has been minimized.
This comment has been minimized.
panic_unwind: Use global_asm! for IMGREL relocations try-job: *msvc*
This comment has been minimized.
This comment has been minimized.
|
💔 Test for aa22e3c failed: CI. Failed jobs:
|
|
@bors try jobs=msvc |
This comment has been minimized.
This comment has been minimized.
panic_unwind: Use global_asm! for IMGREL relocations try-job: *msvc*
|
☔ The latest upstream changes (presumably #161256) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
|
r=me with rebase (and maybe commits squashed a bit) |
View all comments
Rust consteval cannot construct 32-bit values that contain the offset between two symbols, but this is required for panic_unwind on some architectures because unwinding on Windows SEH uses image-base-relative pointers for the panic information (which makes them fit in 32-bit rather than 64-bit).
Currently, this is worked around by initializing these globals on panic with atomic stores. This works, but is undefined behavior as the panic runtime reads the values with non-atomic loads, which leads to a data race.
Instead, utilize
global_asm!to create the globals with@IMGRELrelocations so that the linker constructs the relative pointers for us at link or load time.For context: #t-compiler > relative pointers in windows SEH panic_unwind @ 💬
AI assistance was involved with writing the assembly code.