Search code examples
assemblygccgnu-assembler68000objcopy

GNU Assembler .long Declaration Zeroed Out


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?


Solution

  • 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