Skip to content

naked + variadic args partially ignores the naked #99858

Closed
@aviramha

Description

@aviramha

I found out that if I define a #[naked] function that has variadic args it still emits a function prolog.

I tried this code:

#![feature(c_variadic)]
#![feature(naked_functions)]
use std::{arch::asm};
#[no_mangle]
#[cfg(target_os = "linux")]
#[cfg(target_arch = "x86_64")]
#[naked]
unsafe extern "C" fn rsyscall(syscall: i64, args: ...) -> i64 {
    asm!(
        "mov    rax, rdi",
        "mov    rdi, rsi",
        "mov    rsi, rdx",
        "mov    rdx, rcx",
        "mov    r10, r8",
        "mov    r8, r9",
        "mov    r9, qword ptr[rsp]",
        "syscall",
        "ret",
        options(noreturn)
    )
}

I expected to see this happen: asm output:

        mov     rax, rdi
        mov     rdi, rsi
        mov     rsi, rdx
        mov     rdx, rcx
        mov     r10, r8
        mov     r8, r9
        mov     r9, qword ptr [rsp]
        syscall
        ret

Instead, this happened: asm output

rsyscall:
        mov     rax, rsp
        mov     qword ptr [rsp + 16], rax
        mov     qword ptr [rsp + 8], rax
        mov     qword ptr [rsp], 0

        mov     rax, rdi
        mov     rdi, rsi
        mov     rsi, rdx
        mov     rdx, rcx
        mov     r10, r8
        mov     r8, r9
        mov     r9, qword ptr [rsp]
        syscall
        ret

Meta

rustc --version --verbose:

rustc 1.64.0-nightly (2643b1646 2022-07-27)
binary: rustc
commit-hash: 2643b16468fda787470340890212591d8bc832b7
commit-date: 2022-07-27
host: x86_64-unknown-linux-gnu
release: 1.64.0-nightly
LLVM version: 14.0.6

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-naked_functions`#![feature(naked_functions)]`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions