Generate ELF in x86 with RELA relocations

Hi guys,

I 'd like to generate an ELF object file in x86 that uses RELA instead
of REL for relocations. The reason I want that is because I have a
custom loader that only works with Elf32_Rela. Is there any flag in LLVM
to force that relocation scheme?

Is this demand reasonable? The only thing that I managed to dig out of
Google was [1] that states, among other things:

"REL relocations thus take 2 words of storage, and RELA relocations,
3. On x86, the ELF ABI *only* uses REL relocations, and words are 32
bits, making each relocation take 8 bytes ; on x86-64, the ELF ABI
only uses RELA relocations, and words are 64 bits, thus making each
relocation take 24 bytes, 3 times that of x86 relocations. On ARM,
both may be used, but apparently the compiler and the linker only use
REL relocations."

However, I am not convinced that I should start hacking on the loader,
yet! :slight_smile:

Cheers,
Yiannis

[1]: http://glandium.org/blog/?m=201011

Hi Yiannis,

I 'd like to generate an ELF object file in x86 that uses RELA instead
of REL for relocations. The reason I want that is because I have a
custom loader that only works with Elf32_Rela. Is there any flag in LLVM
to force that relocation scheme?

Is this demand reasonable? The only thing that I managed to dig out of
Google was [1] that states, among other things:

It's not controlled by a flag in LLVM at the moment. Each target picks
.rel or .rela based on the ABIs it supports (the key decision is made
in X86ELFObjectWriter.cpp, in the HasRelocationAddend setting).

Adding support for .rela is probably much easier than for .rel (which
would definitely need real compiler support), but I'd still be
slightly wary of assuming everything will just work. The linker might
well decide to rewrite the file with .rel for example, or some odd
corner case may rely on non-idempotency of .rel relocations (I
sincerely hope not!).

Cheers.

Tim.