Skip to content

Commit

Permalink
[RISCV][JitLink] Propagate error from Expected<T> result during R_RIS…
Browse files Browse the repository at this point in the history
…CV_PCREL_HI20 parsing

related issue: #59139

Differential Revision: https://reviews.llvm.org/D138781
  • Loading branch information
dkurt authored and preames committed Dec 7, 2022
1 parent 390029b commit a2c9f12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
Expand Up @@ -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]
Expand Down

0 comments on commit a2c9f12

Please sign in to comment.