Skip to content

Commit

Permalink
[JITLink][RISCV] Add relocation fixup test
Browse files Browse the repository at this point in the history
This patch add R_RISCV_HI20, R_RISCV_LO12 and R_RISCV_CALL relocation test

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D107327
  • Loading branch information
luxufan committed Aug 6, 2021
1 parent d6b4993 commit dc9b41f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
33 changes: 33 additions & 0 deletions llvm/test/ExecutionEngine/JITLink/RISCV/ELF_abs_reloc.s
@@ -0,0 +1,33 @@
# RUN: rm -rf %t && mkdir -p %t
# RUN: llvm-mc -triple=riscv64 -filetype=obj -o %t/elf_riscv64_non_pc_indirect_reloc.o %s
# RUN: llvm-mc -triple=riscv32 -filetype=obj -o %t/elf_riscv32_non_pc_indirect_reloc.o %s
# RUN: llvm-jitlink -noexec -slab-allocate 100Kb -slab-address 0xfff00000 -define-abs external_data=0xfff10000\
# RUN: -check %s %t/elf_riscv64_non_pc_indirect_reloc.o
# RUN: llvm-jitlink -noexec -slab-allocate 100Kb -slab-address 0xfff00000 -define-abs external_data=0xfff10000\
# RUN: -check %s %t/elf_riscv32_non_pc_indirect_reloc.o
#

.text
.file "testcase.c"

# Empty main entry point.
.globl main
.p2align 1
.type main,@function
main:
ret

.size main, .-main

# Test R_RISCV_HI20 and R_RISCV_LO12

# jitlink-check: decode_operand(test_abs_rel, 1) = (external_data + 0x800)[31:12]
# jitlink-check: decode_operand(test_abs_rel+4, 2)[11:0] = (external_data)[11:0]
.globl test_abs_rel
.p2align 1
.type test_abs_rel,@function
test_abs_rel:
lui a0, %hi(external_data)
lw a0, %lo(external_data)(a0)

.size test_abs_rel, .-test_abs_rel
24 changes: 15 additions & 9 deletions llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
Expand Up @@ -2,8 +2,10 @@
# RUN: llvm-mc -triple=riscv64 -position-independent -filetype=obj -o %t/elf_riscv64_sm_pic_reloc.o %s
# RUN: llvm-mc -triple=riscv32 -position-independent -filetype=obj -o %t/elf_riscv32_sm_pic_reloc.o %s
# RUN: llvm-jitlink -noexec -slab-allocate 100Kb -slab-address 0xfff00000 \
# RUN: -define-abs external_func=0x1 -define-abs external_data=0x2 \
# RUN: -check %s %t/elf_riscv64_sm_pic_reloc.o
# RUN: llvm-jitlink -noexec -slab-allocate 100Kb -slab-address 0xfff00000 \
# RUN: llvm-jitlink -noexec -slab-allocate 100Kb -slab-address 0xfff00000\
# RUN: -define-abs external_func=0x1 -define-abs external_data=0x2 \
# RUN: -check %s %t/elf_riscv32_sm_pic_reloc.o
#
# Test ELF small/PIC relocations
Expand All @@ -21,20 +23,24 @@ main:
.size main, .-main

# Test R_RISCV_PCREL_HI20 and R_RISCV_PCREL_LO
# jitlink-check: decode_operand(test_pcrel32, 1) = ((named_data - test_pcrel32) + 0x800)[31:12]
# jitlink-check: decode_operand(test_pcrel32+4, 2)[11:0] = (named_data - test_pcrel32)[11:0]
# jitlink-check: decode_operand(test_pcrel32, 1) = ((external_data - test_pcrel32) + 0x800)[31:12]
# jitlink-check: decode_operand(test_pcrel32+4, 2)[11:0] = (external_data - test_pcrel32)[11:0]
.globl test_pcrel32
.p2align 1
.type test_pcrel32,@function
test_pcrel32:
auipc a0, %pcrel_hi(named_data)
auipc a0, %pcrel_hi(external_data)
lw a0, %pcrel_lo(test_pcrel32)(a0)

.size test_pcrel32, .-test_pcrel32

.data
.type named_data,@object
# 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]
.globl test_call
.p2align 1
named_data:
.quad 42
.size named_data, 4
.type test_call,@function
test_call:
call external_func
ret
.size test_call, .-test_call

0 comments on commit dc9b41f

Please sign in to comment.