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 3484bab

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 3484bab

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed
 

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

+12-7
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,12 +645,20 @@ fn something_with_a_dtor(f: &dyn Fn()) {
648645
}
649646

650647
#[no_mangle]
651-
#[cfg(not(thumb))]
648+
#[cfg(not(any(thumb, windows)))]
652649
fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
653650
run();
654651
0
655652
}
656653

654+
#[no_mangle]
655+
#[cfg(windows)]
656+
#[allow(non_snake_case)]
657+
fn mainCRTStartup() -> core::ffi::c_int {
658+
run();
659+
0
660+
}
661+
657662
#[no_mangle]
658663
#[cfg(thumb)]
659664
pub fn _start() -> ! {

‎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.