about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-04-24 11:40:42 +0200
committerGitHub <noreply@github.com>2025-04-24 11:40:42 +0200
commita90f31e319659170539f50a306165dcb7afb3f46 (patch)
tree8c75200ef3aca6061ecb8f1275a2190ec0fcc483
parent60c2c34d1de100a3779fc38251c2ba1393bef7a8 (diff)
parentf2ab763c20c468411cd99bc367b479c12c44fd25 (diff)
downloadrust-a90f31e319659170539f50a306165dcb7afb3f46.tar.gz
rust-a90f31e319659170539f50a306165dcb7afb3f46.zip
Rollup merge of #140194 - jieyouxu:minicore-force-unwind-tables, r=bjorn3
minicore: Have `//@ add-core-stubs` also imply `-Cforce-unwind-tables=yes`

To preserve CFI directives in assembly tests, as `//@ add-core-stubs` already imply `-C panic=abort`.

This is a blocker for https://github.com/rust-lang/rust/pull/140037#issuecomment-2816665358.

cc ```@RalfJung```
r? ```@bjorn3```
-rw-r--r--src/doc/rustc-dev-guide/src/tests/minicore.md26
-rw-r--r--src/tools/compiletest/src/runtest.rs8
-rw-r--r--tests/assembly/x86-return-float.rs10
3 files changed, 35 insertions, 9 deletions
diff --git a/src/doc/rustc-dev-guide/src/tests/minicore.md b/src/doc/rustc-dev-guide/src/tests/minicore.md
index e4853b6d40e..507b259e027 100644
--- a/src/doc/rustc-dev-guide/src/tests/minicore.md
+++ b/src/doc/rustc-dev-guide/src/tests/minicore.md
@@ -6,25 +6,37 @@
 ui/codegen/assembly test suites. It provides `core` stubs for tests that need to
 build for cross-compiled targets but do not need/want to run.
 
+<div class="warning">
+Please note that [`minicore`] is only intended for `core` items, and explicitly
+**not** `std` or `alloc` items because `core` items are applicable to a wider
+range of tests.
+</div>
+
 A test can use [`minicore`] by specifying the `//@ add-core-stubs` directive.
 Then, mark the test with `#![feature(no_core)]` + `#![no_std]` + `#![no_core]`.
 Due to Edition 2015 extern prelude rules, you will probably need to declare
 `minicore` as an extern crate.
 
+## Implied compiler flags
+
 Due to the `no_std` + `no_core` nature of these tests, `//@ add-core-stubs`
 implies and requires that the test will be built with `-C panic=abort`.
-Unwinding panics are not supported.
+**Unwinding panics are not supported.**
+
+Tests will also be built with `-C force-unwind-tables=yes` to preserve CFI
+directives in assembly tests.
+
+TL;DR: `//@ add-core-stubs` implies two compiler flags:
+
+1. `-C panic=abort`
+2. `-C force-unwind-tables=yes`
+
+## Adding more `core` stubs
 
 If you find a `core` item to be missing from the [`minicore`] stub, consider
 adding it to the test auxiliary if it's likely to be used or is already needed
 by more than one test.
 
-<div class="warning">
-Please note that [`minicore`] is only intended for `core` items, and explicitly
-**not** `std` or `alloc` items because `core` items are applicable to a wider
-range of tests.
-</div>
-
 ## Example codegen test that uses `minicore`
 
 ```rust,no_run
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index cc09463c358..fe23cce81e9 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -1710,12 +1710,16 @@ impl<'test> TestCx<'test> {
         rustc.args(&self.props.compile_flags);
 
         // FIXME(jieyouxu): we should report a fatal error or warning if user wrote `-Cpanic=` with
-        // something that's not `abort`, however, by moving this last we should override previous
-        // `-Cpanic=`s
+        // something that's not `abort` and `-Cforce-unwind-tables` with a value that is not `yes`,
+        // however, by moving this last we should override previous `-Cpanic`s and
+        // `-Cforce-unwind-tables`s. Note that checking here is very fragile, because we'd have to
+        // account for all possible compile flag splittings (they have some... intricacies and are
+        // not yet normalized).
         //
         // `minicore` requires `#![no_std]` and `#![no_core]`, which means no unwinding panics.
         if self.props.add_core_stubs {
             rustc.arg("-Cpanic=abort");
+            rustc.arg("-Cforce-unwind-tables=yes");
         }
 
         rustc
diff --git a/tests/assembly/x86-return-float.rs b/tests/assembly/x86-return-float.rs
index 2c39c830684..165c11d2280 100644
--- a/tests/assembly/x86-return-float.rs
+++ b/tests/assembly/x86-return-float.rs
@@ -35,6 +35,7 @@ use minicore::*;
 pub fn return_f32(x: f32) -> f32 {
     // CHECK: movss {{.*}}(%ebp), %xmm0
     // CHECK-NEXT: popl %ebp
+    // linux-NEXT: .cfi_def_cfa
     // CHECK-NEXT: retl
     x
 }
@@ -44,6 +45,7 @@ pub fn return_f32(x: f32) -> f32 {
 pub fn return_f64(x: f64) -> f64 {
     // CHECK: movsd {{.*}}(%ebp), %xmm0
     // CHECK-NEXT: popl %ebp
+    // linux-NEXT: .cfi_def_cfa
     // CHECK-NEXT: retl
     x
 }
@@ -313,9 +315,13 @@ pub unsafe fn call_other_f64(x: &mut (usize, f64)) {
 #[no_mangle]
 pub fn return_f16(x: f16) -> f16 {
     // CHECK: pushl %ebp
+    // linux-NEXT: .cfi_def_cfa_offset
+    // linux-NEXT: .cfi_offset
     // CHECK-NEXT: movl %esp, %ebp
+    // linux-NEXT: .cfi_def_cfa_register
     // CHECK-NEXT: pinsrw $0, 8(%ebp), %xmm0
     // CHECK-NEXT: popl %ebp
+    // linux-NEXT: .cfi_def_cfa
     // CHECK-NEXT: retl
     x
 }
@@ -324,10 +330,14 @@ pub fn return_f16(x: f16) -> f16 {
 #[no_mangle]
 pub fn return_f128(x: f128) -> f128 {
     // CHECK: pushl %ebp
+    // linux-NEXT: .cfi_def_cfa_offset
+    // linux-NEXT: .cfi_offset
     // CHECK-NEXT: movl %esp, %ebp
+    // linux-NEXT: .cfi_def_cfa_register
     // linux-NEXT: movaps 8(%ebp), %xmm0
     // win-NEXT: movups 8(%ebp), %xmm0
     // CHECK-NEXT: popl %ebp
+    // linux-NEXT: .cfi_def_cfa
     // CHECK-NEXT: retl
     x
 }