xref: /llvm-project/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s (revision 26ee8947702d79ce2cab8e577f713685a5ca4a55)
1# RUN: rm -rf %t && mkdir -p %t
2# RUN: llvm-mc -triple=riscv64 -position-independent -filetype=obj \
3# RUN:     -o %t/elf_riscv64_sm_pic_reloc.o %s
4# RUN: llvm-mc -triple=riscv32 -position-independent -filetype=obj \
5# RUN:     -o %t/elf_riscv32_sm_pic_reloc.o %s
6# RUN: llvm-jitlink -noexec \
7# RUN:     -slab-allocate 100Kb -slab-address 0x1ff00000 -slab-page-size 4096 \
8# RUN:     -abs external_data=0x2 \
9# RUN:     -check %s %t/elf_riscv64_sm_pic_reloc.o
10# RUN: llvm-jitlink -noexec \
11# RUN:     -slab-allocate 100Kb -slab-address 0x1ff00000 -slab-page-size 4096 \
12# RUN:     -abs external_data=0x2 \
13# RUN:     -check %s %t/elf_riscv32_sm_pic_reloc.o
14#
15# Test ELF small/PIC relocations
16
17        .text
18        .file   "testcase.c"
19
20# Empty main entry point.
21        .globl  main
22        .p2align  1
23        .type   main,@function
24main:
25        ret
26
27        .size   main, .-main
28
29# Test R_RISCV_PCREL_HI20 and R_RISCV_PCREL_LO
30# jitlink-check: decode_operand(test_pcrel32, 1) = ((external_data - test_pcrel32) + 0x800)[31:12]
31# jitlink-check: decode_operand(test_pcrel32+4, 2)[11:0] = (external_data - test_pcrel32)[11:0]
32        .globl  test_pcrel32
33        .p2align  1
34        .type   test_pcrel32,@function
35test_pcrel32:
36        auipc a0, %pcrel_hi(external_data)
37        lw  a0, %pcrel_lo(test_pcrel32)(a0)
38
39        .size   test_pcrel32, .-test_pcrel32
40
41# Test R_RISCV_PCREL_HI20 and R_RISCV_PCREL_LO12_S
42# jitlink-check: decode_operand(test_pcrel32_s, 1) = ((external_data - test_pcrel32_s) + 0x800)[31:12]
43# jitlink-check: decode_operand(test_pcrel32_s+4, 2)[11:0] = (external_data - test_pcrel32_s)[11:0]
44        .globl  test_pcrel32_s
45        .p2align  1
46        .type   test_pcrel32_s,@function
47test_pcrel32_s:
48        auipc a0, %pcrel_hi(external_data)
49        sw  a0, %pcrel_lo(test_pcrel32_s)(a0)
50
51        .size   test_pcrel32_s, .-test_pcrel32_s
52
53# Test R_RISCV_CALL
54# jitlink-check: decode_operand(test_call, 1) = ((internal_func - test_call) + 0x800)[31:12]
55# jitlink-check: decode_operand(test_call+4, 2)[11:0] = (internal_func - test_call)[11:0]
56        .globl test_call
57        .p2align  1
58        .type  test_call,@function
59test_call:
60        .reloc ., R_RISCV_CALL, internal_func
61        auipc ra, 0
62        jalr ra
63        ret
64        .size test_call, .-test_call
65
66# Test R_RISCV_CALL_PLT
67# jitlink-check: decode_operand(test_call_plt, 1) = ((internal_func - test_call_plt) + 0x800)[31:12]
68# jitlink-check: decode_operand(test_call_plt+4, 2)[11:0] = (internal_func - test_call_plt)[11:0]
69        .globl test_call_plt
70        .p2align  1
71        .type  test_call_plt,@function
72test_call_plt:
73        .reloc ., R_RISCV_CALL_PLT, internal_func
74        auipc ra, 0
75        jalr ra
76        ret
77        .size test_call_plt, .-test_call_plt
78
79       .globl   internal_func
80       .p2align  1
81       .type    internal_func,@function
82internal_func:
83       ret
84       .size internal_func, .-internal_func
85