0

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?

SRobertJames
  • 7,706
  • 14
  • 53
  • 95
  • [Why does the x86-64 / AMD64 System V ABI mandate a 16 byte stack alignment?](https://stackoverflow.com/q/49391001) - so that compilers can use `movaps` to more efficiently do stuff with locals on the stack 16 bytes at a time. Like modern builds of glibc are apparently doing inside functions that printf uses. – Peter Cordes Dec 01 '21 at 16:42

0 Answers0