Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't call rust_begin_unwind #802

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions builtins-test-intrinsics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ publish = false
compiler_builtins = { path = "../", features = ["compiler-builtins"]}
panic-handler = { path = '../crates/panic-handler' }

[target.'cfg(target_family = "windows")'.dependencies]
# `#![no_std]` on Windows needs `string.h` routines.
compiler_builtins = { path = "../", features = ["compiler-builtins", "mem"]}

[features]
c = ["compiler_builtins/c"]
5 changes: 5 additions & 0 deletions builtins-test-intrinsics/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ fn main() {
let target = builtins_configure::Target::from_env();
builtins_configure::configure_f16_f128(&target);
builtins_configure::configure_aliases(&target);

if target.os == "windows" {
// Needed for using the `mainCRTStartup` entrypoint
println!("cargo::rustc-link-arg=/subsystem:console");
}
}
45 changes: 31 additions & 14 deletions builtins-test-intrinsics/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#![no_std]
#![no_main]

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

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

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

extern "C" {
fn rust_begin_unwind(x: usize);
}

unsafe {
rust_begin_unwind(0);
// Ensure panic machinery gets linked, but still allow this to run to completion.
// FIXME(windows): we should have this on Windows too but it requires a lot more
// missing symbols.
#[cfg(not(windows))]
if bb(false) {
panic!();
}
}

Expand All @@ -648,15 +651,23 @@ fn something_with_a_dtor(f: &dyn Fn()) {
}

#[no_mangle]
#[cfg(not(thumb))]
fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
#[cfg(not(any(thumb, windows)))]
extern "C" fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
run();
0
}

#[no_mangle]
#[cfg(windows)]
#[allow(non_snake_case)]
extern "C" fn mainCRTStartup() -> core::ffi::c_int {
run();
0
}

#[no_mangle]
#[cfg(thumb)]
pub fn _start() -> ! {
extern "C" fn _start() -> ! {
run();
loop {}
}
Expand All @@ -673,15 +684,21 @@ pub fn __aeabi_unwind_cpp_pr0() {}
#[no_mangle]
pub fn __aeabi_unwind_cpp_pr1() {}

#[cfg(not(any(windows, target_os = "cygwin")))]
#[allow(non_snake_case)]
#[no_mangle]
#[allow(non_snake_case)]
#[cfg(not(any(windows, target_os = "cygwin")))]
pub fn _Unwind_Resume() {}

#[cfg(not(any(windows, target_os = "cygwin")))]
#[lang = "eh_personality"]
#[no_mangle]
pub extern "C" fn eh_personality() {}
#[lang = "eh_personality"]
#[cfg(not(any(windows, target_os = "cygwin")))]
pub extern "system" fn eh_personality() {}

#[cfg(windows)]
#[unsafe(no_mangle)]
extern "system" fn __CxxFrameHandler3() -> ! {
unimplemented!()
}

#[cfg(any(all(windows, target_env = "gnu"), target_os = "cygwin"))]
mod mingw_unwinding {
Expand Down
26 changes: 16 additions & 10 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,28 @@ done

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

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

cargo "$cmd" --target "$target" -v --package builtins-test-intrinsics "$@"
}

# Verify that we haven't dropped any intrinsics/symbols
build_intrinsics_test
build_intrinsics_test --release
build_intrinsics_test --features c
build_intrinsics_test --features c --release
run_intrinsics_test
run_intrinsics_test --release
run_intrinsics_test --features c
run_intrinsics_test --features c --release

# Verify that there are no undefined symbols to `panic` within our
# implementations
CARGO_PROFILE_DEV_LTO=true \
cargo build --target "$target" --package builtins-test-intrinsics
CARGO_PROFILE_RELEASE_LTO=true \
cargo build --target "$target" --package builtins-test-intrinsics --release
CARGO_PROFILE_DEV_LTO=true run_intrinsics_test
CARGO_PROFILE_RELEASE_LTO=true run_intrinsics_test --release

# Ensure no references to any symbols from core
update_rlib_paths
Expand Down
Loading