1# REQUIRES: ppc 2 3# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unkown-linux %p/Inputs/ppc64-toc-relax-shared.s -o %t.o 4# RUN: ld.lld -shared -soname=t.so %t.o -o %t.so 5# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t1.o 6# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-toc-relax.s -o %t2.o 7# RUN: llvm-readobj -r %t1.o | FileCheck --check-prefix=RELOCS %s 8# RUN: ld.lld %t1.o %t2.o %t.so -o %t 9# RUN: llvm-readelf -S %t | FileCheck --check-prefix=SECTIONS %s 10# RUN: llvm-nm %t | FileCheck --check-prefix=NM %s 11# RUN: llvm-objdump -D %t | FileCheck %s 12 13# In most cases, .toc contains exclusively addresses relocated by R_PPC64_ADDR16. 14# Rarely .toc contain constants or variables. 15# Test we can still perform toc-indirect to toc-relative relaxation. 16 17# RELOCS: .rela.text { 18# RELOCS-NEXT: 0x0 R_PPC64_TOC16_HA .toc 0x0 19# RELOCS-NEXT: 0x4 R_PPC64_TOC16_LO_DS .toc 0x0 20# RELOCS-NEXT: 0x8 R_PPC64_TOC16_HA .toc 0x8 21# RELOCS-NEXT: 0xC R_PPC64_TOC16_LO_DS .toc 0x8 22# RELOCS-NEXT: 0x10 R_PPC64_TOC16_HA .toc 0x10 23# RELOCS-NEXT: 0x14 R_PPC64_TOC16_LO_DS .toc 0x10 24# RELOCS-NEXT: } 25 26# SECTIONS: .got PROGBITS 00000000100202f8 27# SECTIONS: .toc PROGBITS 00000000100202f8 28 29# NM: 0000000010030310 D default 30 31# .LCONST1 is .toc[0]. 32# .LCONST1 - (.got+0x8000) = 0x10020350 - (0x10020350+0x8000) = -32768 33# CHECK: nop 34# CHECK: lwa 3, -32768(2) 35 addis 3, 2, .LCONST1@toc@ha 36 lwa 3, .LCONST1@toc@l(3) 37 38# .LCONST2 is .toc[1] 39# .LCONST2 - (.got+0x8000) = 0x10020358 - (0x10020350+0x8000) = -32760 40# CHECK: nop 41# CHECK: ld 4, -32760(2) 42 addis 4, 2, .LCONST2@toc@ha 43 ld 4, .LCONST2@toc@l(4) 44 45# .Ldefault is .toc[2]. `default` is not preemptable when producing an executable. 46# After toc-indirection to toc-relative relaxation, it is loaded using an 47# offset relative to r2. 48# CHECK: addis 5, 2, 1 49# CHECK: addi 5, 5, -32744 50# CHECK: lwa 5, 0(5) 51 addis 5, 2, .Ldefault@toc@ha 52 ld 5, .Ldefault@toc@l(5) 53 lwa 5, 0(5) 54 55.section .toc,"aw",@progbits 56.LCONST1: 57 .quad 11 58.LCONST2: 59 .quad 22 60.Ldefault: 61 .tc default[TC],default 62