[PATCH] D148238: [JITLink][RISCV] Handle R_RISCV_CALL_PLT fixups

Job Noorman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 13 08:20:41 PDT 2023


jobnoorman created this revision.
jobnoorman added reviewers: lhames, StephenFan.
Herald added subscribers: asb, luke, pmatos, VincentWu, vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
jobnoorman requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, eopXD.
Herald added a project: LLVM.

In the default link configuration, PLT stubs are created automatically
for R_RISCV_CALL_PLT relocations and the relocation itself is
transformed to R_RISCV_CALL (PerGraphGOTAndPLTStubsBuilder_ELF_riscv).
Only the latter is later handled when applying fixups and the former is
simply ignored.

This patch proposes to handle R_RISCV_CALL_PLT anyway when applying
fixups to support custom configurations that do not need automatic PLT
creation. An example of this is BOLT where PLT entries from the input
binary are reused (D147544 <https://reviews.llvm.org/D147544>).

As a side note, I would like to point out that R_RISCV_CALL has been
deprecated. [1] Both GCC and LLVM seem to not generate it anymore and
always use R_RISCV_CALL_PLT (even for calls that do not need a PLT
entry). So I'm not sure if the current strategy of generating PLT
entries based on relocation type is correct. This [2] suggests basing
this on whether the target symbol is preemptable.

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/340
[2] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/98


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148238

Files:
  llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp


Index: llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
===================================================================
--- llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
+++ llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
@@ -229,6 +229,7 @@
           (RawInstr & 0xFFF) | Imm20 | Imm10_1 | Imm11 | Imm19_12;
       break;
     }
+    case R_RISCV_CALL_PLT:
     case R_RISCV_CALL: {
       int64_t Value = E.getTarget().getAddress() + E.getAddend() - FixupAddress;
       int64_t Hi = Value + 0x800;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148238.513247.patch
Type: text/x-patch
Size: 504 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230413/8ca97624/attachment.bin>


More information about the llvm-commits mailing list