How to implement new ELF 64 bit relocation (N64)

The ELF relocation record format is different for N64 which many Mips 64 ABIs use than for O64 which many if not all other target ABIs use.

The question I have is whether to treat N64 as a valid generic variant or should it be treated as target specific?

My contention is that it should be treated as an alternative generic format handled recognized and handled in the ELF class objects above the target specific level.

Most architectures have the following 64 bit relocation record format:

typedef struct
{

Elf64_Addr r_offset; /* Address of reference /
Elf64_Xword r_info; /
Symbol index and type of relocation */
} Elf64_Rel;

typedef struct
{

Elf64_Addr r_offset;
Elf64_Xword r_info;
Elf64_Sxword r_addend;

} Elf64_Rela;

Whereas N64 has the following format:

typedef struct
{

Elf64_Addr r_offset; /* Address of reference /
Elf64_Word r_sym; /
Symbol index /
Elf64_Byte r_ssym; /
Special symbol */

Elf64_Byte r_type3; /* Relocation type */

Elf64_Byte r_type2; /* Relocation type */

Elf64_Byte r_type; /* Relocation type */

} Elf64_Rel;

typedef struct
{

Elf64_Addr r_offset; /* Address of reference /
Elf64_Word r_sym; /
Symbol index /
Elf64_Byte r_ssym; /
Special symbol /
Elf64_Byte r_type3; /
Relocation type /
Elf64_Byte r_type2; /
Relocation type */

Elf64_Byte r_type; /* Relocation type */
Elf64_Sxword r_addend;

} Elf64_Rela;

The structure is the same size, but the r_info data element is now 5 separate elements. Besides the content aspects, endian byte reordering will be different for the area with each element being endianized separately.

In my mind there are 3 ways to approach this:

  1. Treat this as target specific :

    1. ELFObjectWriter::RecordRelocation would need to be derived for N64 implementations
  2. Treat this as generic and continue to pass r_type as an integer masking and unmasking the byte sized N64 values for N64 mode. I’ve implemented this and it causes no affect on other current targets.

  3. Treat as generic and changing r_type as a union. This is technically cleaner than (2) but would need to change the r_type type declaration and assignment for each target.

My preference is to treat it as a generic format variation an first implement #2 and then the more intrusive #3.

I have attached a sample patch series, not for submittal yet, but as an example of my local implementation.

Thanks,

Jack

01-N64.patch (6.96 KB)

02-hello_rel.patch (8.85 KB)

I’m resending this since many of the folks that would be interested in ELF direct object relocations were out last week.

01-N64.patch (6.96 KB)

02-hello_rel.patch (8.85 KB)