This is an archive of the discontinued LLVM Phabricator instance.

[JITLink][PowerPC] Add TOC and relocations for ppc64
ClosedPublic

Authored by lkail on Jun 30 2023, 3:23 AM.

Details

Summary

This patch builds TOC and adds common relocations for ppc64.

To build TOC, sections belong to TOC are merged into one section, serves as GOT and small data accessing.

Relocations commonly seen in local function call, external function call and global variable reference are added.

References

Diff Detail

Event Timeline

lkail created this revision.Jun 30 2023, 3:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2023, 3:23 AM
lkail requested review of this revision.Jun 30 2023, 3:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2023, 3:23 AM
lkail edited the summary of this revision. (Show Details)Jun 30 2023, 3:30 AM
lkail edited the summary of this revision. (Show Details)
lkail updated this revision to Diff 536174.Jun 30 2023, 3:47 AM

Make premerge bot happy.

lhames added a comment.Jul 4 2023, 4:45 PM

Thanks very much @lkail!

I just tested this out locally and it's exciting to see nontrivial test cases running.

llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h
112–117

Just to make sure I follow:

ELFLinkGraphBuilder_ppc64 converts R_PPC64_ADDR64 to RequestToBeGOTEntry when it's a relocation _from_ a preexisting GOT entry in the object file?

Rather than using a special edge kind, could we walk the .toc section in the buildTables_ELF_ppc64 function to pre-register the entries before calling visitExistingEdges? Would that allow us to drop the RequestToBeGOTEntry edge kind and use Pointer64 unconditionally for R_PPC64_ADDR64?

I'm imagining something like:

template <support::endianness Endianness>
Error buildTables_ELF_ppc64(LinkGraph &G) {
  LLVM_DEBUG(dbgs() << "Visiting edges in graph:\n");
  ppc64::TOCTableManager<Endianness> TOC;

  // Register preexisting GOT entries with TOC table manager.
  if (auto *dotTOCSection = G.findSectionByName(".toc")) {
    for (<each GOT entry>)
      TOC.appendEntry(<entry target>, <entry symbol>);
  }

  ppc64::PLTTableManager<Endianness> PLT(TOC);
  createELFGOTHeader(G, TOC);
  visitExistingEdges(G, TOC, PLT);
  ...
lkail added inline comments.Jul 4 2023, 10:51 PM
llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h
112–117

ELFLinkGraphBuilder_ppc64 converts R_PPC64_ADDR64 to RequestToBeGOTEntry when it's a relocation _from_ a preexisting GOT entry in the object file?

Yes, that's the case.

Rather than using a special edge kind, could we walk the .toc section in the buildTables_ELF_ppc64 function to pre-register the entries before calling visitExistingEdges?

That sounds nice.

lkail updated this revision to Diff 537221.Jul 4 2023, 10:52 PM

Drop usage of RequestToBeGOTEntry.

lhames accepted this revision.Jul 5 2023, 8:45 PM

Thanks very much for the updates @lkail! LGTM. :)

This revision is now accepted and ready to land.Jul 5 2023, 8:45 PM
MaskRay added inline comments.Jul 5 2023, 9:09 PM
llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp
271

we add braces if the body is a complex statement.

280

we add braces if the body is a complex statement.

lkail updated this revision to Diff 537591.Jul 5 2023, 10:55 PM

Added braces.

This revision was landed with ongoing or failed builds.Jul 9 2023, 8:27 PM
This revision was automatically updated to reflect the committed changes.
chapuni added inline comments.
llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h
254

NopInst is unused in -Asserts

lkail marked an inline comment as done.Jul 10 2023, 1:14 AM
lkail added inline comments.
llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h
254