This is an archive of the discontinued LLVM Phabricator instance.

[ELF2] getLocalRelTarget can ask the Target for symbolless relocations
ClosedPublic

Authored by hfinkel on Oct 16 2015, 12:14 PM.

Details

Reviewers
ruiu
rafael
Summary

R_PPC64_TOC does not have an associated symbol, but does have a non-zero VA that target-specific code must compute using some non-trivial rule. We currently handle this as a special case in PPC64TargetInfo::relocateOne, where we know to write this special address, but does not work when creating shared libraries. The special TOC address needs to be the subject of a R_PPC64_RELATIVE relocation, and so we also need to know how to encode this special address in the addend of that relocation.

Thus, some target-specific logic is necessary when creating R_PPC64_RELATIVE as well. It looks like the best way to solve this problem is to simply have getLocalRelTarget ask the target for the address of special symbolless relocations. This allows us to remove the special case in PPC64TargetInfo::relocateOne (simplifying code there), and naturally allows the existing logic to do the right thing when creating associated R_PPC64_RELATIVE relocations for shared libraries.

Diff Detail

Event Timeline

hfinkel updated this revision to Diff 37623.Oct 16 2015, 12:14 PM
hfinkel retitled this revision from to [ELF2] getLocalRelTarget can ask the Target for symbolless relocations.
hfinkel updated this object.
hfinkel added reviewers: rafael, ruiu.
hfinkel added a project: lld.
hfinkel added a subscriber: llvm-commits.
ruiu added inline comments.Oct 16 2015, 12:44 PM
ELF/OutputSections.cpp
437–438

Update the comment to mention that we usually return 0 but may be different on PPC64.

But, actually, does this happen on non-PPC64 platform? If there's no other platform that we have to take care of this case, this is probably over-designed. We can define a function like getPPC64TocDefault() and use that function here if it's on PPC64.

ELF/Target.cpp
436

Remove this blank line.

ruiu added inline comments.Oct 16 2015, 1:45 PM
ELF/OutputSections.cpp
437–438

So this can be as easy as

// R_PPC64_TOC is special as that has no corresponding symbol.
// getPPCTocBase will take care of the details for PPC.
if (Config->EMachine == EM_PPC64 && Type == R_PPC64_TOC)
  return getPPCTocBase();
hfinkel added inline comments.Oct 16 2015, 1:51 PM
ELF/OutputSections.cpp
437–438

I took a quick look at the other ABIs (ARM, MIPS, etc.) and did not see any other similar-looking relocations. This may be a PPC64-specific "feature". I can move the function for determining the TOC address into this file and call it here.

ruiu added inline comments.Oct 16 2015, 2:18 PM
ELF/OutputSections.cpp
437–438

Sounds good to me.

hfinkel updated this revision to Diff 37647.Oct 16 2015, 2:41 PM

Updated per reviewer comments (I left the getPPC64TocBase function in Target.cpp, since it is still needed there anyway; I just made it non-static).

ruiu accepted this revision.Oct 16 2015, 2:46 PM
ruiu edited edge metadata.

LGTM

ELF/OutputSections.cpp
439

Ah, this is even better. Thank you for making this change.

This revision is now accepted and ready to land.Oct 16 2015, 2:46 PM
hfinkel closed this revision.Oct 16 2015, 2:57 PM

r250555, thanks!