This is an archive of the discontinued LLVM Phabricator instance.

[PPC64] Position-independent long-branch thunks.
AbandonedPublic

Authored by sfertile on Jul 25 2018, 6:10 AM.

Details

Summary

Patch implements range-extending thunks for calls that exceed the reach of a bl instruction for position-independent code.

If a callee is the target of a call that needs a range-extension, its allocated a slot in the procedure linkage table after all the entries that are for non-local calls, and a relative dynamic relocation is emitted in the rela.dyn section. The thunk body loads the address of the local-entry from the .plt and indirectly branches to it.

Diff Detail

Repository
rLLD LLVM Linker

Event Timeline

sfertile created this revision.Jul 25 2018, 6:10 AM
sfertile retitled this revision from [PPC64] Position-indepenent long-branch thunks. to [PPC64] Position-independent long-branch thunks..Jul 25 2018, 8:03 AM
rdhindsa added inline comments.Oct 3 2018, 12:08 PM
ELF/SyntheticSections.h
362

I think you need to add postThunkContents as virtual function to class SyntheticSection as well.

ELF/Writer.cpp
1686

Could you please rebase and update Inx::GotPlt to In.GotPlt

sfertile added inline comments.Oct 3 2018, 12:23 PM
ELF/Writer.cpp
1686

Will do. I rebased the 2 long-branch thunk patches earlier this week and realized there were a number of changes in lld I had to merge in. I'll post the update versions shortly.

dxf added a subscriber: dxf.Oct 3 2018, 1:30 PM
ruiu added a comment.Oct 3 2018, 1:45 PM

This patch seems a bit too intrusive to me, but I'm not sure if it is unavoidable (and thus this is a straightforward implementation) or there's another way to implement it.

ELF/Arch/PPC64.cpp
527

Flip the condition to return early.

553

Can you use IsInt<N> instead?

ELF/Symbols.h
74

nit: add a blank line before a multi-line comment.

76

Hmm, do you really need to add a new member to Symbol? I need to understand the spec better, but if we can, we should avoid adding a member to Symbol.

158–159

Do you need to distinguish a .got.plt entry for a long branch thunk from a regular .got.plt entry? I wonder if you can treat a symbol that needs a range-extension thunk as a symbol that has a (regular) .got.plt entry.

ELF/Thunks.cpp
223

Flip the condition to return early.

615–616

No else after return

This patch seems a bit too intrusive to me, but I'm not sure if it is unavoidable (and thus this is a straightforward implementation) or there's another way to implement it.

This isn't something that is dictated by the ABI and its entirely constrained to the module being linked so we are free design something less invasive. This implementation was chosen mostly to match what ld.gold implements. I think your suggestion of treating a long branch target as a regular .got.plt entry is feasible, but I'll likely have to make a small change in Symbol since the PltIndex does double duty for the GotPlt offset as well as determining if a symbol is in the plt.