Search code examples
x86x86-64elfrelocation

Why doesn't Elf64 use Elf64_Rel for relocations on 64-bit x86?


https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-54839.html#chapter7-2 states:

64–bit SPARC and 64–bit x86 use only Elf64_Rela relocation entries. Thus, the r_addend member serves as the relocation addend. x86 uses only Elf32_Rel relocation entries. The field to be relocated holds the addend.

There exists an Elf64_Rel struct, so why isn't it being used on 64-bit x86 targets? Doesn't using Elf64_Rela only waste space here as the pre-relocation addresses are just ignored (or at least are always 0 from what I've seen in testing)?

Note: r_addend is omitted in Elf64_Rel, not simply unused.


Solution

  • There exists an Elf64_Rel struct, so why isn't it being used on 64-bit x86 targets?

    On x86_64, there are several possible memory models. By default, the small memory model is used, which doesn't need any 64-bit relocations.

    If you compile with -mcmodel=large, then 64-bit relocations will be used.