[PATCH] Re-enable a hook in MCELFObjectTargetWriter to allow target-specific relocationtable sorting and use this hook for Mips.

Vladimir Stefanovic Vladimir.Stefanovic at imgtec.com
Fri Apr 3 08:09:43 PDT 2015


Ok, so, what do you say, is the current explanation from the patch clear enough about why and how we sort the table? (I mean, the whole text before sortRelocs().)

Regards,
Vladimir
________________________________________
From: Rafael EspĂ­ndola [rafael.espindola at gmail.com]
Sent: Friday, April 03, 2015 5:05 AM
To: Vladimir Stefanovic
Cc: reviews+D7414+public+018ed232ff71bbc8 at reviews.llvm.org; Daniel Sanders; Simon Atanasyan; Toma Tabacu; Petar Jovanovic; llvm-commits
Subject: Re: [PATCH] Re-enable a hook in MCELFObjectTargetWriter to allow target-specific relocationtable sorting and use this hook for Mips.

On 2 April 2015 at 17:49, Vladimir Stefanovic
<Vladimir.Stefanovic at imgtec.com> wrote:
>
> But we are sorting the table exactly as gas only for easier comparison of the generated o files, aren't we?
>
> The linker must not produce different results if it matches a hi with a different lo, as long as their types match (R_MIPS_HI16 with R_MIPS_LO16, etc.) and are against the same symbol.
>
> E.g.:
>
> 0x0: lui $2,%hi(sym)
> 0x4: addiu $2,$2,%lo(sym)
> 0x8: addiu $2,$2,%lo(sym)
> 0xc: lui $2,%hi(sym)
>
> The ABI and the extension allow hi at 0xc to be put before any of two lo's, and the linker must properly calculate the address in both cases. If it didn't, it would be a linker bug.

So, there are a few things going in here

* Normal ELF sorts by offset to match gas and make the .o easier to compare.
* Normal ELF then sorts by type, just to make the order deterministic.
I have no idea if gas does this or not.
* Normal ELF could decide to sort the relocs by SHA1 if it wanted.

but for Mips ELF

* There are strong ordering constraints that the assembler *must* obey
for the linker to produce the correct result.
* In addition to that, we can choose to sort more like gas to make the
objects easier to compare.
* For MIPS, we cannot break the first item unless we decide to declare
ourselfs incompatible with gas, and even if we did we would have to
document in what way we were incompatible.

The main thing the comment has to cover is the first item. We have to
document what restrictions must be obeyed.

Cheers,
Rafael




More information about the llvm-commits mailing list