[llvm] dc9b41f - [JITLink][RISCV] Add relocation fixup test
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 5 23:36:43 PDT 2021
Author: luxufan
Date: 2021-08-06T14:35:59+08:00
New Revision: dc9b41f3b45fdd88c5a259e8abd6ede57f457ad0
URL: https://github.com/llvm/llvm-project/commit/dc9b41f3b45fdd88c5a259e8abd6ede57f457ad0
DIFF: https://github.com/llvm/llvm-project/commit/dc9b41f3b45fdd88c5a259e8abd6ede57f457ad0.diff
LOG: [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
Added:
llvm/test/ExecutionEngine/JITLink/RISCV/ELF_abs_reloc.s
Modified:
llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
Removed:
################################################################################
diff --git a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_abs_reloc.s b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_abs_reloc.s
new file mode 100644
index 0000000000000..a70a8b8cbc6fd
--- /dev/null
+++ b/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, at 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, at function
+test_abs_rel:
+ lui a0, %hi(external_data)
+ lw a0, %lo(external_data)(a0)
+
+ .size test_abs_rel, .-test_abs_rel
diff --git a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
index 02afc9f6ae33d..25ae81fcd2f13 100644
--- a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
+++ b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
@@ -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
@@ -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, at 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, at 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, at function
+test_call:
+ call external_func
+ ret
+ .size test_call, .-test_call
More information about the llvm-commits
mailing list