Skip to content

panic_unwind: Use global_asm! for IMGREL relocations - #160183

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Darksonn:seh-imgrel
Aug 26, 2026
Merged

panic_unwind: Use global_asm! for IMGREL relocations#160183
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Darksonn:seh-imgrel

Conversation

@Darksonn

@Darksonn Darksonn commented Jul 29, 2026

Copy link
Copy Markdown
Member

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 @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 @ 💬

AI assistance was involved with writing the assembly code.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 29, 2026
@rustbot

rustbot commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

r? @LawnGnome

rustbot has assigned @LawnGnome.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from 7 candidates

Comment thread library/panic_unwind/src/seh.rs Outdated
Comment thread library/panic_unwind/src/seh.rs Outdated
Comment thread library/panic_unwind/src/seh.rs Outdated
Comment thread library/panic_unwind/src/seh.rs Outdated
Comment thread library/panic_unwind/src/seh.rs Outdated
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

@Fulgen301 Fulgen301 Jul 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Nitpick: I'd clarify that they're offsets from the image base and not __ImageBase, even if that's the exact same address.)

View changes since the review

@LawnGnome

Copy link
Copy Markdown
Contributor

Re-rolling, as my asm is absolutely not good enough for this.

@rustbot reroll

@rustbot rustbot assigned Mark-Simulacrum and unassigned LawnGnome Jul 30, 2026
Comment thread library/panic_unwind/src/seh.rs Outdated

@Mark-Simulacrum Mark-Simulacrum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not familiar with the Windows aspects of this... but happy to approve given Bjorn has taken a look with a response to the comment (either telling me I'm wrong or changing things :)

View changes since this review

Comment thread library/panic_unwind/src/seh.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 8, 2026
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors try jobs=msvc

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 8, 2026
panic_unwind: Use global_asm! for IMGREL relocations


try-job: *msvc*
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

💔 Test for ee5da48 failed: CI. Failed jobs:

@Darksonn

Darksonn commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

@bors try jobs=msvc

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 9, 2026
panic_unwind: Use global_asm! for IMGREL relocations


try-job: *msvc*
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

💔 Test for aa22e3c failed: CI. Failed jobs:

@Darksonn

Copy link
Copy Markdown
Member Author

@bors try jobs=msvc

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 10, 2026
panic_unwind: Use global_asm! for IMGREL relocations


try-job: *msvc*
@rust-bors

rust-bors Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 976338d (976338db6bad68e99abbdc7370002f113822c140)
Base parent: 7088e4b (7088e4b63a9516ebfbfe2ab2d999cf01a528ac14)

@rust-bors

This comment has been minimized.

@Mark-Simulacrum

Copy link
Copy Markdown
Member

r=me with rebase (and maybe commits squashed a bit)

@rustbot

rustbot commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

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.

@Darksonn

Copy link
Copy Markdown
Member Author

@bors try jobs=msvc

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 25, 2026
panic_unwind: Use global_asm! for IMGREL relocations


try-job: *msvc*
@rust-bors

rust-bors Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 47b8902 (47b8902dd55a82ada8730a99f6366c46b1ad8835)
Base parent: cc05892 (cc05892c8346313865afd91ca12ee1fde6d3603c)

@Darksonn

Copy link
Copy Markdown
Member Author

@bors r=Mark-Simulacrum

@rust-bors

rust-bors Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 4339216 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 26, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 26, 2026
…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))
@rust-bors
rust-bors Bot merged commit c00735c into rust-lang:main Aug 26, 2026
14 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Aug 26, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 26, 2026
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.
@rust-timer

Copy link
Copy Markdown
Collaborator

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 count

This 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.

mean range count
Regressions ❌
(primary)
4.1% [4.1%, 4.1%] 1
Regressions ❌
(secondary)
1.9% [1.0%, 3.7%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.9% [-2.9%, -2.9%] 1
All ❌✅ (primary) 4.1% [4.1%, 4.1%] 1

Cycles

Results (primary -0.5%, secondary 2.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.8% [2.8%, 2.8%] 1
Regressions ❌
(secondary)
4.2% [3.1%, 5.3%] 2
Improvements ✅
(primary)
-2.1% [-2.2%, -2.1%] 2
Improvements ✅
(secondary)
-2.5% [-2.5%, -2.5%] 1
All ❌✅ (primary) -0.5% [-2.2%, 2.8%] 3

Binary size

Results (secondary -0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 1
All ❌✅ (primary) - - 0

Bootstrap: 475.812s -> 474.909s (-0.19%)
Artifact size: 403.37 MiB -> 402.66 MiB (-0.18%)

@Darksonn
Darksonn deleted the seh-imgrel branch August 26, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants