This is an archive of the discontinued LLVM Phabricator instance.

[JITLink] Optimize GOTPCRELX Relocations
ClosedPublic

Authored by StephenFan on Aug 18 2021, 1:43 AM.

Details

Summary

This patch optimize the GOTPCRELX Reloations, which is described in X86-64 psabi chapter B.2. And Not all optimization of this chapter is implemented.

  1. Convert call and jmp has been implemented
  2. Convert mov, but the optimization that when the symbol is defined in the lower 32-bit address space, memory operand in mov can be convertted into immediate operand has not been implemented.
  3. Conver Test and Binop has not been implemented.

The new test file named ELF_got_plt_optimizations.s has been added, and I moved some test cases about optimization of got/plt from ELF_x86_64_small_pic_relocations.s to the new test file.

By referencing the lld, so, the optimization Convert call and jmp is not same as what psabi says, and I have explained it in the comment.

Diff Detail

Event Timeline

StephenFan created this revision.Aug 18 2021, 1:43 AM
StephenFan requested review of this revision.Aug 18 2021, 1:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2021, 1:43 AM

Change test file name from ELF_got_plt_optimization.s to ELF_x86-64_got_plt_optimizations.s

lhames accepted this revision.Aug 18 2021, 2:19 AM

This is very cool -- thanks Stephen!

Please address the inline comments, otherwise LGTM!

llvm/lib/ExecutionEngine/JITLink/x86_64.cpp
82–84

BlockData should be FixupData.

I know that was my name originally, but now that this function is getting more attention we should fix my old mistakes. ;)

95

The preferred way to express this is JITTargetAddress EdgeAddr = B->getFixupAddress(E).

100–101

I assume the rationale here is "if neither of these is true then there's no point looking at the instruction sequence more closely"? I would add a comment for that to make it clear.

llvm/test/ExecutionEngine/JITLink/X86/ELF_x86-64_small_pic_relocations.s
71–81

Could you add to the comment to note that leal is used here to suppress optimization (in case anybody looks at it and wonders why it isn't a mov).

This revision is now accepted and ready to land.Aug 18 2021, 2:19 AM
  1. Local variable BlockData renamed to FixupData.
  2. Get edge address by class block's getFixupAddress method.
  3. Add comment.
StephenFan marked 3 inline comments as done.

Improve comments.

This revision was landed with ongoing or failed builds.Aug 18 2021, 7:30 PM
This revision was automatically updated to reflect the committed changes.