Skip to content

Commit 9cdaea3

Browse files
committed
Add tests for abort link to unwind.
1 parent af7c540 commit 9cdaea3

4 files changed

+142
-0
lines changed
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+
}

0 commit comments

Comments
 (0)