1# REQUIRES: ppc
2# RUN: echo 'SECTIONS { \
3# RUN:       .text_low 0x2000: { *(.text_low) } \
4# RUN:       .text_high 0x2002000 : { *(.text_high) } \
5# RUN:       }' > %t.script
6
7# RUN: llvm-mc -filetype=obj -triple=powerpc %s -o %t.o
8# RUN: ld.lld -T %t.script %t.o -o %t
9# RUN: llvm-readelf -r %t | FileCheck --check-prefix=SEC %s
10# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefixes=CHECK,PD %s
11# RUN: llvm-nm --no-sort %t | FileCheck --check-prefix=NM %s
12
13# RUN: ld.lld -T %t.script -pie %t.o -o %t
14# RUN: llvm-readelf -r %t | FileCheck --check-prefix=SEC %s
15# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefixes=CHECK,PI %s
16# RUN: llvm-nm --no-sort %t | FileCheck --check-prefix=NM %s
17
18# SEC: There are no relocations in this file.
19
20# CHECK:      <_start>:
21# CHECK-NEXT:     2000: bl 0x2018
22# CHECK-NEXT:           bl 0x2018
23# CHECK-NEXT:           bl 0x2018
24# CHECK-NEXT:           bl 0x2002008
25# PD-NEXT:              bl 0x2028
26# PI-NEXT:              bl 0x2038
27
28## high = 0x02002008 = 65536*512+8200
29# PD:         <__LongThunk_high>:
30# PD-NEXT:        2018: lis 12, 512
31# PD-NEXT:              addi 12, 12, 8200
32# PD-NEXT:              mtctr 12
33# PD-NEXT:              bctr
34
35## .text_high+16 = 0x02002010 = 65536*512+8208
36# PD:         <__LongThunk_>:
37# PD-NEXT:        2028: lis 12, 512
38# PD-NEXT:              addi 12, 12, 8208
39# PD-NEXT:              mtctr 12
40# PD-NEXT:              bctr
41
42## high-0x2028 = 0x02002008-0x2020 = 65536*512-24
43# PI:         <__LongThunk_high>:
44# PI-NEXT:        2018: mflr 0
45# PI-NEXT:              bcl 20, 31, 0x2020
46# PI-NEXT:        2020: mflr 12
47# PI-NEXT:              addis 12, 12, 512
48# PI-NEXT:              addi 12, 12, -24
49# PI-NEXT:              mtlr 0
50# PI-NEXT:              mtctr 12
51# PI-NEXT:              bctr
52
53## .text_high+16-0x2048 = 0x02002010-0x2048 = 65536*512-48
54# PI:         <__LongThunk_>:
55# PI-NEXT:        2038: mflr 0
56# PI-NEXT:              bcl 20, 31, 0x2040
57# PI-NEXT:        2040: mflr 12
58# PI-NEXT:              addis 12, 12, 512
59# PI-NEXT:              addi 12, 12, -48
60# PI-NEXT:              mtlr 0
61# PI-NEXT:              mtctr 12
62# PI-NEXT:              bctr
63
64.section .text_low, "ax", %progbits
65.globl _start
66_start:
67bl high@local     # Need a thunk
68bl high@local     # Need a thunk
69bl high+32768@plt # Need a thunk
70bl high
71bl .text_high+16  # Need a thunk
72blr
73
74# PD:         02002008 <high>:
75# PD-NEXT:              bl 0x2008
76# PD-NEXT:              bl 0x2002010
77# PD:         <__LongThunk_>:
78# PD-NEXT:     2002010: lis 12, 0
79# PD-NEXT:              addi 12, 12, 8200
80# PD-NEXT:              mtctr 12
81# PD-NEXT:              bctr
82
83.section .text_high, "ax", %progbits
84nop
85nop
86.globl high
87high:
88bl .text_low+8
89bl .text_low+8    # Need a thunk
90
91# NM:      t __LongThunk_high
92# NM-NEXT: t __LongThunk_
93# NM-NEXT: t __LongThunk_
94# NM-NEXT: T _start
95# NM-NEXT: T high
96