Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3ed644a

Browse files
committedMar 19, 2025
Don't call rust_begin_unwind directly
`builtins-test-intrinsics` has long included a call to an unmangled `rust_begin_unwind` (the name `rustc` gives the `#[panic_handler]`), since [1], which I believe was intended to ensure panic machinery links correctly. However, since [2], `rust_begin_unwind` is mangled and unavailable for calling directly, which explains the recent CI failures. Instead of calling the function directly, we can just panic; do so here. Additionally, put this call behind `black_box(false)` rather than unconditional, which means we can run the binary and ensure there are no runtime issues. [1]: rust-lang#360 [2]: rust-lang/rust#127173
1 parent 45007cc commit 3ed644a

File tree

3 files changed

+39
-20
lines changed

3 files changed

+39
-20
lines changed
 

‎builtins-test-intrinsics/build.rs

+5
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ fn main() {
88
let target = builtins_configure::Target::from_env();
99
builtins_configure::configure_f16_f128(&target);
1010
builtins_configure::configure_aliases(&target);
11+
12+
if target.os == "windows" {
13+
// Needed for using the `mainCRTStartup` entrypoint
14+
println!("cargo::rustc-link-arg=/subsystem:console");
15+
}
1116
}

‎builtins-test-intrinsics/src/main.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#![no_std]
1414
#![no_main]
1515

16+
// Ensure this repo's version of `compiler_builtins` gets used, rather than what gets injected from
17+
// the sysroot.
18+
extern crate compiler_builtins;
1619
extern crate panic_handler;
1720

1821
#[cfg(all(not(thumb), not(windows), not(target_arch = "wasm32")))]
@@ -626,12 +629,9 @@ fn run() {
626629

627630
something_with_a_dtor(&|| assert_eq!(bb(1), 1));
628631

629-
extern "C" {
630-
fn rust_begin_unwind(x: usize);
631-
}
632-
633-
unsafe {
634-
rust_begin_unwind(0);
632+
// Ensure panic machinery gets linked, but still allow this to run to completion.
633+
if bb(false) {
634+
panic!();
635635
}
636636
}
637637

@@ -648,15 +648,23 @@ fn something_with_a_dtor(f: &dyn Fn()) {
648648
}
649649

650650
#[no_mangle]
651-
#[cfg(not(thumb))]
652-
fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
651+
#[cfg(not(any(thumb, windows)))]
652+
extern "C" fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
653+
run();
654+
0
655+
}
656+
657+
#[no_mangle]
658+
#[cfg(windows)]
659+
#[allow(non_snake_case)]
660+
extern "C" fn mainCRTStartup() -> core::ffi::c_int {
653661
run();
654662
0
655663
}
656664

657665
#[no_mangle]
658666
#[cfg(thumb)]
659-
pub fn _start() -> ! {
667+
extern "C" fn _start() -> ! {
660668
run();
661669
loop {}
662670
}
@@ -681,7 +689,7 @@ pub fn _Unwind_Resume() {}
681689
#[cfg(not(any(windows, target_os = "cygwin")))]
682690
#[lang = "eh_personality"]
683691
#[no_mangle]
684-
pub extern "C" fn eh_personality() {}
692+
pub extern "system" fn eh_personality() {}
685693

686694
#[cfg(any(all(windows, target_env = "gnu"), target_os = "cygwin"))]
687695
mod mingw_unwinding {

‎ci/run.sh

+16-10
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,28 @@ done
120120

121121
rm -f "${rlib_paths[@]}"
122122

123-
build_intrinsics_test() {
124-
cargo build --target "$target" -v --package builtins-test-intrinsics "$@"
123+
run_intrinsics_test() {
124+
# FIXME(windows): We should be able to run this test on Windows too, but it
125+
# seems to run into a lot more missing symbols.
126+
if [[ "${NO_STD:-}" = "1" || "$target" == *"windows" ]]; then
127+
cmd=build
128+
else
129+
cmd=run
130+
fi
131+
132+
cargo "$cmd" --target "$target" -v --package builtins-test-intrinsics "$@"
125133
}
126134

127135
# Verify that we haven't dropped any intrinsics/symbols
128-
build_intrinsics_test
129-
build_intrinsics_test --release
130-
build_intrinsics_test --features c
131-
build_intrinsics_test --features c --release
136+
run_intrinsics_test
137+
run_intrinsics_test --release
138+
run_intrinsics_test --features c
139+
run_intrinsics_test --features c --release
132140

133141
# Verify that there are no undefined symbols to `panic` within our
134142
# implementations
135-
CARGO_PROFILE_DEV_LTO=true \
136-
cargo build --target "$target" --package builtins-test-intrinsics
137-
CARGO_PROFILE_RELEASE_LTO=true \
138-
cargo build --target "$target" --package builtins-test-intrinsics --release
143+
CARGO_PROFILE_DEV_LTO=true run_intrinsics_test
144+
CARGO_PROFILE_RELEASE_LTO=true run_intrinsics_test --release
139145

140146
# Ensure no references to any symbols from core
141147
update_rlib_paths

0 commit comments

Comments
 (0)
Failed to load comments.