Skip to content

Commit 063fe40

Browse files
authored
Rollup merge of rust-lang#83607 - Berrysoft:master, r=nagisa
Add `__CxxFrameHandler3` in `panic_abort` Fix rust-lang#54137 <del>I initially tried to forward to `__CxxFrameHandler3` from `rust_eh_personality`, but later I found that LLVM uses handler names to distinguish exception type. Therefore I choose to add `__CxxFrameHandler3` in `panic_abort`. Anyway it solves the link problem, and this function will never be called.</del> It seems that the original issue was solved, but still adding these tests.
2 parents 9decf14 + 48acdb7 commit 063fe40

7 files changed

+249
-0
lines changed

library/panic_abort/src/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ pub mod personalities {
116116
)))]
117117
pub extern "C" fn rust_eh_personality() {}
118118

119+
// On *-pc-windows-msvc we need such a symbol to make linker happy.
120+
#[allow(non_snake_case)]
121+
#[no_mangle]
122+
#[cfg(all(target_os = "windows", target_env = "msvc"))]
123+
pub extern "C" fn __CxxFrameHandler3(
124+
_record: usize,
125+
_frame: usize,
126+
_context: usize,
127+
_dispatcher: usize,
128+
) -> u32 {
129+
1
130+
}
131+
119132
// On x86_64-pc-windows-gnu we use our own personality function that needs
120133
// to return `ExceptionContinueSearch` as we're passing on all our frames.
121134
#[rustc_std_internal_symbol]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// build-pass
2+
// compile-flags: -C panic=abort -C target-feature=+crt-static
3+
// aux-build:exit-success-if-unwind-msvc-no-std.rs
4+
// only-msvc
5+
// Test that `no_std` with `panic=abort` under MSVC toolchain
6+
// doesn't cause error when linking to libcmt.
7+
// We don't run this executable because it will hang in `rust_begin_unwind`
8+
9+
#![no_std]
10+
#![no_main]
11+
12+
extern crate exit_success_if_unwind_msvc_no_std;
13+
14+
use core::panic::PanicInfo;
15+
16+
#[panic_handler]
17+
fn handle_panic(_: &PanicInfo) -> ! {
18+
loop {}
19+
}
20+
21+
#[link(name = "libcmt")]
22+
extern "C" {}
23+
24+
#[no_mangle]
25+
pub extern "C" fn main() -> i32 {
26+
exit_success_if_unwind_msvc_no_std::bar(do_panic);
27+
0
28+
}
29+
30+
fn do_panic() {
31+
panic!();
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// build-pass
2+
// compile-flags: -C panic=abort
3+
// aux-build:exit-success-if-unwind-msvc-no-std.rs
4+
// only-msvc
5+
// Test that `no_std` with `panic=abort` under MSVC toolchain
6+
// doesn't cause error when linking to msvcrt.
7+
// We don't run this executable because it will hang in `rust_begin_unwind`
8+
9+
#![no_std]
10+
#![no_main]
11+
12+
extern crate exit_success_if_unwind_msvc_no_std;
13+
14+
use core::panic::PanicInfo;
15+
16+
#[panic_handler]
17+
fn handle_panic(_: &PanicInfo) -> ! {
18+
loop {}
19+
}
20+
21+
#[link(name = "msvcrt")]
22+
extern "C" {}
23+
24+
#[no_mangle]
25+
pub extern "C" fn main() -> i32 {
26+
exit_success_if_unwind_msvc_no_std::bar(do_panic);
27+
0
28+
}
29+
30+
fn do_panic() {
31+
panic!();
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// build-pass
2+
// compile-flags:-C panic=abort
3+
// aux-build:exit-success-if-unwind-msvc-no-std.rs
4+
// no-prefer-dynamic
5+
// only-msvc
6+
// We don't run this executable because it will hang in `rust_begin_unwind`
7+
8+
#![no_std]
9+
#![no_main]
10+
#![windows_subsystem = "console"]
11+
#![feature(panic_abort)]
12+
13+
extern crate exit_success_if_unwind_msvc_no_std;
14+
extern crate panic_abort;
15+
16+
use core::panic::PanicInfo;
17+
18+
#[panic_handler]
19+
fn handle_panic(_: &PanicInfo) -> ! {
20+
loop {}
21+
}
22+
23+
#[no_mangle]
24+
pub unsafe extern "C" fn memcpy(dest: *mut u8, _src: *const u8, _n: usize) -> *mut u8 {
25+
dest
26+
}
27+
28+
#[no_mangle]
29+
pub unsafe extern "C" fn memmove(dest: *mut u8, _src: *const u8, _n: usize) -> *mut u8 {
30+
dest
31+
}
32+
33+
#[no_mangle]
34+
pub unsafe extern "C" fn memset(mem: *mut u8, _val: i32, _n: usize) -> *mut u8 {
35+
mem
36+
}
37+
38+
#[no_mangle]
39+
pub unsafe extern "C" fn memcmp(_mem1: *const u8, _mem2: *const u8, _n: usize) -> i32 {
40+
0
41+
}
42+
43+
#[no_mangle]
44+
#[used]
45+
static _fltused: i32 = 0;
46+
47+
#[no_mangle]
48+
pub extern "C" fn mainCRTStartup() {
49+
exit_success_if_unwind_msvc_no_std::bar(main);
50+
}
51+
52+
fn main() {
53+
panic!();
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// compile-flags:-C panic=unwind
2+
// no-prefer-dynamic
3+
4+
#![no_std]
5+
#![crate_type = "rlib"]
6+
7+
struct Bomb;
8+
9+
impl Drop for Bomb {
10+
fn drop(&mut self) {
11+
#[link(name = "kernel32")]
12+
extern "C" {
13+
fn ExitProcess(code: u32) -> !;
14+
}
15+
unsafe {
16+
ExitProcess(0);
17+
}
18+
}
19+
}
20+
21+
pub fn bar(f: fn()) {
22+
let _bomb = Bomb;
23+
f();
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// build-pass
2+
// compile-flags: -C panic=unwind -C target-feature=+crt-static
3+
// only-msvc
4+
// Test that `no_std` with `panic=unwind` under MSVC toolchain
5+
// doesn't cause error when linking to libcmt.
6+
7+
#![no_std]
8+
#![no_main]
9+
#![feature(alloc_error_handler)]
10+
#![feature(panic_unwind)]
11+
12+
use core::alloc::{GlobalAlloc, Layout};
13+
14+
struct DummyAllocator;
15+
16+
unsafe impl GlobalAlloc for DummyAllocator {
17+
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
18+
core::ptr::null_mut()
19+
}
20+
21+
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {}
22+
}
23+
24+
#[global_allocator]
25+
static ALLOC: DummyAllocator = DummyAllocator;
26+
27+
#[alloc_error_handler]
28+
fn rust_oom(_layout: Layout) -> ! {
29+
panic!()
30+
}
31+
32+
extern crate panic_unwind;
33+
34+
use core::panic::PanicInfo;
35+
36+
#[panic_handler]
37+
fn handle_panic(_: &PanicInfo) -> ! {
38+
loop {}
39+
}
40+
41+
#[link(name = "libcmt")]
42+
extern "C" {}
43+
44+
#[no_mangle]
45+
pub extern "C" fn main() -> i32 {
46+
panic!();
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// build-pass
2+
// compile-flags: -C panic=unwind
3+
// only-msvc
4+
// Test that `no_std` with `panic=unwind` under MSVC toolchain
5+
// doesn't cause error when linking to msvcrt.
6+
7+
#![no_std]
8+
#![no_main]
9+
#![feature(alloc_error_handler)]
10+
#![feature(panic_unwind)]
11+
12+
use core::alloc::{GlobalAlloc, Layout};
13+
14+
struct DummyAllocator;
15+
16+
unsafe impl GlobalAlloc for DummyAllocator {
17+
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
18+
core::ptr::null_mut()
19+
}
20+
21+
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {}
22+
}
23+
24+
#[global_allocator]
25+
static ALLOC: DummyAllocator = DummyAllocator;
26+
27+
#[alloc_error_handler]
28+
fn rust_oom(_layout: Layout) -> ! {
29+
panic!()
30+
}
31+
32+
extern crate panic_unwind;
33+
34+
use core::panic::PanicInfo;
35+
36+
#[panic_handler]
37+
fn handle_panic(_: &PanicInfo) -> ! {
38+
loop {}
39+
}
40+
41+
#[link(name = "msvcrt")]
42+
extern "C" {}
43+
44+
#[no_mangle]
45+
pub extern "C" fn main() -> i32 {
46+
panic!();
47+
}

0 commit comments

Comments
 (0)