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 |
| "lea {}, [rip + 2f]" | ||
| } | ||
| any(target_arch = "arm", target_arch = "aarch64", target_arch = "arm64ec") => { | ||
| "adr {}, 2f" |
There was a problem hiding this comment.
Isn't the range of this offset too small?
Is the program label whose address is to be calculated. It is an offset from the address of this instruction, in the range ±1MB.
(https://support.arm.com/documentation/dui0802/b/A64-General-Instructions/ADR)
I would expect we need to support programs where the instructions and rdata are farther apart. Should we be using adrl here?
(Not sure if lea has the same problem).
There was a problem hiding this comment.
Using adrl makes sense to me. For lea, it can be encoded with a 16bit, 32bit or 64bit offset. I don't know which one LLVM picks. Probably either 32bit or 64bit.
There was a problem hiding this comment.
I'm hoping this is the cause of the exit code: 0xc0000005, STATUS_ACCESS_VIOLATION in the try job, but once fixed we should re-run that. If it is the cause, I'm sad that LLVM / rustc didn't complain about the relocation overflowing, but maybe it's not that surprising.
There was a problem hiding this comment.
It looks like using wider offsets fixed the issue.
|
@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*
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.