objcopy elf->coff relocs

Ian Lance Taylor ian@zembu.com
Mon Sep 6 16:59:00 GMT 1999


   Date: Mon, 6 Sep 1999 16:32:10 -0500
   From: Robert Lipe <robertl@sco.com>

   I have a reason to convert (simple) ELF i386 relocatables to COFF
   format for an open-sourced project.  I had used objcopy for similar
   tasks in the past so I though I'd give it a shot.  Unfortunately, the
   resulting object has bad reloc types which sends the linker into a
   tizzy.  Hopefully some can point out any pilot error along the way or
   at least point me to a good starting place in BFD's guts if the problem
   isn't self-evident to those of you comfortable inside it.

objcopy doesn't really convert relocations.  In the general case it is
impossible.  In specific cases it may be possible, but objcopy does
not do the necessary transformations.  Moreover, the current BFD
relocation structures don't provide enough information to correctly
detect whether a specific transformation is possible or impossible.

   I then went to a Linux/IA32 system and spun the binutils tree as of this
   morning configured  with --enable-targets=i386-coff.

   First, I converted:

   $ ./objcopy --output-format=coff-i386 telf.o tcvt.o

   Then I examined:
   $ ./objdump --reloc tcvt.o 

   tcvt.o:     file format coff-i386

   RELOCATION RECORDS FOR [.text]:
   OFFSET   TYPE              VALUE 
   00000004 1                 wretch
   00000009 2                 bletch

   The way I read <reloc.h> reloc types 1 and 2 are R_DIR16 and R_REL16
   and these are certainly not meant to be 16-bit objects.

objcopy didn't change the relocation type numbers.  Types 1 and 2 are
R_386_32 and R_386_PC32 in ELF.

Ian


More information about the Binutils mailing list