On x86 64 SysV (Linux), my understanding is that, assuming no floating point arguments, to call a varadic func like printf, we simply zero al and call the func normally:
mov al, 0
mov rdi, msg
call printf
However, in my minimal example below, this works in print but not in wrap:
; Minimal example of failing code
; nasm -felf64 -gdwarf min.asm && gcc -no-pie min.o -o min
global main
extern printf
section .data
msg:
db `OK\n\0`
section .text
print:
mov al, 0
mov rdi, msg
call printf
ret
wrap:
call print
ret
main:
call print ; works
call wrap ; SEGV
ret
What needs to be changed?