This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

RFC: should objcopy convert .rel.* to .rela and back?


[Resend due to no response]

Hi all,

In our product, we have some 32- and 64-bit x86 code within a single binary. They share the data structures so it is convenient to link them together. This is done by compiling the 32-bit code and then converting it to 64-bit using `objcopy -Oelf64-x86-64 input.o output.o` and then using output.o to link with 64-bit parts.

The problem with this approach, though, is that the i386 and x86-64 ABIs mandate use of different formats for the relocation sections. i386 ABI uses .rel.*, while x86-64 prescribes using .rela.* (in relocatable objects). The objcopy command above, however, does not change the format of the relocation sections: the resulting output.o, despite being an x86-64 object, contains .rel.* sections.

This in turn leads to a problem during incremental link when the linker needs to update the addends in the relocations. When linking "regular" x86-64 files, ld updates the r_addend fields in the respective .rela.* sections. When linking "regular" i386 files, ld updates the values within the section against which the relocation is made. But when linking such "converted" files, ld does neither! Apparently, it wants to update r_addend fields because it links for x86-64 - but there is no .rela.* sections. The resulting object has bogus relocations for 2nd and subsequent object files.

That means, this approach can currently be used only if there is a single instance of such "converted" object in the link, and that "converted" object is the first linker's input (in this case, the addends remain the same - so they're valid even if ld does not update them). What bothers me is that if that assumption does not hold, ld silently creates a bogus object. I attached a script that reproduces the issue.

Hence, two questions:

1. Should objcopy have an ability to convert .rel.* to .rela.* and back? I am thinking of something like: --reloc-format=[native|keep|rel|rela], with default being either "keep" (the current behavior) or "native" (converting to the default relocation format for the output BFD - which, IMO, makes the most sense).

2. Shouldn't ld detect that it must update the addends and has no way to do so?

Regards,
Alexey.


Attachment: foo.bash
Description: Text document


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