Skip to content

Add uwtable annotation to modules when required#156973

Open
Darksonn wants to merge 2 commits into
rust-lang:mainfrom
Darksonn:unwind-tables-module
Open

Add uwtable annotation to modules when required#156973
Darksonn wants to merge 2 commits into
rust-lang:mainfrom
Darksonn:unwind-tables-module

Conversation

@Darksonn
Copy link
Copy Markdown
Member

@Darksonn Darksonn commented May 26, 2026

When unwind tables are enabled with -Cforce-unwind-tables=y, Rust will annotate all functions with the uwtable annotation. However, this annotation is missing on modules, which leads to incorrect unwind tables being generated by LLVM for constructors (such as asan.module_ctor).

This was discovered because it leads to a crash in Linux when KASAN and dynamic shadow call stack are both enabled. In this scenario, the kernel uses the unwind tables to locate the paciasp and autiasp instructions in each function and patches the machine code at boot to use the shadow call stack instructions instead. However, LLVM's AArch64PointerAuth pass emits DWARF info for paciasp whenever -g is passed, but only emits DWARF info for autiasp when the uwtable attribute is present. Since the uwtable annotation is missing for modules, the relevant directives are generated for only the autiasp instruction in asan.module_ctor, and not for the paciasp instruction. This causes the kernel's dynamic SCS logic to patch the prolouge of asan.module_ctor, but not the epilogue. This leads to a crash as the shadow call stack becomes unbalanced.

The fact that LLVM doesn't use the same condition for whether to emit DWARF information for both instructions may be a separate bug in LLVM.

Relevant issue: llvm/llvm-project#188234

AI assistance was used to determine the root cause of this crash from the observed symptoms, and to write the tests. Also thanks to @samitolvanen and @maurer for debugging this issue.

Similar to this previous PR of mine: #130824

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 26, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 26, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
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: compiler
  • compiler expanded to 73 candidates
  • Random selection from 18 candidates

@Darksonn Darksonn added the A-rust-for-linux Relevant for the Rust-for-Linux project label May 26, 2026
@Darksonn
Copy link
Copy Markdown
Member Author

Darksonn commented May 26, 2026

Verified that passing -Zllvm_module_flag=uwtable:u32:2:max to the Linux kernel build fixes the boot failure that triggered this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-rust-for-linux Relevant for the Rust-for-Linux project S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants