1// REQUIRES: arm
2// RUN: llvm-mc -filetype=obj -triple=armv7a-linux-gnueabihf --arm-add-build-attributes %s -o %t.o
3// RUN: echo "SECTIONS { \
4// RUN:          .text0 0x011006 : { *(.text.00) } \
5// RUN:          .text1 0x110000 : { *(.text.01) *(.text.02) *(.text.03) \
6// RUN:                             *(.text.04) } \
7// RUN:          .text2 0x210000 : { *(.text.05) } } " > %t.script
8// RUN: ld.lld --script %t.script --fix-cortex-a8 --shared -verbose %t.o -o %t2 2>&1
9// RUN: llvm-objdump -d --no-show-raw-insn %t2 | FileCheck %s
10
11/// Test cases for Cortex-a8 Erratum 657417 that involve interactions with
12/// range extension thunks. Both erratum fixes and range extension thunks need
13/// precise information and after creation alter address information.
14 .thumb
15
16 .section .text.00, "ax", %progbits
17 .thumb_func
18early:
19 bx lr
20
21 .section .text.01, "ax", %progbits
22 .balign 4096
23 .globl _start
24 .type _start, %function
25_start:
26  beq.w far_away
27/// Thunk to far_away and state change needed, size 12-bytes goes here.
28// CHECK: 00110004 <__ThumbV7PILongThunk_far_away>:
29// CHECK-NEXT: 110004: movw    r12, #65524
30// CHECK-NEXT:         movt    r12, #15
31// CHECK-NEXT:         add     r12, pc
32// CHECK-NEXT:         bx      r12
33
34 .section .text.02, "ax", %progbits
35 .space 4096 - 22
36
37 .section .text.03, "ax", %progbits
38 .thumb_func
39target:
40/// After thunk is added this branch will line up across 2 4 KiB regions
41/// and will trigger a patch.
42 nop.w
43 bl target
44
45/// Expect erratum patch inserted here
46// CHECK: 00110ffa <target>:
47// CHECK-NEXT: 110ffa: nop.w
48// CHECK-NEXT:         bl      #2
49// CHECK: 00111004 <__CortexA8657417_110FFE>:
50// CHECK-NEXT: 111004: b.w     #-14
51
52/// Expect range extension thunk here.
53// CHECK: 00111008 <__ThumbV7PILongThunk_early>:
54// CHECK-NEXT: 111008: b.w     #-1048582
55
56 .section .text.04, "ax", %progbits
57/// The erratum patch will push this branch out of range, so another
58/// range extension thunk will be needed.
59        beq.w early
60// CHECK:   11100c:            beq.w   #-8
61
62 .section .text.05, "ax", %progbits
63 .arm
64 nop
65 .type far_away, %function
66far_away:
67  bx lr
68