Commit dc9b41f3 authored by luxufan's avatar luxufan
Browse files

[JITLink][RISCV] Add relocation fixup test

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
parent d6b49937
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
# 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
+15 −9
Original line number Diff line number Diff line
@@ -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:      -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
@@ -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