[llvm] bcd1296 - [JITLink][RISCV] Consider relaxable call edges for PLT edges

Job Noorman via llvm-commits llvm-commits at lists.llvm.org
Mon May 22 01:41:44 PDT 2023


Author: Job Noorman
Date: 2023-05-22T10:41:32+02:00
New Revision: bcd1296a1a5989131b188d605b9777d495281c75

URL: https://github.com/llvm/llvm-project/commit/bcd1296a1a5989131b188d605b9777d495281c75
DIFF: https://github.com/llvm/llvm-project/commit/bcd1296a1a5989131b188d605b9777d495281c75.diff

LOG: [JITLink][RISCV] Consider relaxable call edges for PLT edges

For linker relaxation (D149526), a new edge kind (`CallRelaxable`) was
introduced. However, this new kind was not taken into account by
`PerGraphGOTAndPLTStubsBuilder_ELF_riscv`. This patch fixes this.

Reviewed By: StephenFan

Differential Revision: https://reviews.llvm.org/D150957

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
    llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv64_got_plt_reloc.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
index 307bf101f74a7..d07b30ffa48c5 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
@@ -70,13 +70,16 @@ class PerGraphGOTAndPLTStubsBuilder_ELF_riscv
   }
 
   void fixPLTEdge(Edge &E, Symbol &PLTStubs) {
-    assert(E.getKind() == R_RISCV_CALL_PLT && "Not a R_RISCV_CALL_PLT edge?");
+    assert((E.getKind() == R_RISCV_CALL || E.getKind() == R_RISCV_CALL_PLT ||
+            E.getKind() == CallRelaxable) &&
+           "Not a PLT edge?");
     E.setKind(R_RISCV_CALL);
     E.setTarget(PLTStubs);
   }
 
   bool isExternalBranchEdge(Edge &E) const {
-    return (E.getKind() == R_RISCV_CALL || E.getKind() == R_RISCV_CALL_PLT) &&
+    return (E.getKind() == R_RISCV_CALL || E.getKind() == R_RISCV_CALL_PLT ||
+            E.getKind() == CallRelaxable) &&
            !E.getTarget().isDefined();
   }
 

diff  --git a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv64_got_plt_reloc.s b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv64_got_plt_reloc.s
index 8e01b08b5e1ca..76261e8d8f459 100644
--- a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv64_got_plt_reloc.s
+++ b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv64_got_plt_reloc.s
@@ -6,6 +6,13 @@
 # RUN:     -abs external_func=0x1 -abs external_data=0x2 \
 # RUN:     -check %s %t/elf_riscv64_got_plt_reloc.o
 
+## Run the same tests with relaxation enabled.
+# RUN: llvm-mc -triple=riscv64 -position-independent -filetype=obj \
+# RUN:     -mattr=+relax -o %t/elf_riscv64_got_plt_reloc.o %s
+# RUN: llvm-jitlink -noexec \
+# RUN:     -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
+# RUN:     -abs external_func=0x1 -abs external_data=0x2 \
+# RUN:     -check %s %t/elf_riscv64_got_plt_reloc.o
 
         .text
         .file   "testcase.c"


        


More information about the llvm-commits mailing list