Skip to content
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

Add support for environments with the FPU disabled #25

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 59 additions & 30 deletions src/unwinder/arch/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,18 @@ impl ops::IndexMut<gimli::Register> for Context {
}
}

#[naked]
pub extern "C-unwind" fn save_context(f: extern "C" fn(&mut Context, *mut ()), ptr: *mut ()) {
// No need to save caller-saved registers here.
unsafe {
macro_rules! save {
(gp$(, $fp:ident)?) => {
// No need to save caller-saved registers here.
asm!(
"
stp x29, x30, [sp, -16]!
sub sp, sp, 512
mov x8, x0
mov x0, sp

stp d8, d9, [sp, 0x140]
stp d10, d11, [sp, 0x150]
stp d12, d13, [sp, 0x160]
stp d14, d15, [sp, 0x170]

",
save!(maybesavefp($($fp)?)),
"
str x19, [sp, 0x98]
stp x20, x21, [sp, 0xA0]
stp x22, x23, [sp, 0xB0]
Expand All @@ -91,30 +87,33 @@ pub extern "C-unwind" fn save_context(f: extern "C" fn(&mut Context, *mut ()), p
",
options(noreturn)
);
}
};
(maybesavefp(fp)) => {
"
stp d8, d9, [sp, 0x140]
stp d10, d11, [sp, 0x150]
stp d12, d13, [sp, 0x160]
stp d14, d15, [sp, 0x170]
"
};
(maybesavefp()) => { "" };
}

pub unsafe fn restore_context(ctx: &Context) -> ! {
#[naked]
pub extern "C-unwind" fn save_context(f: extern "C" fn(&mut Context, *mut ()), ptr: *mut ()) {
unsafe {
#[cfg(target_feature = "fp-armv8")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK there is no such a target feature in aarch64 (at least on the Rust side):

$ rustc +nightly --print cfg --target aarch64-unknown-linux-gnu | grep target_feature
target_feature="neon"
$ rustc +nightly --print cfg --target aarch64-unknown-none | grep target_feature
target_feature="neon"
$ rustc +nightly --print cfg --target aarch64-unknown-none-softfloat | grep target_feature

https://github.com/rust-lang/rust/blob/b5b13568fb5da4ac988bde370008d6134d3dfe6c/compiler/rustc_target/src/target_features.rs#L87

arm has it though: https://github.com/rust-lang/rust/blob/b5b13568fb5da4ac988bde370008d6134d3dfe6c/compiler/rustc_target/src/target_features.rs#L62

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, weird—the error when I tried to use unwinding mentioned fp-armv8 explicitly. I'll fix that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more clear: when I tried to use the current unwinding master branch on aarch64-unknown-none-softfloat, I got a compile error saying that the registers d[n] require target feature fp-armv8. This is likely a diagnostic issue, and I'll see if I can reproduce it to send that over to rustc.

save!(gp, fp);
#[cfg(not(target_feature = "fp-armv8"))]
save!(gp);
}
}

macro_rules! restore {
($ctx:expr, gp$(, $fp:ident)?) => {
asm!(
restore!(mayberestore($($fp)?)),
"
ldp d0, d1, [x0, 0x100]
ldp d2, d3, [x0, 0x110]
ldp d4, d5, [x0, 0x120]
ldp d6, d7, [x0, 0x130]
ldp d8, d9, [x0, 0x140]
ldp d10, d11, [x0, 0x150]
ldp d12, d13, [x0, 0x160]
ldp d14, d15, [x0, 0x170]
ldp d16, d17, [x0, 0x180]
ldp d18, d19, [x0, 0x190]
ldp d20, d21, [x0, 0x1A0]
ldp d22, d23, [x0, 0x1B0]
ldp d24, d25, [x0, 0x1C0]
ldp d26, d27, [x0, 0x1D0]
ldp d28, d29, [x0, 0x1E0]
ldp d30, d31, [x0, 0x1F0]

ldp x2, x3, [x0, 0x10]
ldp x4, x5, [x0, 0x20]
ldp x6, x7, [x0, 0x30]
Expand All @@ -135,8 +134,38 @@ pub unsafe fn restore_context(ctx: &Context) -> ! {
ldp x0, x1, [x0, 0x00]
ret
",
in("x0") ctx,
in("x0") $ctx,
options(noreturn)
);
};
(mayberestore(fp)) => {
"
ldp d0, d1, [x0, 0x100]
ldp d2, d3, [x0, 0x110]
ldp d4, d5, [x0, 0x120]
ldp d6, d7, [x0, 0x130]
ldp d8, d9, [x0, 0x140]
ldp d10, d11, [x0, 0x150]
ldp d12, d13, [x0, 0x160]
ldp d14, d15, [x0, 0x170]
ldp d16, d17, [x0, 0x180]
ldp d18, d19, [x0, 0x190]
ldp d20, d21, [x0, 0x1A0]
ldp d22, d23, [x0, 0x1B0]
ldp d24, d25, [x0, 0x1C0]
ldp d26, d27, [x0, 0x1D0]
ldp d28, d29, [x0, 0x1E0]
ldp d30, d31, [x0, 0x1F0]
"
};
(mayberestore()) => { "" };
}

pub unsafe fn restore_context(ctx: &Context) -> ! {
unsafe {
#[cfg(target_feature = "fp-armv8")]
restore!(ctx, gp, fp);
#[cfg(not(target_feature = "fp-armv8"))]
restore!(ctx, gp);
}
}