Add uwtable annotation to modules when required#156973
Conversation
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Verified that passing |
| DllExport = 2, // Function to be accessible from DLL. | ||
| } | ||
|
|
||
| /// Must match the layout of `UWTableKind`. |
There was a problem hiding this comment.
This struct is UWTableKind. Did you mean to name a different type here?
There was a problem hiding this comment.
I'm referring to the C++ enum of the same name on the LLVM side.
There was a problem hiding this comment.
Can you add that information to the comment? It wasn't clear to me. In nearby cases the LLVM type has a different name to the Rust type.
There was a problem hiding this comment.
I checked a few other constants, and half of them just add an LLVM prefix even though it doesn't have that prefix in LLVM. The other half does have the prefix on the LLVM side. Anyways, I adjusted the comment.
|
@bors r+ rollup |
…nethercote Add uwtable annotation to modules when required 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: rust-lang#130824
|
If uwtable is emitted at the module level, is it still necessary to emit it at the function level too? |
|
Yes I believe the only effect of setting it on the module level is to inherit it for compiler-generated functions such as Furthermore, this matches clang. |
Rollup of 8 pull requests Successful merges: - #156970 (coverage: Use original HIR info for synthetic by-move coroutine bodies) - #156390 (Constify Iterator-related methods and functions) - #156401 (rustdoc: deterministic sorting for `doc_cfg` badges) - #156845 (Clarify "infinite size" in cyclic-type diagnostic refers to the type name) - #156973 (Add uwtable annotation to modules when required) - #156985 (Limit the additional DLL to Windows) - #156988 (interpret/validity: properly treat zero-variant enums so that we do not have to check layout.is_uninhabited) - #157002 (std: Fix thread::available_parallelism on Redox targets)
Rollup of 10 pull requests Successful merges: - #156970 (coverage: Use original HIR info for synthetic by-move coroutine bodies) - #157022 (MIR inlining: allow backends to opt-in to inlining intrinsics) - #157026 (miri subtree update) - #156390 (Constify Iterator-related methods and functions) - #156845 (Clarify "infinite size" in cyclic-type diagnostic refers to the type name) - #156955 (Fix const-eval of shared generic reborrows) - #156973 (Add uwtable annotation to modules when required) - #156985 (Limit the additional DLL to Windows) - #156988 (interpret/validity: properly treat zero-variant enums so that we do not have to check layout.is_uninhabited) - #157002 (std: Fix thread::available_parallelism on Redox targets)
|
@rust-timer build c42badd |
This comment has been minimized.
This comment has been minimized.
Rollup of 10 pull requests Successful merges: - rust-lang/rust#156970 (coverage: Use original HIR info for synthetic by-move coroutine bodies) - rust-lang/rust#157022 (MIR inlining: allow backends to opt-in to inlining intrinsics) - rust-lang/rust#157026 (miri subtree update) - rust-lang/rust#156390 (Constify Iterator-related methods and functions) - rust-lang/rust#156845 (Clarify "infinite size" in cyclic-type diagnostic refers to the type name) - rust-lang/rust#156955 (Fix const-eval of shared generic reborrows) - rust-lang/rust#156973 (Add uwtable annotation to modules when required) - rust-lang/rust#156985 (Limit the additional DLL to Windows) - rust-lang/rust#156988 (interpret/validity: properly treat zero-variant enums so that we do not have to check layout.is_uninhabited) - rust-lang/rust#157002 (std: Fix thread::available_parallelism on Redox targets)
|
Finished benchmarking commit (c42badd): comparison URL. Overall result: no relevant changes - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countThis perf run didn't have relevant results for this metric. Max RSS (memory usage)Results (secondary 6.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 3.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 511.088s -> 514.114s (0.59%) |
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