This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Re: objcopy elf->coff relocs
Date: Mon, 6 Sep 1999 21:43:15 -0500
From: Robert Lipe <robertl@sco.com>
Ian Lance Taylor wrote:
> 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
>
> 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
I've now looked at a representative sample of the ELF i386 objects in
question. The only types of relocs I spot are R_386_32 and R_386_PC32
and only against .text, .data, and .rodata.
For this specific case (ELF->COFF for those two reloc types on IA32)
could objcopy do enough conversion to be practical or do I have to
start thinking about implementing an ELF linker (cringe) for the target
environment?
Yes, it's possible to convert 32 and PC32 relocs between i386 COFF and
ELF. The key is that both formats are able to represent all the
relocations you care about. This is not true in the general case: for
example, there are many ELF relocations which can not be represented
in COFF (e.g., all GOT and PLT relocations) and there are sometimes
COFF relocations which can not be represented in ELF (e.g., the m68k
COFF negative 32 bit relocation).
Is objcopy likely doing something pretty close to the right thing and
"merely" forgetting to renumber the relocation type or is your warning
that there are deeper problems than this? If you're warning that we
can't convert relocs reliably between two any arbitrary types, then I'm
just hoping that the limited scope of the problem makes this a tractable
task.
While you could say that objcopy is merely forgetting to renumber the
relocation type, a better way to say it would be that objcopy isn't
even trying to renumber the relocation type. I suppose you could have
objcopy call bfd_reloc_type_lookup on both object file formats. It
could then compare the howtos. If they look plausibly similar, it
could simply stuff the new howto into the arelent. That would work
some of the time, which would be better than the current situation in
which it definitely never works.
Ian