Author Topic: Mach-O 64-bit format does not support 32-bit absolute addresses  (Read 7990 times)

Offline cre8eve

  • Jr. Member
  • *
  • Posts: 3
Mach-O 64-bit format does not support 32-bit absolute addresses
« on: September 11, 2014, 07:42:47 PM »
Hey everyone  :) I am trying to write numbers from one array to another, but I am stuck with the topic error.
I have
section .data
 
source:    db      '5', '6', '7', '8'
dest:       db   '0', '0', '0', '0'

section .text
...
mov rax, source ; copying the first number (5) into rax register
mov dest, rax    ; ERROR: Mach-O 64-bit format does not support 32-bit absolute addresses
...

I compile it with -f macho64 option

How can I rewrite from one array to another? Any suggestions?
Thanks in advance.
« Last Edit: September 11, 2014, 08:06:02 PM by cre8eve »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Mach-O 64-bit format does not support 32-bit absolute addresses
« Reply #1 on: September 11, 2014, 10:38:28 PM »
Well... Finally... at the end of the day... I think (not sure of this) there's an error in Nasm's "-f macho64" output format. You may need to use (G)as, or perhaps try Yasm.

However, we can discuss what else is wrong with your code, and why it wouldn't have worked anyway.

Code: [Select]
section .data
 
source:    db      '5', '6', '7', '8'
dest:       db   '0', '0', '0', '0'

What you've got here is characters, not numbers. They're numbers, too, of course, but probably not the numbers you want.

Code: [Select]
section .text
...
mov rax, source ; copying the first number (5) into rax register

Comment does not match code. You've moved the address of your array into rax.

Code: [Select]
mov rax, [source]

This would move the first 64-bit number (8 bytes) into rax. rax would be 0x3030303038373635. I doubt this is what you want. To move a single byte into a register, try:

Code: [Select]
mov al, [source]

This is still going to be the character '5', not the number 5.

Code: [Select]
mov dest, rax    ; ERROR: Mach-O 64-bit format does not support 32-bit absolute addresses
...

This attempts to move rax into the address of "dest" - an immediate value. Reminds me of the old Hendrix tune "If Six Were Nine". Simply isn't going to work - no such instruction.

Code: [Select]
mov [dest], rax

... would move rax - 64-bits, 8 bytes - into your buffer... which is only 4 bytes, causing an overflow. Probably what you want - to move just one byte (one character):

Code: [Select]
mov [dest], al

I don't know what to advise you, Cre8eve. You appear to be fairly new at this (no offense intended - none of us are born knowing this stuff) and as such, probably don't want to mess with a potentially buggy format. AFAIK, "-f macho32" (or just "-f macho") works. There may be a problem convincing a 64-bit ld that you want 32-bit code - there is in Linux. For Linux, we tell ld "-m elf_i386", but that isn't going to work for MacOS. "objdump -i" produces a list of supported formats - this may work for Mac, too(?). Then... if you attempt to link against C libraries, there may be an issue of incompatible libraries (there is in Linux)...

I wish I had a better answer for ya!

Best,
Frank


Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: Mach-O 64-bit format does not support 32-bit absolute addresses
« Reply #2 on: September 21, 2014, 01:14:23 PM »
Put DEFAULT REL near the top of your source if you are using macho64: more info

I also reposted an older Mac OS X demo, which may help guide you: http://forum.nasm.us/index.php?topic=1972.0