1// REQUIRES: aarch64
2// RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
3// RUN: echo "SECTIONS { \
4// RUN:       .text_low 0x2000: { *(.text_low) } \
5// RUN:       .text_high 0x8002000 : { *(.text_high) } \
6// RUN:       } " > %t.script
7// RUN: ld.lld --script %t.script %t.o -o %t
8// RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t | FileCheck %s
9// RUN: llvm-nm --no-sort %t | FileCheck --check-prefix=NM %s
10
11// Check that we have the out of branch range calculation right. The immediate
12// field is signed so we have a slightly higher negative displacement.
13 .section .text_low, "ax", %progbits
14 .globl _start
15 .type _start, %function
16_start:
17 // Need thunk to high_target@plt
18 bl high_target
19 // Need thunk to .text_high+4
20 bl .text_high+4
21 ret
22
23 .section .text_high, "ax", %progbits
24 .globl high_target
25 .type high_target, %function
26high_target:
27 // No Thunk needed as we are within signed immediate range
28 bl _start
29 ret
30
31// CHECK: Disassembly of section .text_low:
32// CHECK-EMPTY:
33// CHECK-NEXT: <_start>:
34// CHECK-NEXT:     2000:       bl      0x200c <__AArch64AbsLongThunk_high_target>
35// CHECK-NEXT:     2004:       bl      0x201c <__AArch64AbsLongThunk_>
36// CHECK-NEXT:                 ret
37// CHECK: <__AArch64AbsLongThunk_high_target>:
38// CHECK-NEXT:     200c:       ldr     x16, 0x2014
39// CHECK-NEXT:                 br      x16
40// CHECK: <$d>:
41// CHECK-NEXT:     2014:       00 20 00 08     .word   0x08002000
42// CHECK-NEXT:     2018:       00 00 00 00     .word   0x00000000
43// CHECK:      <__AArch64AbsLongThunk_>:
44// CHECK-NEXT:     201c:       ldr x16, 0x2024
45// CHECK-NEXT:     2020:       br x16
46// CHECK:      <$d>:
47// CHECK-NEXT:     2024:       04 20 00 08     .word   0x08002004
48// CHECK-NEXT:     2028:       00 00 00 00     .word   0x00000000
49// CHECK: Disassembly of section .text_high:
50// CHECK-EMPTY:
51// CHECK-NEXT: <high_target>:
52// CHECK-NEXT:  8002000:       bl      0x2000 <_start>
53// CHECK-NEXT:                 ret
54
55/// Local symbols copied from %t.o
56// NM:      t $x.0
57// NM-NEXT: t $x.1
58/// Local thunk symbols.
59// NM-NEXT: t __AArch64AbsLongThunk_high_target
60// NM-NEXT: t $x
61// NM-NEXT: t $d
62// NM-NEXT: t __AArch64AbsLongThunk_{{$}}
63// NM-NEXT: t $x
64// NM-NEXT: t $d
65/// Global symbols.
66// NM-NEXT: T _start
67// NM-NEXT: T high_target
68