This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

objcopy of coff-i386 to elf32-i386?


Hi, I'm not sure if "user" questions like this are on-topic here, but
here goes...

I'm trying to port an application from Win32 to Unix (Linux
initially). Most of the code is C and C++ which I've got to compile
under Linux without too much trouble. However, some of the code is
written for MASM, and can't be easily re-written. So what I've done is
build binutils 2.10 with support coff-i386 in addition to elf.

So I took the various coff-i386 object files produced by MASM and put:

objcopy --remove-leading-char \
	--input-target=coff-i386 --output-target=elf32-i386 \
	$(COFFDIR)/$*.obj $*.o

in my makefile to convert them to elf. Then I just linked the elf object
files produced by gcc with the elf object files converted from COFF.

Both the conversion and the linking worked and I got an elf
executable. However, calls from converted COFF object files to
functions in other object files are not being resolved properly. The
offset parameter to the call is always 4 bytes larger than it should
be. It seems like the linker expected the call instruction to be 4 bytes
lower when it worked out the offset. Calls to the same functions from C
code are fine. It doesn't matter if the function being called is
implemented in C, or is in another converted COFF file.

So there's something different about the elf files being produced by
objcopy, which is confusing the linker. I've had a look at the converted
files with objdump and readelf, but I don't know enough about how elf
works to know if what I'm seeing is correct.

I actually got a simpler program to work by subtracting 4 bytes from the
symbol's value in a linker script, so it seems this approach will work
if I can get the call offsets right. If anyone has any suggestions as to
how to proceed or where to look for the cause, that would be great. I
can give you readelf or objdump output if it's useful.

-- 
Lachlan O'Dea <mailto:lodea@vet.com.au>   Computer Associates Pty Ltd
Webmaster                                   Vet - Anti-Virus Software
http://www.vet.com.au/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]