xref: /llvm-project/lld/test/ELF/riscv-ifunc-nonpreemptible.s (revision 691b97c884a15a7eac641ddf67c9f2f30fb4e747)
1# REQUIRES: riscv
2# RUN: llvm-mc -filetype=obj -triple=riscv32 %s -o %t.32.o
3# RUN: ld.lld -pie %t.32.o -o %t.32
4# RUN: ld.lld -pie %t.32.o -o %t.32-apply --apply-dynamic-relocs
5# RUN: llvm-readobj -r -x .got.plt %t.32 | FileCheck --check-prefixes=RELOC32,NO-APPLY-RELOC32 %s
6# RUN: llvm-readobj -r -x .got.plt %t.32-apply | FileCheck --check-prefixes=RELOC32,APPLY-RELOC32 %s
7# RUN: llvm-readelf -s %t.32 | FileCheck --check-prefix=SYM32 %s
8# RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck --check-prefix=DIS32 %s
9
10# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.64.o
11# RUN: ld.lld -pie %t.64.o -o %t.64
12# RUN: ld.lld -pie %t.64.o -o %t.64-apply --apply-dynamic-relocs
13# RUN: llvm-readobj -r -x .got.plt %t.64 | FileCheck --check-prefixes=RELOC64,NO-APPLY-RELOC64 %s
14# RUN: llvm-readobj -r -x .got.plt %t.64-apply | FileCheck --check-prefixes=RELOC64,APPLY-RELOC64 %s
15# RUN: llvm-readelf -s %t.64 | FileCheck --check-prefix=SYM64 %s
16# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck --check-prefix=DIS64 %s
17
18# RELOC32:      .rela.dyn {
19# RELOC32-NEXT:   0x3200 R_RISCV_IRELATIVE - 0x117C
20# RELOC32-NEXT: }
21# RELOC32-LABEL:    Hex dump of section '.got.plt':
22# NO-APPLY-RELOC32: 0x00003200 00000000
23# APPLY-RELOC32:    0x00003200 7c110000
24# RELOC32-EMPTY:
25
26# SYM32: 0001190 0 FUNC GLOBAL DEFAULT {{.*}} func
27
28# DIS32:      <_start>:
29# DIS32-NEXT: 1180: auipc a0, 0x0
30# DIS32-NEXT:       addi a0, a0, 0x10
31# DIS32:      Disassembly of section .iplt:
32# DIS32:      <func>:
33## 32-bit: &.got.plt[func]-. = 0x3200-0x1190 = 4096*2+0x70
34# DIS32-NEXT: 1190: auipc t3, 0x2
35# DIS32-NEXT:       lw t3, 0x70(t3)
36# DIS32-NEXT:       jalr t1, t3
37# DIS32-NEXT:       nop
38
39# RELOC64:      .rela.dyn {
40# RELOC64-NEXT:   0x3340 R_RISCV_IRELATIVE - 0x1260
41# RELOC64-NEXT: }
42# RELOC64-LABEL:    Hex dump of section '.got.plt':
43# NO-APPLY-RELOC64: 0x00003340 00000000 00000000
44# APPLY-RELOC64:    0x00003340 60120000 00000000
45# RELOC64-EMPTY:
46
47# SYM64: 000000000001270 0 FUNC GLOBAL DEFAULT {{.*}} func
48
49# DIS64:      <_start>:
50# DIS64-NEXT: 1264: auipc a0, 0x0
51# DIS64-NEXT:       addi a0, a0, 0xc
52# DIS64:      Disassembly of section .iplt:
53# DIS64:      <func>:
54## 64-bit: &.got.plt[func]-. = 0x3340-0x1270 = 4096*2+0xd0
55# DIS64-NEXT: 1270: auipc t3, 0x2
56# DIS64-NEXT:       ld t3, 0xd0(t3)
57# DIS64-NEXT:       jalr t1, t3
58# DIS64-NEXT:       nop
59
60.text
61.globl func
62.type func, @gnu_indirect_function
63func:
64  ret
65
66.globl _start
67_start:
68.L:
69  auipc a0, %pcrel_hi(func)
70  addi a0, a0, %pcrel_lo(.L)
71