panic_unwind: Use global_asm! for IMGREL relocations - #160183
Open
Darksonn wants to merge 3 commits into
Open
Conversation
Collaborator
|
r? @LawnGnome rustbot has assigned @LawnGnome. Use Why was this reviewer chosen?The reviewer was selected based on:
|
bjorn3
reviewed
Jul 29, 2026
bjorn3
reviewed
Jul 29, 2026
bjorn3
reviewed
Jul 29, 2026
Fulgen301
reviewed
Jul 30, 2026
Comment on lines
+80
to
+81
| // 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 |
Contributor
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.)
Contributor
|
Re-rolling, as my asm is absolutely not good enough for this. @rustbot reroll |
bjorn3
reviewed
Jul 31, 2026
bjorn3
approved these changes
Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.