NASM compiles just fine, but when i use YASM I'm getting the following error:
hello.asm:12: error: macho: sorry, cannot apply 32 bit absolute relocations in 64 bit mode, consider "[_symbol wrt rip]" for mem access, "qword" and "dq _foo" for pointers.
Makefile
test: hello
./hello
hello:
yasm -f macho64 hello.asm
ld -o hello hello.o
clean:
rm *.o *.core hello
system.inc
%define stdin 0
%define stdout 1
%define stderr 2
%define SYS_nosys 0
%define SYS_exit 1
%define SYS_fork 2
%define SYS_read 3
%define SYS_write 4
section .text
align 4
access.the.osx.kernel:
syscall
ret
%macro system 1
mov rax, %1
call access.the.osx.kernel
%endmacro
%macro sys.exit 0
system SYS_exit
%endmacro
%macro sys.write 0
system SYS_write
%endmacro
hello.asm
%include 'system.inc'
section .data
hello db 'Hello, World!', 0Ah
hbytes equ $-hello
section .text
global start
start:
mov rax, 0x2000004
mov rdi, stdout
mov rsi, hello
mov rdx, hbytes
syscall
;sys.write
xor rdi, rdi
mov rax, 0x2000001
syscall
;sys.exit
Anyone know what's going on? And if you could explain why NASM works, but YASM doesn't that would be a bonus.
I got it working. In yasm
you have to explicitly tell it that the address is 64-bit like so:
mov rsi, qword hello
The documentation talks about the situation here: https://github.com/yasm/yasm/wiki/AMD64