This is an archive of the discontinued LLVM Phabricator instance.

[JITLink] [ELF/AARCH64] Generic aarch64 patch fixups
ClosedPublic

Authored by sunho on May 24 2022, 3:30 AM.

Details

Summary

This patch simply moves aarch64 patch up logic from macho/aarch64 backend to aarch64.h file so that other aarch64 jitlink backend (ELF/AARCH64) can reuse the code. The fixup edges are idenetical to those of macho/aarch64 right now, as we don't know how much of them will be used by some target yet. But, I think this is a good initial start as Branch26, Page21, and PageOffset12 can be used verbatim in elf/aarch64 backend.

Diff Detail

Event Timeline

sunho created this revision.May 24 2022, 3:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2022, 3:30 AM
sunho requested review of this revision.May 24 2022, 3:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2022, 3:30 AM
sunho edited the summary of this revision. (Show Details)May 24 2022, 3:37 AM
sunho added reviewers: lhames, sgraenitz, v.g.vassilev.

Kudos, this is a really good first patch. Thanks for working on this sunho! I think this is almost ready to land as is. Just pointing out a few minor details I encountered while reading through.

llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch64.h
25 ↗(On Diff #431630)

This originates from my initial AArch64 patch. Looking at the other backends, no-one uses ALL-CAPS for such an enum anymore.

While you are here, could you fix it as well? I think the naming convention to follow is the one used in the MachO backends, so this would become ELFBranch26. If I understand correctly, ELF_aarch64 relocation resolution would then generalize it into aarch64::Branch26. The getELFAarch64RelocationKindName() function would need adjustment as well.

llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
202

All these fixups are now automatically available in the AArch64 backend as well? That's amazing! Let's talk about the testing story for it in our weekly today.

llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp
112

I think Lang shortly mentioned it in Discord already: The default block here is counter-productive and causes a compiler warning, because LLVM builds with -Wcovered-switch-default. If you remove the default and more enum values are added in the future, the compiler can warn us in case we forget to handle them in this switch. That's a very handy mechanism.

184

We could now use getGenericEdgeKindName() instead of the llvm_unreachable() here

sunho updated this revision to Diff 431992.May 25 2022, 7:46 AM

Would it help to move the implementation of applyFixup to aarch64.cpp to not pollute headers? The declaration can stay in the header.

sunho added a comment.May 25 2022, 8:15 AM

I just followed what x86 backend was doing, but I don't see any reason against moving it to aarch64.cpp.

sunho updated this revision to Diff 432858.May 30 2022, 12:51 AM

Move fixup function to aarch64.cpp

sunho marked 4 inline comments as done.May 30 2022, 12:52 AM
sunho updated this revision to Diff 432879.May 30 2022, 3:29 AM

Format using latest clang-format

sgraenitz accepted this revision.Jun 5 2022, 12:03 PM

LGTM, thanks for working on this!

Your patch touches the MachO implementations as well, so let's wait for @lhames to have a look before landing it.

This revision is now accepted and ready to land.Jun 5 2022, 12:03 PM
lhames accepted this revision.Jun 6 2022, 9:28 PM

LGTM. This is great work -- Thanks @sunho!

llvm/include/llvm/ExecutionEngine/JITLink/ELF_aarch64.h
43 ↗(On Diff #432879)

This can also be moved down to the .cpp file.

25 ↗(On Diff #431630)

This enum should be moved down to the .cpp file anyway -- this is an implementation detail of the ELFAArch64LinkGraphBuilder.

llvm/include/llvm/ExecutionEngine/JITLink/MachO_arm64.h
20–21

This enum should be sunk into MachO_arm64.cpp file now, similar to MachOLinkGraphBuilder_x86_64::MachONormalizedRelocationType. That can happen in a follow-up patch though.

llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
105–106

Keeping TLVPage21 and GOTPage21 here is a good idea for this initial patch (we want it to be a straightforward hoist of the code from the MachO backend). In a future patch, however, they should be removed from applyFixup. Instead, we'll lower them to simpler edge kinds (e.g. deltas) inside the GOT construction pass. That way applyFixup only handles "simple" edges (expression/operand fixup only), and if we encounter a complex edge we can error out, since it should have been lowered by an earlier pass.

194–197

This triggered a covered switch warning for me:

[660/896] Building CXX object lib/ExecutionEngine/JITLink/CMakeFiles/LLVMJITLink.dir/ELF_aarch64.cpp.o
llvm-github/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp:110:5: warning: default label in switch which covers all enumeration values [-Wcovered-switch-default]
    default:
    ^
llvm-github/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp:110:5: warning: default label in switch which covers all enumeration values [-Wcovered-switch-default]
llvm-github/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp:67:54: note: in instantiation of member function 'llvm::jitlink::ELFLinkGraphBuilder_aarch64<llvm::object::ELFType<llvm::support::little, true>>::addSingleRelocation' requested here
                                              &Self::addSingleRelocation))
                                                     ^
llvm-github/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp:148:10: note: in instantiation of member function 'llvm::jitlink::ELFLinkGraphBuilder_aarch64<llvm::object::ELFType<llvm::support::little, true>>::addRelocations' requested here
  return ELFLinkGraphBuilder_aarch64<object::ELF64LE>((*ELFObj)->getFileName(),

I think it can just be commented out for now, and re-enabled when the GOT edges are moved out of applyFixup.

lhames added inline comments.Jun 6 2022, 9:31 PM
llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
194–197

This triggered a covered switch warning for me: ...

Ignore this -- it's a stale review comments that I failed to remove.

sunho updated this revision to Diff 434852.Jun 7 2022, 9:41 AM

Make enums and related functions private

sunho marked 4 inline comments as done.Jun 7 2022, 9:41 AM
lhames accepted this revision.Jun 7 2022, 11:24 AM