xref: /llvm-project/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_riscv64_got_plt_reloc.s (revision bcd1296a1a5989131b188d605b9777d495281c75)
1# RUN: rm -rf %t && mkdir -p %t
2# RUN: llvm-mc -triple=riscv64 -position-independent -filetype=obj \
3# RUN:     -o %t/elf_riscv64_got_plt_reloc.o %s
4# RUN: llvm-jitlink -noexec \
5# RUN:     -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
6# RUN:     -abs external_func=0x1 -abs external_data=0x2 \
7# RUN:     -check %s %t/elf_riscv64_got_plt_reloc.o
8
9## Run the same tests with relaxation enabled.
10# RUN: llvm-mc -triple=riscv64 -position-independent -filetype=obj \
11# RUN:     -mattr=+relax -o %t/elf_riscv64_got_plt_reloc.o %s
12# RUN: llvm-jitlink -noexec \
13# RUN:     -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
14# RUN:     -abs external_func=0x1 -abs external_data=0x2 \
15# RUN:     -check %s %t/elf_riscv64_got_plt_reloc.o
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# Test R_RISCV_GOT_HI20. The low 12 relocation is R_RISCV_PC_REL_LO12. This test case will
29# check both the offset to the GOT entry and its content.
30# jitlink-check: decode_operand(test_got, 1) = (got_addr(elf_riscv64_got_plt_reloc.o, external_data) - test_got + 0x800)[31:12]
31# jitlink-check: decode_operand(test_got+4, 2)[11:0] = (got_addr(elf_riscv64_got_plt_reloc.o, external_data) - test_got)[11:0]
32# jitlink-check: *{8}(got_addr(elf_riscv64_got_plt_reloc.o, external_data)) = external_data
33        .globl test_got
34        .p2align  1
35        .type  test_got,@function
36test_got:
37        auipc a0, %got_pcrel_hi(external_data)
38        ld    a0, %pcrel_lo(test_got)(a0)
39
40        .size test_got, .-test_got
41
42# Test R_RISCV_CALL_PLT.
43# jitlink-check: decode_operand(test_plt, 1) = (stub_addr(elf_riscv64_got_plt_reloc.o, external_func) - test_plt + 0x800)[31:12]
44# jitlink-check: decode_operand(test_plt+4, 2) = (stub_addr(elf_riscv64_got_plt_reloc.o, external_func) - test_plt)[11:0]
45# jitlink-check: *{8}(got_addr(elf_riscv64_got_plt_reloc.o, external_func)) = external_func
46       .globl   test_plt
47       .p2align  1
48       .type    test_got,@function
49test_plt:
50       call external_func@plt
51
52       .size test_plt, .-test_plt
53
54