[RISCV][JitLink] Propagate error from Expected<T> result during R_RISCV_PCREL_HI20...
authorDmitry Kurtaev <dmitry.kurtaev@gmail.com>
Wed, 7 Dec 2022 16:19:33 +0000 (08:19 -0800)
committerPhilip Reames <listmail@philipreames.com>
Wed, 7 Dec 2022 16:26:38 +0000 (08:26 -0800)
related issue: https://github.com/llvm/llvm-project/issues/59139

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

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

index c7839ac..91f0fe0 100644 (file)
@@ -302,6 +302,8 @@ private:
       // 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;
index 1a420b0..0124900 100644 (file)
@@ -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,@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]