[JITLink][arm64] Support arm64e JIT'd code (initially enabled for MachO only).
[llvm-project.git] / lld / test / ELF / loongarch-call36.s
blobb593fdf1f6045e21cfa7d61f668dea2e06efbca9
1 # REQUIRES: loongarch
3 # RUN: rm -rf %t && split-file %s %t
4 # RUN: llvm-mc --filetype=obj --triple=loongarch64-unknown-elf %t/a.s -o %t/a.o
6 # RUN: ld.lld %t/a.o --section-start=.text=0x20010 --section-start=.sec.foo=0x60020 -o %t/exe1
7 # RUN: llvm-objdump --no-show-raw-insn -d %t/exe1 | FileCheck --match-full-lines %s --check-prefix=EXE1
8 ## hi20 = target - pc + (1 << 17) >> 18 = 0x60020 - 0x20010 + 0x20000 >> 18 = 1
9 ## lo18 = target - pc & (1 << 18) - 1 = 0x60020 - 0x20010 & 0x3ffff = 16
10 # EXE1: 20010: pcaddu18i $t0, 1
11 # EXE1-NEXT: 20014: jirl $zero, $t0, 16
13 # RUN: ld.lld %t/a.o --section-start=.text=0x20010 --section-start=.sec.foo=0x40020 -o %t/exe2
14 # RUN: llvm-objdump --no-show-raw-insn -d %t/exe2 | FileCheck --match-full-lines %s --check-prefix=EXE2
15 ## hi20 = target - pc + (1 << 17) >> 18 = 0x40020 - 0x20010 + 0x20000 >> 18 = 1
16 ## lo18 = target - pc & (1 << 18) - 1 = 0x40020 - 0x20010 & 0x3ffff = -131056
17 # EXE2: 20010: pcaddu18i $t0, 1
18 # EXE2-NEXT: 20014: jirl $zero, $t0, -131056
20 # RUN: ld.lld %t/a.o -shared -T %t/a.t -o %t/a.so
21 # RUN: llvm-readelf -x .got.plt %t/a.so | FileCheck --check-prefix=GOTPLT %s
22 # RUN: llvm-objdump -d --no-show-raw-insn %t/a.so | FileCheck --check-prefix=SO %s
23 ## PLT should be present in this case.
24 # SO: Disassembly of section .plt:
25 # SO: <.plt>:
26 ## foo@plt:
27 # SO: 1234520: pcaddu12i $t3, 64{{$}}
28 # SO-NEXT: ld.d $t3, $t3, 544{{$}}
29 # SO-NEXT: jirl $t1, $t3, 0
30 # SO-NEXT: nop
32 # SO: Disassembly of section .text:
33 # SO: <_start>:
34 ## hi20 = foo@plt - pc + (1 << 17) >> 18 = 0x1234520 - 0x1274670 + 0x20000 >> 18 = -1
35 ## lo18 = foo@plt - pc & (1 << 18) - 1 = 0x1234520 - 0x1274670 & 0x3ffff = -336
36 # SO-NEXT: pcaddu18i $t0, -1{{$}}
37 # SO-NEXT: jirl $zero, $t0, -336{{$}}
39 # GOTPLT: section '.got.plt':
40 # GOTPLT-NEXT: 0x01274730 00000000 00000000 00000000 00000000
41 # GOTPLT-NEXT: 0x01274740 00452301 00000000
43 # RUN: not ld.lld %t/a.o --section-start=.text=0x20000 --section-start=.sec.foo=0x2000020000 -o /dev/null 2>&1 | \
44 # RUN: FileCheck -DFILE=%t/a.o --check-prefix=ERROR-RANGE %s
45 # ERROR-RANGE: error: [[FILE]]:(.text+0x0): relocation R_LARCH_CALL36 out of range: 137438953472 is not in [-137439084544, 137438822399]; references 'foo'
47 ## Impossible case in reality becasue all LoongArch instructions are fixed 4-bytes long.
48 # RUN: not ld.lld %t/a.o --section-start=.text=0x20000 --section-start=.sec.foo=0x40001 -o /dev/null 2>&1 | \
49 # RUN: FileCheck -DFILE=%t/a.o --check-prefix=ERROR-ALIGN %s
50 # ERROR-ALIGN: error: [[FILE]]:(.text+0x0): improper alignment for relocation R_LARCH_CALL36: 0x20001 is not aligned to 4 bytes
52 #--- a.t
53 SECTIONS {
54 .plt 0x1234500: { *(.plt) }
55 .text 0x1274670: { *(.text) }
58 #--- a.s
59 .text
60 .global _start
61 _start:
62 .reloc ., R_LARCH_CALL36, foo
63 pcaddu18i $t0, 0
64 jirl $zero, $t0, 0
66 .section .sec.foo,"awx"
67 .global foo
68 foo:
69 ret