Skip to content

Commit c72f179

Browse files
committed
Move to global_asm, naked functions are too unstable
1 parent fdf9ad2 commit c72f179

File tree

6 files changed

+45
-65
lines changed

6 files changed

+45
-65
lines changed

unwind/src/glue/aarch64.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ use registers::{Registers, DwarfRegisterAArch64};
33

44
#[allow(improper_ctypes)] // trampoline just forwards the ptr
55
extern "C" {
6-
#[cfg(not(feature = "nightly"))]
76
pub fn unwind_trampoline(payload: *mut UnwindPayload);
8-
#[cfg(not(feature = "nightly"))]
97
fn unwind_lander(regs: *const LandingRegisters);
108
}
119

1210
#[cfg(feature = "nightly")]
13-
#[naked]
14-
pub unsafe extern fn unwind_trampoline(_payload: *mut UnwindPayload) {
15-
asm!("
11+
global_asm! {
12+
r#"
13+
.global unwind_trampoline
14+
unwind_trampoline:
15+
.cfi_startproc
1616
mov x1, sp
1717
sub sp, sp, 0xA0
1818
.cfi_adjust_cfa_offset 0xA0
@@ -34,14 +34,10 @@ pub unsafe extern fn unwind_trampoline(_payload: *mut UnwindPayload) {
3434
add sp, sp, 0xA0
3535
.cfi_adjust_cfa_offset -0xA0
3636
ret
37-
");
38-
::std::hint::unreachable_unchecked();
39-
}
37+
.cfi_endproc
4038
41-
#[cfg(feature = "nightly")]
42-
#[naked]
43-
unsafe extern fn unwind_lander(_regs: *const LandingRegisters) {
44-
asm!("
39+
.global unwind_lander
40+
unwind_lander:
4541
ldp x2, x3, [x0, #0x010]
4642
ldp x4, x5, [x0, #0x020]
4743
ldp x6, x7, [x0, #0x030]
@@ -78,8 +74,7 @@ unsafe extern fn unwind_lander(_regs: *const LandingRegisters) {
7874
7975
ldp x0, x1, [x0, #0x000]
8076
ret x30 // HYPERSPACE JUMP :D
81-
");
82-
::std::hint::unreachable_unchecked();
77+
"#
8378
}
8479

8580
#[repr(C)]

unwind/src/glue/x86_64.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,12 @@ use registers::{Registers, DwarfRegister};
33

44
#[allow(improper_ctypes)] // trampoline just forwards the ptr
55
extern "C" {
6-
#[cfg(not(feature = "nightly"))]
76
pub fn unwind_trampoline(payload: *mut UnwindPayload);
8-
#[cfg(not(feature = "nightly"))]
97
fn unwind_lander(regs: *const LandingRegisters);
108
}
119

1210
#[cfg(feature = "nightly")]
13-
#[naked]
14-
pub unsafe extern fn unwind_trampoline(_payload: *mut UnwindPayload) {
15-
asm!(include_str!("x86_64_trampoline.S"));
16-
::std::hint::unreachable_unchecked();
17-
}
18-
19-
#[cfg(feature = "nightly")]
20-
#[naked]
21-
unsafe extern fn unwind_lander(_regs: *const LandingRegisters) {
22-
asm!(include_str!("x86_64_lander.S"));
23-
::std::hint::unreachable_unchecked();
24-
}
11+
global_asm!(include_str!("x86_64_helper.S"));
2512

2613
#[repr(C)]
2714
struct LandingRegisters {

unwind/src/glue/x86_64_helper.S

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
11
.global unwind_trampoline
22
unwind_trampoline:
33
.cfi_startproc
4-
.include "x86_64_trampoline.S"
4+
movq %rsp, %rsi
5+
.cfi_def_cfa rsi, 8
6+
pushq %rbp
7+
.cfi_offset rbp, -16
8+
pushq %rbx
9+
pushq %r12
10+
pushq %r13
11+
pushq %r14
12+
pushq %r15
13+
movq %rsp, %rdx
14+
subq $0x08, %rsp
15+
.cfi_def_cfa rsp, 0x40
16+
call unwind_recorder
17+
addq $0x38, %rsp
18+
.cfi_def_cfa rsp, 8
19+
ret
520
.cfi_endproc
621

722
.global unwind_lander
823
unwind_lander:
9-
.include "x86_64_lander.S"
24+
movq %rdi, %rsp
25+
popq %rax
26+
popq %rbx
27+
popq %rcx
28+
popq %rdx
29+
popq %rdi
30+
popq %rsi
31+
popq %rbp
32+
popq %r8
33+
popq %r9
34+
popq %r10
35+
popq %r11
36+
popq %r12
37+
popq %r13
38+
popq %r14
39+
popq %r15
40+
movq 0(%rsp), %rsp
41+
ret /* HYPERSPACE JUMP :D */

unwind/src/glue/x86_64_lander.S

Lines changed: 0 additions & 18 deletions
This file was deleted.

unwind/src/glue/x86_64_trampoline.S

Lines changed: 0 additions & 16 deletions
This file was deleted.

unwind/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(feature = "nightly", feature(asm, naked_functions))]
1+
#![cfg_attr(feature = "nightly", feature(global_asm))]
22

33
extern crate gimli;
44
extern crate libc;

0 commit comments

Comments
 (0)