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

Naked functions generate unsound code #52836

Closed
roblabla opened this issue Jul 29, 2018 · 4 comments
Closed

Naked functions generate unsound code #52836

roblabla opened this issue Jul 29, 2018 · 4 comments
Labels
A-naked Area: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzS

Comments

@roblabla
Copy link
Contributor

roblabla commented Jul 29, 2018

https://github.com/roblabla/unwind-rs/blob/d27dfb13a2dd663d89ba67257bc050b8e76febde/unwind/src/glue/aarch64.rs#L14

This function generates the following ASM:

str    x0, [sp, #8] ; wtf
mov    x1, sp
sub    sp, sp, #0xa0
stp    x19, x20, [sp]
stp    x21, x22, [sp, #16]
stp    x23, x24, [sp, #32]
stp    x25, x26, [sp, #48]
stp    x27, x28, [sp, #64]
stp    x29, x30, [sp, #80]
stp    d8, d9, [sp, #96]
stp    d10, d11, [sp, #112]
stp    d12, d13, [sp, #128]
stp    d14, d15, [sp, #144]
mov    x2, sp
bl     0xaaaaaac35dd8 <unwind_recorder>
ldr    x30, [sp, #88]
add    sp, sp, #0xa0
ret

The first instruction was not part of the asm! macro. It seems to be a stack slot for the first argument. However, since the prelude got removed, sp will not get updated to a new size, and this will write over whatever was in the parent's stack.

I tried to reproduce it on godbolt, but was unable to do so. It seems to depend on optimization levels and size of the project/code ? I have a similar problem on i386 in another project, so this is not arch-specific.

@parched
Copy link
Contributor

parched commented Jul 30, 2018

permalink? There's no naked function there now.

@parched
Copy link
Contributor

parched commented Jul 30, 2018

Do you see the same result without unreachable_unchecked, because I don't think you're allowed anything but asm in a naked function?

@roblabla
Copy link
Contributor Author

Oops, fixed.

Yes, removing unreachable_unchecked has no effect on the generated assembly.

@nagisa nagisa added the A-naked Area: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzS label Jul 30, 2018
@nagisa
Copy link
Member

nagisa commented Jul 30, 2018

Duplicate of #34043. Complain if you think otherwise and I’ll reopen.

@nagisa nagisa closed this as completed Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-naked Area: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzS
Projects
None yet
Development

No branches or pull requests

3 participants