-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add __CxxFrameHandler3
in panic_abort
#83607
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
Changes from all commits
af7c540
9cdaea3
48acdb7
fc4bf6d
c162f8a
7a54baa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// run-fail | ||
// compile-flags: -C panic=abort -C target-feature=+crt-static | ||
// aux-build:exit-success-if-unwind-msvc-no-std.rs | ||
// only-msvc | ||
// Test that `no_std` with `panic=abort` under MSVC toolchain | ||
// doesn't cause error when linking to libcmt. | ||
// We don't run this executable because it will hang in `rust_begin_unwind` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we expect that this should actually run successfully? If the MSCRT is linked in statically, then we should be able to handle linking another crate which is compiled with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At first, I expect it fail because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I solved this problem now. It should be able to run and fail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should be changed then. |
||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
extern crate exit_success_if_unwind_msvc_no_std; | ||
|
||
#[link(name = "libcmt")] | ||
extern "C" {} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn main() -> i32 { | ||
exit_success_if_unwind_msvc_no_std::bar(do_panic); | ||
0 | ||
} | ||
|
||
fn do_panic() { | ||
panic!(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// run-fail | ||
// compile-flags: -C panic=abort | ||
// aux-build:exit-success-if-unwind-msvc-no-std.rs | ||
// only-msvc | ||
// Test that `no_std` with `panic=abort` under MSVC toolchain | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we also expect this to run successfully (even though it doesn't currently)? Since MSCRT is linked in? |
||
// doesn't cause error when linking to msvcrt. | ||
// We don't run this executable because it will hang in `rust_begin_unwind` | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
extern crate exit_success_if_unwind_msvc_no_std; | ||
|
||
#[link(name = "msvcrt")] | ||
extern "C" {} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn main() -> i32 { | ||
exit_success_if_unwind_msvc_no_std::bar(do_panic); | ||
0 | ||
} | ||
|
||
fn do_panic() { | ||
panic!(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// run-fail | ||
// compile-flags:-C panic=abort | ||
// aux-build:exit-success-if-unwind-msvc-no-std.rs | ||
// no-prefer-dynamic | ||
// only-msvc | ||
// We don't run this executable because it will hang in `rust_begin_unwind` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is wrong now |
||
|
||
#![no_std] | ||
#![no_main] | ||
#![windows_subsystem = "console"] | ||
#![feature(panic_abort)] | ||
|
||
extern crate exit_success_if_unwind_msvc_no_std; | ||
extern crate panic_abort; | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn memcpy(dest: *mut u8, _src: *const u8, _n: usize) -> *mut u8 { | ||
dest | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn memmove(dest: *mut u8, _src: *const u8, _n: usize) -> *mut u8 { | ||
dest | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn memset(mem: *mut u8, _val: i32, _n: usize) -> *mut u8 { | ||
mem | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn memcmp(_mem1: *const u8, _mem2: *const u8, _n: usize) -> i32 { | ||
0 | ||
} | ||
|
||
// Used by compiler_builtins | ||
#[no_mangle] | ||
#[used] | ||
static _fltused: i32 = 0; | ||
|
||
// MSVC always assumes that some functions are avaliable | ||
#[link(name = "ntdll")] | ||
extern "system" {} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn mainCRTStartup() { | ||
exit_success_if_unwind_msvc_no_std::bar(main); | ||
} | ||
|
||
fn main() { | ||
panic!(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// compile-flags:-C panic=unwind | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to add a comment explaining what this helper crate does at a high level. |
||
// no-prefer-dynamic | ||
|
||
#![no_std] | ||
#![crate_type = "rlib"] | ||
#![feature(core_intrinsics)] | ||
|
||
struct Bomb; | ||
|
||
impl Drop for Bomb { | ||
fn drop(&mut self) { | ||
#[link(name = "kernel32")] | ||
extern "system" { | ||
fn ExitProcess(code: u32) -> !; | ||
} | ||
unsafe { | ||
ExitProcess(0); | ||
} | ||
} | ||
} | ||
|
||
pub fn bar(f: fn()) { | ||
let _bomb = Bomb; | ||
f(); | ||
} | ||
|
||
use core::panic::PanicInfo; | ||
|
||
#[panic_handler] | ||
fn handle_panic(_: &PanicInfo) -> ! { | ||
core::intrinsics::abort(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// build-pass | ||
// compile-flags: -C panic=unwind -C target-feature=+crt-static | ||
// only-msvc | ||
// Test that `no_std` with `panic=unwind` under MSVC toolchain | ||
// doesn't cause error when linking to libcmt. | ||
|
||
#![no_std] | ||
#![no_main] | ||
#![feature(alloc_error_handler)] | ||
#![feature(panic_unwind)] | ||
|
||
use core::alloc::{GlobalAlloc, Layout}; | ||
|
||
struct DummyAllocator; | ||
|
||
unsafe impl GlobalAlloc for DummyAllocator { | ||
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 { | ||
core::ptr::null_mut() | ||
} | ||
|
||
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} | ||
} | ||
|
||
#[global_allocator] | ||
static ALLOC: DummyAllocator = DummyAllocator; | ||
|
||
#[alloc_error_handler] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for bringing in alloc? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason we're using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm only testing a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess I'm asking if testing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoughts here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean adding a test with |
||
fn rust_oom(_layout: Layout) -> ! { | ||
panic!() | ||
} | ||
|
||
extern crate panic_unwind; | ||
|
||
use core::panic::PanicInfo; | ||
|
||
#[panic_handler] | ||
fn handle_panic(_: &PanicInfo) -> ! { | ||
loop {} | ||
} | ||
|
||
#[link(name = "libcmt")] | ||
extern "C" {} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn main() -> i32 { | ||
panic!(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// build-pass | ||
// compile-flags: -C panic=unwind | ||
// only-msvc | ||
// Test that `no_std` with `panic=unwind` under MSVC toolchain | ||
// doesn't cause error when linking to msvcrt. | ||
|
||
#![no_std] | ||
#![no_main] | ||
#![feature(alloc_error_handler)] | ||
#![feature(panic_unwind)] | ||
|
||
use core::alloc::{GlobalAlloc, Layout}; | ||
|
||
struct DummyAllocator; | ||
|
||
unsafe impl GlobalAlloc for DummyAllocator { | ||
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 { | ||
core::ptr::null_mut() | ||
} | ||
|
||
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} | ||
} | ||
|
||
#[global_allocator] | ||
static ALLOC: DummyAllocator = DummyAllocator; | ||
|
||
#[alloc_error_handler] | ||
fn rust_oom(_layout: Layout) -> ! { | ||
panic!() | ||
} | ||
|
||
extern crate panic_unwind; | ||
|
||
use core::panic::PanicInfo; | ||
|
||
#[panic_handler] | ||
fn handle_panic(_: &PanicInfo) -> ! { | ||
loop {} | ||
} | ||
|
||
#[link(name = "msvcrt")] | ||
extern "C" {} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn main() -> i32 { | ||
panic!(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm slightly confused about
-C target-feature=+crt-static
. We're statically linking the crt but also dynamically linkinglibcmt
. Shouldn't we be testing on or the other.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libcmt
is the static C runtime library. It is a static library, though it should be linked dynamically. I just cannot tell why it needs dynamic linking. It should make no difference between dynamic linking and static linking.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+crt-static
will already linklibcmt
so there should be no reason to declare it manually.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right when using
libc
crate, but here we need to test underno_std
.