Skip to content

Commit 9bcdc06

Browse files
committed
Use a global_asm! instead of a naked function
1 parent bc314ab commit 9bcdc06

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/libpanic_unwind/gcc.rs

+24-8
Original file line numberDiff line numberDiff line change
@@ -326,22 +326,38 @@ unsafe fn find_eh_action(
326326

327327
// See docs in the `unwind` module.
328328
#[cfg(all(
329+
not(bootstrap),
330+
target_os = "windows",
331+
any(target_arch = "x86", target_arch = "x86_64"),
332+
target_env = "gnu"
333+
))]
334+
global_asm! {
335+
r#"
336+
.def _rust_eh_unwind_resume;
337+
.scl 2;
338+
.type 32;
339+
.endef
340+
.globl _rust_eh_unwind_resume
341+
.p2align 4, 0x90
342+
_rust_eh_unwind_resume:
343+
.cfi_startproc
344+
jmp __Unwind_Resume
345+
.cfi_endproc
346+
"#
347+
}
348+
#[cfg(all(
349+
bootstrap,
329350
target_os = "windows",
330351
any(target_arch = "x86", target_arch = "x86_64"),
331352
target_env = "gnu"
332353
))]
333354
#[lang = "eh_unwind_resume"]
334355
#[unwind(allowed)]
335-
#[naked]
336-
#[inline(never)]
337-
unsafe extern "C" fn rust_eh_unwind_resume(_panic_ctx: *mut u8) -> ! {
338-
// This needs to be a naked function because _Unwind_Resume expects to be
339-
// called directly from the landing pad. This means that we need to force
340-
// a tail call here.
341-
asm!("jmp ${0:P}" :: "s" (uw::_Unwind_Resume as usize) :: "volatile");
342-
core::hint::unreachable_unchecked();
356+
unsafe extern "C" fn rust_eh_unwind_resume(panic_ctx: *mut u8) -> ! {
357+
uw::_Unwind_Resume(panic_ctx as *mut uw::_Unwind_Exception);
343358
}
344359

360+
345361
// Frame unwind info registration
346362
//
347363
// Each module's image contains a frame unwind info section (usually

src/libpanic_unwind/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#![feature(naked_functions)]
3333
#![panic_runtime]
3434
#![feature(panic_runtime)]
35+
#![feature(global_asm)]
3536

3637
use alloc::boxed::Box;
3738
use core::any::Any;

0 commit comments

Comments
 (0)