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 6f5bae3

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 6f5bae3

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed
 

‎builtins-test-intrinsics/build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ 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+
println!("cargo::rustc-link-arg=/ENTRY:mainCRTStartup");
14+
}
1115
}

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

+14-9
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,9 @@ fn run() {
626626

627627
something_with_a_dtor(&|| assert_eq!(bb(1), 1));
628628

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

@@ -648,15 +645,23 @@ fn something_with_a_dtor(f: &dyn Fn()) {
648645
}
649646

650647
#[no_mangle]
651-
#[cfg(not(thumb))]
652-
fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
648+
#[cfg(not(any(thumb, windows)))]
649+
extern "C" fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
650+
run();
651+
0
652+
}
653+
654+
#[no_mangle]
655+
#[cfg(windows)]
656+
#[allow(non_snake_case)]
657+
extern "C" fn mainCRTStartup() -> core::ffi::c_int {
653658
run();
654659
0
655660
}
656661

657662
#[no_mangle]
658663
#[cfg(thumb)]
659-
pub fn _start() -> ! {
664+
extern "C" fn _start() -> ! {
660665
run();
661666
loop {}
662667
}

‎ci/run.sh

+14-10
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,26 @@ 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+
if [ "${NO_STD:-}" = "1" ]; then
125+
cmd=build
126+
else
127+
cmd=run
128+
fi
129+
130+
cargo "$cmd" --target "$target" -v --package builtins-test-intrinsics "$@"
125131
}
126132

127133
# 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
134+
run_intrinsics_test
135+
run_intrinsics_test --release
136+
run_intrinsics_test --features c
137+
run_intrinsics_test --features c --release
132138

133139
# Verify that there are no undefined symbols to `panic` within our
134140
# 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
141+
CARGO_PROFILE_DEV_LTO=true run_intrinsics_test
142+
CARGO_PROFILE_RELEASE_LTO=true run_intrinsics_test --release
139143

140144
# Ensure no references to any symbols from core
141145
update_rlib_paths

0 commit comments

Comments
 (0)
Failed to load comments.