I'm working on a project in ASM x86-64
on a mac with the last version of catalina. When I try to compile it, I got tihs error error: Macho-O 64-bit format doest not support 32-bit absolute adresses
. I got this when I try to move an adress in the stack frame.
Example:
my_fnc:
push rbp
mov rbp, rsp
sub rsp, 64
mov qword [rbp - 8], __zpair
....
....
....
section .rodata
__zpair:
db "pair", 0
There's only space for 32 bits in most immediate operands. __zpair
, being a 64 bit address, might not fit† which is why the assembler rejects this code. Use
lea rax, [rel __zpair] ; load the address of __zpair
mov [rbp - 8], rax ; write address to stack
to first load the address using a rip
-relative addressing mode and then write it into the stack frame.
† Contrary to other platforms, macOS does not guarantee that your executable will be loaded into the first 2 GB of memory. In fact, it will never do so unless specifically configured.