Skip to content

Naked functions with arguments generate a prologue #42779

Description

@Ekleog

When compiling

#[naked]
pub extern fn naked_test(_fubar: u64) {
    unsafe { asm!("int3") }
}

(https://is.gd/Q03g7b)

The generated assembly includes a prologue with unexpected mov's (as well as a trailing ret, already reported in #32487)

Expected behaviour would be to have no prologue (and prevent compilation of a #[naked] function that is not extern as this would require implementing an undefined ABI, contrarily to what seems to happen https://is.gd/sQFBIy).

This is treacherous, as it dereferences some memory locations that may not be accessible, as happened to me and led to hours of debugging to finally figure out the compiled function was not the one defined.

cc #32408

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-nakedArea: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzSC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions