Add uwtable annotation to modules when required#156973
Open
Darksonn wants to merge 2 commits into
Open
Conversation
Collaborator
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Member
Author
|
Verified that passing |
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.
When unwind tables are enabled with
-Cforce-unwind-tables=y, Rust will annotate all functions with theuwtableannotation. However, this annotation is missing on modules, which leads to incorrect unwind tables being generated by LLVM for constructors (such asasan.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
paciaspandautiaspinstructions 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 forpaciaspwhenever-gis passed, but only emits DWARF info forautiaspwhen theuwtableattribute is present. Since theuwtableannotation is missing for modules, the relevant directives are generated for only theautiaspinstruction inasan.module_ctor, and not for thepaciaspinstruction. This causes the kernel's dynamic SCS logic to patch the prolouge ofasan.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