[llvm] a2c9f12 - [RISCV][JitLink] Propagate error from Expected<T> result during R_RISCV_PCREL_HI20 parsing

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 7 08:26:50 PST 2022


Author: Dmitry Kurtaev
Date: 2022-12-07T08:26:38-08:00
New Revision: a2c9f12dd6acf0134e6e6d6e78d7e8ae3083cf24

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

LOG: [RISCV][JitLink] Propagate error from Expected<T> result during R_RISCV_PCREL_HI20 parsing

related issue: https://github.com/llvm/llvm-project/issues/59139

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
index c7839ac81ee7e..91f0fe0f0abeb 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
@@ -302,6 +302,8 @@ class ELFJITLinker_riscv : public JITLinker<ELFJITLinker_riscv> {
       // pairs with current relocation R_RISCV_PCREL_LO12_S. So here may need a
       // check.
       auto RelHI20 = getRISCVPCRelHi20(E);
+      if (!RelHI20)
+        return RelHI20.takeError();
       int64_t Value = RelHI20->getTarget().getAddress() +
                       RelHI20->getAddend() - E.getTarget().getAddress();
       int64_t Lo = Value & 0xFFF;

diff  --git a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
index 1a420b09d9c96..01249005d0dda 100644
--- a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
+++ b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
@@ -38,6 +38,18 @@ test_pcrel32:
 
         .size   test_pcrel32, .-test_pcrel32
 
+# Test R_RISCV_PCREL_HI20 and R_RISCV_PCREL_LO12_S
+# jitlink-check: decode_operand(test_pcrel32_s, 1) = ((external_data - test_pcrel32_s) + 0x800)[31:12]
+# jitlink-check: decode_operand(test_pcrel32_s+4, 2)[11:0] = (external_data - test_pcrel32_s)[11:0]
+        .globl  test_pcrel32_s
+        .p2align  1
+        .type   test_pcrel32_s, at function
+test_pcrel32_s:
+        auipc a0, %pcrel_hi(external_data)
+        sw  a0, %pcrel_lo(test_pcrel32_s)(a0)
+
+        .size   test_pcrel32_s, .-test_pcrel32_s
+
 # Test R_RISCV_CALL
 # jitlink-check: decode_operand(test_call, 1) = ((external_func - test_call) + 0x800)[31:12]
 # jitlink-check: decode_operand(test_call+4, 2)[11:0] = (external_func - test_call)[11:0]


        


More information about the llvm-commits mailing list