Skip to content

Naked functions don't produce an active frame for asm! .seh_* directives on Windows #75897

Open
@bkolobara

Description

@bkolobara

I'm trying to port some Unix asm! code, using the .cfi_* directives inside naked functions to provide information to the unwinder/debugger about call frames, to Windows.

The following code compiles on MacOs and Linux under rustc 1.47.0-nightly (f44c6e4e2 2020-08-24):

#[naked]
unsafe extern "C" fn a() {
    asm!(".cfi_def_cfa rbp, 16")
}

If I try to do something similar on Windows:

#[naked]
unsafe extern "C" fn a() {
    asm!(".seh_setframe rbp, 16")
}

I get: error: .seh_ directive must appear within an active frame. Only if I add .seh_proc a, .seh_endproc and declare the function #[no_mangle] the code compiles:

#[naked]
#[no_mangle]
unsafe extern "C" fn a() {
    asm!(
        ".seh_proc a",
        ".seh_setframe rbp, 16",
        ".seh_endproc"
    )
}

I don't think this is correct though, as the return statement in the naked function happens after .seh_endproc and is excluded from the frame information.

I expect the #[naked] function to behave the same way on Windows as on Unix platforms, where a cfi_startproc is implicitly added to #[naked] functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-nakedArea: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzSC-bugCategory: This is a bug.F-asm`#![feature(asm)]` (not `llvm_asm`)requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions