1

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
fuz
  • 88,405
  • 25
  • 200
  • 352
SebCollard
  • 332
  • 2
  • 20
  • See also [Mach-O 64-bit format does not support 32-bit absolute addresses. NASM Accessing Array](https://stackoverflow.com/a/47301555/417501). – fuz Feb 18 '20 at 12:30

1 Answers1

2

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.

fuz
  • 88,405
  • 25
  • 200
  • 352
  • 1
    And more importantly, Mach-O doesn't have relocations for 32-bit absolute addresses, so NASM has no way of telling the linker to even make an attempt to do that. – Peter Cordes Feb 18 '20 at 12:50