News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

forward referencing in masm32 and masm6.x

Started by bobl, November 28, 2009, 04:35:36 PM

Previous topic - Next topic

bobl

#15
UPDATE 10/12/09
32bit binutils does produce a working binary from the sources

64bit binutils apparently doesn't cos it needs a different command line.


"
Not a bug.  objcopy -O binary on a relocatable file loses the relocs.
X86_64 uses rela style relocs where the addend is in the reloc, x86
uses rel where the addend is in the section.  So in the latter case
you get the "+4" from .text+4, in the former you don't.

If you want a binary output you must lose the relocs.  So don't try to
objcopy relocatable file.  Final link them first.
"


This contrasts with nasm which produces the same correct result with the same command in both 32 and 64 bit flavors.

Just in case anyone ever has a similar problem.

bobl

To complete this thread...
To reproduce the same flat binary with addresses starting from 0,
i.e. for little os'es relocated to memory address 0,
using 32 and 64 bit binutils

you need to use these different commands
32 bit binutils
========
as test.s
objcopy -O binary a.out a.com

64 bit binutils
========
as --32 -o test.o test.s
ld -Ttext=0 -melf_i386 test.o
objcopy -O binary a.out a.com

-Ttext=0 sets addresses to start at 0.
I tried to do this with .org in the gas program with no joy.
This difference in 32 and 64 bit binutils really wasn't obvious to me and this might come in useful to someone doing similar stuff.