70 lines · plain
1# REQUIRES: loongarch2 3# RUN: rm -rf %t && split-file %s %t4# RUN: llvm-mc --filetype=obj --triple=loongarch64-unknown-elf %t/a.s -o %t/a.o5 6# RUN: ld.lld %t/a.o --section-start=.text=0x20010 --section-start=.sec.foo=0x60020 -o %t/exe17# RUN: llvm-objdump --no-show-raw-insn -d %t/exe1 | FileCheck --match-full-lines %s --check-prefix=EXE18## hi20 = target - pc + (1 << 17) >> 18 = 0x60020 - 0x20010 + 0x20000 >> 18 = 19## lo18 = target - pc & (1 << 18) - 1 = 0x60020 - 0x20010 & 0x3ffff = 1610# EXE1: 20010: pcaddu18i $t0, 111# EXE1-NEXT: 20014: jirl $zero, $t0, 16 <foo>12 13# RUN: ld.lld %t/a.o --section-start=.text=0x20010 --section-start=.sec.foo=0x40020 -o %t/exe214# RUN: llvm-objdump --no-show-raw-insn -d %t/exe2 | FileCheck --match-full-lines %s --check-prefix=EXE215## hi20 = target - pc + (1 << 17) >> 18 = 0x40020 - 0x20010 + 0x20000 >> 18 = 116## lo18 = target - pc & (1 << 18) - 1 = 0x40020 - 0x20010 & 0x3ffff = -13105617# EXE2: 20010: pcaddu18i $t0, 118# EXE2-NEXT: 20014: jirl $zero, $t0, -131056 <foo>19 20# RUN: ld.lld %t/a.o -shared -T %t/a.t -o %t/a.so21# RUN: llvm-readelf -x .got.plt %t/a.so | FileCheck --check-prefix=GOTPLT %s22# RUN: llvm-objdump -d --no-show-raw-insn %t/a.so | FileCheck --check-prefix=SO %s23## 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, 030# SO-NEXT: nop31 32# SO: Disassembly of section .text:33# SO: <_start>:34## hi20 = foo@plt - pc + (1 << 17) >> 18 = 0x1234520 - 0x1274670 + 0x20000 >> 18 = -135## lo18 = foo@plt - pc & (1 << 18) - 1 = 0x1234520 - 0x1274670 & 0x3ffff = -33636# SO-NEXT: pcaddu18i $t0, -1{{$}}37# SO-NEXT: jirl $zero, $t0, -336 <.plt+0x20>{{$}}38 39# GOTPLT: section '.got.plt':40# GOTPLT-NEXT: 0x01274730 00000000 00000000 00000000 0000000041# GOTPLT-NEXT: 0x01274740 00452301 0000000042 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 %s45# ERROR-RANGE: error: [[FILE]]:(.text+0x0): relocation R_LARCH_CALL36 out of range: 137438953472 is not in [-137439084544, 137438822399]; references 'foo'46 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 %s50# ERROR-ALIGN: error: [[FILE]]:(.text+0x0): improper alignment for relocation R_LARCH_CALL36: 0x20001 is not aligned to 4 bytes51 52#--- a.t53SECTIONS {54 .plt 0x1234500: { *(.plt) }55 .text 0x1274670: { *(.text) }56}57 58#--- a.s59.text60.global _start61_start:62 .reloc ., R_LARCH_CALL36, foo63 pcaddu18i $t0, 064 jirl $zero, $t0, 065 66.section .sec.foo,"awx"67.global foo68foo:69 ret70