From 77232fb9350dbe09821df27f184301475829f1e4 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 24 Jun 2025 09:00:20 +0000 Subject: [PATCH 1/3] Fix normalization in linker-warning Ensure rustc_codegen_cranelift doesn't get normalized to rustc. And handle -Cpanic=abort. --- .../scripts/test_rustc_tests.sh | 14 -------------- tests/run-make/linker-warning/rmake.rs | 3 ++- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh b/compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh index 32c71f433b0ff..7e356b4b462b2 100755 --- a/compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh +++ b/compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh @@ -151,20 +151,6 @@ rm tests/ui/process/process-panic-after-fork.rs # same cp ../dist/bin/rustdoc-clif ../dist/bin/rustdoc # some tests expect bin/rustdoc to exist cat < Date: Tue, 24 Jun 2025 09:03:16 +0000 Subject: [PATCH 2/3] Fix function signature for rust_eh_personality While cg_llvm is very lax about mismatched function signatures, cg_clif will crash when there is any mismatch. It could be turned into an error, but without Cranelift changes can't just be ignored. --- tests/run-make/bin-emit-no-symbols/app.rs | 10 +++++++++- tests/run-make/crate-circular-deps-link/a.rs | 8 +++++++- tests/run-make/no-alloc-shim/foo.rs | 8 +++++++- .../ui/allocator/no_std-alloc-error-handler-custom.rs | 10 +++++++++- .../ui/allocator/no_std-alloc-error-handler-default.rs | 10 +++++++++- tests/ui/extern-flag/auxiliary/panic_handler.rs | 10 +++++++++- tests/ui/panic-runtime/incompatible-type.rs | 10 +++++++++- 7 files changed, 59 insertions(+), 7 deletions(-) diff --git a/tests/run-make/bin-emit-no-symbols/app.rs b/tests/run-make/bin-emit-no-symbols/app.rs index e9dc1e9744fb1..ad74fcc43dce9 100644 --- a/tests/run-make/bin-emit-no-symbols/app.rs +++ b/tests/run-make/bin-emit-no-symbols/app.rs @@ -12,7 +12,15 @@ fn panic(_: &PanicInfo) -> ! { } #[lang = "eh_personality"] -fn eh() {} +fn eh( + _version: i32, + _actions: i32, + _exception_class: u64, + _exception_object: *mut (), + _context: *mut (), +) -> i32 { + loop {} +} #[alloc_error_handler] fn oom(_: Layout) -> ! { diff --git a/tests/run-make/crate-circular-deps-link/a.rs b/tests/run-make/crate-circular-deps-link/a.rs index a54f429550e74..99b2b65049de8 100644 --- a/tests/run-make/crate-circular-deps-link/a.rs +++ b/tests/run-make/crate-circular-deps-link/a.rs @@ -21,6 +21,12 @@ extern "C" fn __rust_foreign_exception() -> ! { } #[lang = "eh_personality"] -fn eh_personality() { +fn eh_personality( + _version: i32, + _actions: i32, + _exception_class: u64, + _exception_object: *mut (), + _context: *mut (), +) -> i32 { loop {} } diff --git a/tests/run-make/no-alloc-shim/foo.rs b/tests/run-make/no-alloc-shim/foo.rs index b5d0d394d2b9f..a22307f41b39e 100644 --- a/tests/run-make/no-alloc-shim/foo.rs +++ b/tests/run-make/no-alloc-shim/foo.rs @@ -12,7 +12,13 @@ fn panic_handler(_: &core::panic::PanicInfo) -> ! { } #[no_mangle] -extern "C" fn rust_eh_personality() { +extern "C" fn rust_eh_personality( + _version: i32, + _actions: i32, + _exception_class: u64, + _exception_object: *mut (), + _context: *mut (), +) -> i32 { loop {} } diff --git a/tests/ui/allocator/no_std-alloc-error-handler-custom.rs b/tests/ui/allocator/no_std-alloc-error-handler-custom.rs index 6bbfb72510d0f..5b232e667a04e 100644 --- a/tests/ui/allocator/no_std-alloc-error-handler-custom.rs +++ b/tests/ui/allocator/no_std-alloc-error-handler-custom.rs @@ -70,7 +70,15 @@ fn panic(panic_info: &core::panic::PanicInfo) -> ! { // in these libraries will refer to `rust_eh_personality` if LLVM can not *prove* the contents won't // unwind. So, for this test case we will define the symbol. #[lang = "eh_personality"] -extern "C" fn rust_eh_personality() {} +extern "C" fn rust_eh_personality( + _version: i32, + _actions: i32, + _exception_class: u64, + _exception_object: *mut (), + _context: *mut (), +) -> i32 { + loop {} +} #[derive(Default, Debug)] struct Page(#[allow(dead_code)] [[u64; 32]; 16]); diff --git a/tests/ui/allocator/no_std-alloc-error-handler-default.rs b/tests/ui/allocator/no_std-alloc-error-handler-default.rs index 8bcf054ac85f5..b9289d9fb81df 100644 --- a/tests/ui/allocator/no_std-alloc-error-handler-default.rs +++ b/tests/ui/allocator/no_std-alloc-error-handler-default.rs @@ -57,7 +57,15 @@ fn panic(panic_info: &core::panic::PanicInfo) -> ! { // in these libraries will refer to `rust_eh_personality` if LLVM can not *prove* the contents won't // unwind. So, for this test case we will define the symbol. #[lang = "eh_personality"] -extern "C" fn rust_eh_personality() {} +extern "C" fn rust_eh_personality( + _version: i32, + _actions: i32, + _exception_class: u64, + _exception_object: *mut (), + _context: *mut (), +) -> i32 { + loop {} +} #[derive(Default, Debug)] struct Page(#[allow(dead_code)] [[u64; 32]; 16]); diff --git a/tests/ui/extern-flag/auxiliary/panic_handler.rs b/tests/ui/extern-flag/auxiliary/panic_handler.rs index 9140ceed22914..9607f0ed0139e 100644 --- a/tests/ui/extern-flag/auxiliary/panic_handler.rs +++ b/tests/ui/extern-flag/auxiliary/panic_handler.rs @@ -12,4 +12,12 @@ pub fn begin_panic_handler(_info: &core::panic::PanicInfo<'_>) -> ! { } #[lang = "eh_personality"] -extern "C" fn eh_personality() {} +extern "C" fn eh_personality( + _version: i32, + _actions: i32, + _exception_class: u64, + _exception_object: *mut (), + _context: *mut (), +) -> i32 { + loop {} +} diff --git a/tests/ui/panic-runtime/incompatible-type.rs b/tests/ui/panic-runtime/incompatible-type.rs index 4cbcfec11c96c..f82c23d68c2c7 100644 --- a/tests/ui/panic-runtime/incompatible-type.rs +++ b/tests/ui/panic-runtime/incompatible-type.rs @@ -21,4 +21,12 @@ pub fn test(_: DropMe) { } #[rustc_std_internal_symbol] -pub unsafe extern "C" fn rust_eh_personality() {} +pub unsafe extern "C" fn rust_eh_personality( + _version: i32, + _actions: i32, + _exception_class: u64, + _exception_object: *mut (), + _context: *mut (), +) -> i32 { + loop {} +} From 659da5843bd0c176c47ca190d2b1cfaa690ffa09 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 24 Jun 2025 09:04:36 +0000 Subject: [PATCH 3/3] Fix a bunch of missing unwinder related definitions cg_llvm likely just optimizes out their references for these tests, but cg_clif doesn't and would thus give a linker error. --- .../allocator/no_std-alloc-error-handler-custom.rs | 3 ++- .../allocator/no_std-alloc-error-handler-default.rs | 3 ++- tests/ui/no_std/simple-runs.rs | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/ui/allocator/no_std-alloc-error-handler-custom.rs b/tests/ui/allocator/no_std-alloc-error-handler-custom.rs index 5b232e667a04e..1b0f0608fc61b 100644 --- a/tests/ui/allocator/no_std-alloc-error-handler-custom.rs +++ b/tests/ui/allocator/no_std-alloc-error-handler-custom.rs @@ -6,13 +6,14 @@ //@ compile-flags:-C panic=abort //@ aux-build:helper.rs -#![feature(rustc_private, lang_items)] +#![feature(rustc_private, lang_items, panic_unwind)] #![feature(alloc_error_handler)] #![no_std] #![no_main] extern crate alloc; extern crate libc; +extern crate unwind; // For _Unwind_Resume // ARM targets need these symbols #[no_mangle] diff --git a/tests/ui/allocator/no_std-alloc-error-handler-default.rs b/tests/ui/allocator/no_std-alloc-error-handler-default.rs index b9289d9fb81df..51ecf1a6731ac 100644 --- a/tests/ui/allocator/no_std-alloc-error-handler-default.rs +++ b/tests/ui/allocator/no_std-alloc-error-handler-default.rs @@ -6,12 +6,13 @@ //@ compile-flags:-C panic=abort //@ aux-build:helper.rs -#![feature(rustc_private, lang_items)] +#![feature(rustc_private, lang_items, panic_unwind)] #![no_std] #![no_main] extern crate alloc; extern crate libc; +extern crate unwind; // For _Unwind_Resume // ARM targets need these symbols #[no_mangle] diff --git a/tests/ui/no_std/simple-runs.rs b/tests/ui/no_std/simple-runs.rs index 8931ac7ed11be..af44dfec311ed 100644 --- a/tests/ui/no_std/simple-runs.rs +++ b/tests/ui/no_std/simple-runs.rs @@ -4,6 +4,7 @@ //@ compile-flags: -Cpanic=abort //@ ignore-wasm different `main` convention +#![feature(lang_items)] #![no_std] #![no_main] @@ -35,6 +36,17 @@ fn panic_handler(_info: &PanicInfo<'_>) -> ! { loop {} } +#[lang = "eh_personality"] +extern "C" fn rust_eh_personality( + _version: i32, + _actions: i32, + _exception_class: u64, + _exception_object: *mut (), + _context: *mut (), +) -> i32 { + loop {} +} + #[no_mangle] extern "C" fn main(_argc: c_int, _argv: *const *const c_char) -> c_int { 0