Closed
Description
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