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*
This comment has been minimized.
This comment has been minimized.
|
r=me with rebase (and maybe commits squashed a bit) |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@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*
|
@bors r=Mark-Simulacrum |
…uwer Rollup of 7 pull requests Successful merges: - #157036 (lint against repeated repr attributes) - #160183 (panic_unwind: Use global_asm! for IMGREL relocations) - #161718 (Fix the wasm32-unknown-unknown target feature/cfg bug) - #161673 (Fix broken link to lang_items.rs in unstable book) - #161744 (Remove `RawDefPathHash`) - #161747 (explicitly state that allocations cannot grow to the left) - #161796 (Remove dead parse error recovery (underscores in expressions))
Rollup merge of #160183 - Darksonn:seh-imgrel, r=Mark-Simulacrum panic_unwind: Use global_asm! for IMGREL relocations 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 `@IMGREL` relocations 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 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/relative.20pointers.20in.20windows.20SEH.20panic_unwind/near/613200087) AI assistance was involved with writing the assembly code.
|
Note This PR was benchmarked as part of triage of its containing rollup: triage URL. Finished benchmarking commit (ae960b0): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis perf run didn't have relevant results for this metric. Max RSS (memory usage)Results (primary 4.1%, secondary 1.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -0.5%, secondary 2.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (secondary -0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 475.812s -> 474.909s (-0.19%) |
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.