This is an archive of the discontinued LLVM Phabricator instance.

[PPC64] Support R_PPC64_GOT16 Relocations
AbandonedPublic

Authored by martell on Dec 9 2018, 12:19 PM.

Details

Summary

When linking the linux kernel on ppc64
ld.lld: error: unrecognized reloc 58
58 is R_PPC64_GOT16_DS

Diff Detail

Repository
rLLD LLVM Linker

Event Timeline

martell created this revision.Dec 9 2018, 12:19 PM

I implemented this for ppc32 as well but there are a few things that need to be changed as a result of this so I will put that in a separate patch
I'm going to add a bunch of inline comments about things that could change.

martell marked 5 inline comments as done.Dec 9 2018, 12:51 PM

I'm probably going to learn something valuable about the global offsets table or the table of contents sections from the response to this :)

ELF/Arch/PPC64.cpp
23

Any suggestions on a rename here?
(It is no longer just toc but is got also)

63

Ditto

530

ditto

600

I don't think I can just optimize got relocations like toc relocations
but I'm not as familiar with the ISA / symbol groups as others.
Is a --got-optimize useful?

Take R_PPC64_ADDR16_HA for R_PPC64_GOT16_HA as an example

case R_PPC64_ADDR16_HA:
    if (Config->GotOptimize && IsGotRelType && ha(Val) == 0)
      writeInstrFromHalf16(Loc, 0x60000000);
    else
      write16(Loc, ha(Val));
    break;
606

comments probably need to change

martell abandoned this revision.Dec 21 2018, 11:31 AM
martell added a subscriber: sfertile.

This was already implemented in rL349511 and rL349772.
Thanks @sfertile and sorry for the noise.
I don't know if there are any notes here that are useful. --got-optimize ?

This was already implemented in rL349511 and rL349772.
Thanks @sfertile and sorry for the noise.
I don't know if there are any notes here that are useful. --got-optimize ?

Hi @martell, Thanks for creating this patch. If I was aware of it I would have skipped mine and helped review this one. I've left a few comments below related to some of your comments.

ELF/Arch/PPC64.cpp
23

I think we should update this name possibly to PPC64TocBaseOffset or PPC64TocBaseBias . TOC/toc is somewhat overloaded in the ABI, a clearer name makes it explicit that this is an offset used in building the TocBase value.

63

I think this name is good as is. This calculates the address the toc pointer points at which is typically known as the tocbase.

67

This comment is out of date. I'm guessing this description is for the V1 abi. The V2 abi is unfortunately somewhat ambiguous on what exactly is and isn't contained in the Table-Of-Contents.

600

The optimization done here is strictly the transformation of a 2 instruction access sequence into a single instruction access sequence when the relocation offset fits in a single signed 16-bit immediate. It works similarly for got based relocation's as well as the toc based relocation (except it will work on the first 2 instructions of a 3 instruction got-indirect access sequence). For example a got-indirect access where the high-adjusted part of the access is zero gets transformed as such:

addis  r3, r2, sym@got@ha     --> nop
ld     r3, sym@got@l(r3)      --> ld r3, sym@got@l(r2)
lwa    r3, 0(r3)              --> lwa r3, 0(r3)

As for naming, gold does all these optimization with the --toc-optimize flag (likely because the optimization's are related to the toc-pointer )