109 lines · plain
1# REQUIRES: loongarch2# RUN: echo '.globl bar, weak; .type bar,@function; .type weak,@function; bar: weak:' > %t1.s3 4# RUN: llvm-mc --filetype=obj --triple=loongarch32 %t1.s -o %t1.32.o5# RUN: ld.lld -shared %t1.32.o -soname=t1.32.so -o %t1.32.so6# RUN: llvm-mc --filetype=obj --triple=loongarch32 %s -o %t.32.o7# RUN: ld.lld %t.32.o %t1.32.so -z separate-code -o %t.328# RUN: llvm-readelf -S -s %t.32 | FileCheck --check-prefixes=SEC,NM %s9# RUN: llvm-readobj -r %t.32 | FileCheck --check-prefix=RELOC32 %s10# RUN: llvm-readelf -x .got.plt %t.32 | FileCheck --check-prefix=GOTPLT32 %s11# RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck --check-prefixes=DIS,DIS32 %s12 13# RUN: llvm-mc --filetype=obj --triple=loongarch64 %t1.s -o %t1.64.o14# RUN: ld.lld -shared %t1.64.o -soname=t1.64.so -o %t1.64.so15# RUN: llvm-mc --filetype=obj --triple=loongarch64 %s -o %t.64.o16# RUN: ld.lld %t.64.o %t1.64.so -z separate-code -o %t.6417# RUN: llvm-readelf -S -s %t.64 | FileCheck --check-prefixes=SEC,NM %s18# RUN: llvm-readobj -r %t.64 | FileCheck --check-prefix=RELOC64 %s19# RUN: llvm-readelf -x .got.plt %t.64 | FileCheck --check-prefix=GOTPLT64 %s20# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck --check-prefixes=DIS,DIS64 %s21 22# SEC: .plt PROGBITS {{0*}}0002002023 24## A canonical PLT has a non-zero st_value. bar and weak are called but their25## addresses are not taken, so a canonical PLT is not necessary.26# NM: {{0*}}00000000 0 FUNC GLOBAL DEFAULT UND bar27# NM: {{0*}}00000000 0 FUNC WEAK DEFAULT UND weak28 29## The .got.plt slots relocated by .rela.plt point to .plt30## This is required by glibc.31# RELOC32: .rela.plt {32# RELOC32-NEXT: 0x40070 R_LARCH_JUMP_SLOT bar 0x033# RELOC32-NEXT: 0x40074 R_LARCH_JUMP_SLOT weak 0x034# RELOC32-NEXT: }35# GOTPLT32: section '.got.plt'36# GOTPLT32-NEXT: 0x00040068 00000000 00000000 20000200 2000020037 38# RELOC64: .rela.plt {39# RELOC64-NEXT: 0x400E0 R_LARCH_JUMP_SLOT bar 0x040# RELOC64-NEXT: 0x400E8 R_LARCH_JUMP_SLOT weak 0x041# RELOC64-NEXT: }42# GOTPLT64: section '.got.plt'43# GOTPLT64-NEXT: 0x000400d0 00000000 00000000 00000000 0000000044# GOTPLT64-NEXT: 0x000400e0 20000200 00000000 20000200 0000000045 46# DIS: <_start>:47## Direct call48## foo - . = 0x20010-0x20000 = 1649# DIS-NEXT: 20000: bl 1650## bar@plt - . = 0x20040-0x20004 = 6051# DIS-NEXT: 20004: bl 6052## bar@plt - . = 0x20040-0x20008 = 5653# DIS-NEXT: 20008: bl 5654## weak@plt - . = 0x20050-0x2000c = 6855# DIS-NEXT: 2000c: bl 6856# DIS: <foo>:57# DIS-NEXT: 20010:58 59# DIS: Disassembly of section .plt:60# DIS: <.plt>:61## 32-bit: .got.plt - .plt = 0x40068 - 0x20020 = 4096*32+7262# DIS32-NEXT: pcaddu12i $t2, 3263# DIS32-NEXT: sub.w $t1, $t1, $t364# DIS32-NEXT: ld.w $t3, $t2, 7265# DIS32-NEXT: addi.w $t1, $t1, -4466# DIS32-NEXT: addi.w $t0, $t2, 7267# DIS32-NEXT: srli.w $t1, $t1, 268# DIS32-NEXT: ld.w $t0, $t0, 469# DIS32-NEXT: jr $t370 71## 64-bit: .got.plt - .plt = 0x400d0 - 0x20020 = 4096*32+17672# DIS64-NEXT: pcaddu12i $t2, 3273# DIS64-NEXT: sub.d $t1, $t1, $t374# DIS64-NEXT: ld.d $t3, $t2, 17675# DIS64-NEXT: addi.d $t1, $t1, -4476# DIS64-NEXT: addi.d $t0, $t2, 17677# DIS64-NEXT: srli.d $t1, $t1, 178# DIS64-NEXT: ld.d $t0, $t0, 879# DIS64-NEXT: jr $t380 81## 32-bit: &.got.plt[bar]-. = 0x40070-0x20040 = 4096*32+4882## 64-bit: &.got.plt[bar]-. = 0x400e0-0x20040 = 4096*32+16083# DIS: 20040: pcaddu12i $t3, 3284# DIS32-NEXT: ld.w $t3, $t3, 4885# DIS64-NEXT: ld.d $t3, $t3, 16086# DIS-NEXT: jirl $t1, $t3, 087# DIS-NEXT: nop88 89## 32-bit: &.got.plt[weak]-. = 0x40074-0x20050 = 4096*32+3690## 64-bit: &.got.plt[weak]-. = 0x400e8-0x20050 = 4096*32+15291# DIS: 20050: pcaddu12i $t3, 3292# DIS32-NEXT: ld.w $t3, $t3, 3693# DIS64-NEXT: ld.d $t3, $t3, 15294# DIS-NEXT: jirl $t1, $t3, 095# DIS-NEXT: nop96 97.global _start, foo, bar98.weak weak99 100_start:101 bl foo102 bl bar103 bl %plt(bar)104 bl weak105 106## foo is local and non-preemptible, no PLT is generated.107foo:108 ret109