4

When assembling code with GNU Binutils declarations such as:

.long MY_Label
.long MY_Second_label

Assemble without errors but consistently map to zeroed out 32-bit strings when doing a hex dump even when opcodes and other information separate them in the address space. I'm compiling with:

m68k-elf-gcc -c hello.s -o rom.o -nostdlib -static && m68k-elf-objcopy -O binary rom.o rom.bin

And dumping my binary with:

m68k-elf-objdump -D -m m68k --start-address=0x0000 --prefix-addresses -l -x -b binary --disassemble-zeroes rom.bin

What am I missing in my assembly code?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
user2108
  • 43
  • 6
  • 1
    Are they still zero if you link the object file and dump the result of that? How about when your code uses them at runtime? – Joseph Sible-Reinstate Monica Jun 02 '20 at 04:34
  • Linking was my mistake! I'm cross compiling for a different architecture so I wanted to catch as many errors as I could before testing this code. As you might guess the target system runs without an OS. Thank you! – user2108 Jun 02 '20 at 12:45

1 Answers1

4

You never linked your .o relocatable so the addresses are still placeholders. -c tells GCC not to link, just assemble, so -static and -nostdlib are meaningless.

If you use objdump -drwC rom.o you'll see the symbol relocations next to the disassembly (-r option).

Remove the -c from the initial command and keep everything else the same:

m68k-elf-gcc  hello.s -o rom.elf  -nostdlib -static
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 1
    (This question is probably a duplicate, at least if we include the same mistake for x86 or ARM, maybe not m68k. I was feeling lazy and didn't check. If anyone finds a duplicate, let me know and I can close the question.) – Peter Cordes Jun 02 '20 at 04:50
  • Thank you @Peter Cordes. If this was a duplicate I'm sorry - perhaps the way I was phrasing my search was part of the issue in me finding any existing answers. In any case thank you for helping me along. I will try to pay your kindness forward. – user2108 Jun 02 '20 at 12:43