1// REQUIRES: arm
2// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t
3// RUN: ld.lld %t --shared -o %t.so
4// The output file is large, most of it zeroes. We dissassemble only the
5// parts we need to speed up the test and avoid a large output file
6// RUN: llvm-objdump -d %t.so --start-address=16777220 --stop-address=16777244 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK1 %s
7// RUN: llvm-objdump -d %t.so --start-address=17825800 --stop-address=17825826 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK2 %s
8// RUN: llvm-objdump -d %t.so --start-address=17825824 --stop-address=17825892 --triple=armv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK3 %s
9
10/// A branch to a Thunk that we create on pass N, can drift out of range if
11/// other Thunks are added in between. In this case we must create a new Thunk
12/// for the branch that is in range. We also need to make sure that if the
13/// destination of the Thunk is in the PLT the new Thunk also targets the PLT
14 .syntax unified
15 .thumb
16
17 .macro FUNCTION suff
18 .section .text.\suff\(), "ax", %progbits
19 .thumb
20 .balign 0x80000
21 .globl tfunc\suff\()
22 .type  tfunc\suff\(), %function
23tfunc\suff\():
24 bx lr
25 .endm
26
27 .globl imported
28 .type imported, %function
29 .globl imported2
30 .type imported2, %function
31 .globl imported3
32 .type imported3, %function
33.globl imported4
34 .type imported4, %function
35 FUNCTION 00
36 FUNCTION 01
37 FUNCTION 02
38 FUNCTION 03
39 FUNCTION 04
40 FUNCTION 05
41 FUNCTION 06
42 FUNCTION 07
43 FUNCTION 08
44 FUNCTION 09
45 FUNCTION 10
46 FUNCTION 11
47 FUNCTION 12
48 FUNCTION 13
49 FUNCTION 14
50 FUNCTION 15
51 FUNCTION 16
52 FUNCTION 17
53 FUNCTION 18
54 FUNCTION 19
55 FUNCTION 20
56 FUNCTION 21
57 FUNCTION 22
58 FUNCTION 23
59 FUNCTION 24
60 FUNCTION 25
61 FUNCTION 26
62 FUNCTION 27
63 FUNCTION 28
64 FUNCTION 29
65 FUNCTION 30
66 FUNCTION 31
67/// Precreated Thunk Pool goes here
68// CHECK1: <__ThumbV7PILongThunk_imported>:
69// CHECK1-NEXT:  1000004:       40 f2 30 0c     movw    r12, #48
70// CHECK1-NEXT:  1000008:       c0 f2 10 0c     movt    r12, #16
71// CHECK1-NEXT:  100000c:       fc 44   add     r12, pc
72// CHECK1-NEXT:  100000e:       60 47   bx      r12
73// CHECK1: <__ThumbV7PILongThunk_imported2>:
74// CHECK1-NEXT:  1000010:       40 f2 34 0c     movw    r12, #52
75// CHECK1-NEXT:  1000014:       c0 f2 10 0c     movt    r12, #16
76// CHECK1-NEXT:  1000018:       fc 44   add     r12, pc
77// CHECK1-NEXT:  100001a:       60 47   bx      r12
78
79 .section .text.32, "ax", %progbits
80 .space 0x80000
81 .section .text.33, "ax", %progbits
82 .space 0x80000 - 0x14
83 .section .text.34, "ax", %progbits
84 /// Need a Thunk to the PLT entry, can use precreated ThunkSection
85 .globl callers
86 .type callers, %function
87callers:
88 b.w imported
89 beq.w imported
90 b.w imported2
91// CHECK2: <__ThumbV7PILongThunk_imported>:
92// CHECK2-NEXT:  1100008:       40 f2 2c 0c     movw    r12, #44
93// CHECK2-NEXT:  110000c:       c0 f2 00 0c     movt    r12, #0
94// CHECK2-NEXT:  1100010:       fc 44   add     r12, pc
95// CHECK2-NEXT:  1100012:       60 47   bx      r12
96// CHECK2: <callers>:
97// CHECK2-NEXT:  1100014:       ff f6 f6 bf     b.w     #-1048596 <__ThumbV7PILongThunk_imported>
98// CHECK2-NEXT:  1100018:       3f f4 f6 af     beq.w   #-20 <__ThumbV7PILongThunk_imported>
99// CHECK2-NEXT:  110001c:       ff f6 f8 bf     b.w     #-1048592 <__ThumbV7PILongThunk_imported2>
100
101// CHECK3: Disassembly of section .plt:
102// CHECK3-EMPTY:
103// CHECK3-NEXT: <$a>:
104// CHECK3-NEXT:  1100020:       04 e0 2d e5     str     lr, [sp, #-4]!
105// CHECK3-NEXT:  1100024:       00 e6 8f e2     add     lr, pc, #0, #12
106// CHECK3-NEXT:  1100028:       20 ea 8e e2     add     lr, lr, #32
107// CHECK3-NEXT:  110002c:       94 f0 be e5     ldr     pc, [lr, #148]!
108// CHECK3: <$d>:
109// CHECK3-NEXT:  1100030:       d4 d4 d4 d4     .word   0xd4d4d4d4
110// CHECK3-NEXT:  1100034:       d4 d4 d4 d4     .word   0xd4d4d4d4
111// CHECK3-NEXT:  1100038:       d4 d4 d4 d4     .word   0xd4d4d4d4
112// CHECK3-NEXT:  110003c:       d4 d4 d4 d4     .word   0xd4d4d4d4
113// CHECK3: <$a>:
114// CHECK3-NEXT:  1100040:       00 c6 8f e2     add     r12, pc, #0, #12
115// CHECK3-NEXT:  1100044:       20 ca 8c e2     add     r12, r12, #32
116// CHECK3-NEXT:  1100048:       7c f0 bc e5     ldr     pc, [r12, #124]!
117// CHECK3: <$d>:
118// CHECK3-NEXT:  110004c:       d4 d4 d4 d4     .word   0xd4d4d4d4
119// CHECK3: <$a>:
120// CHECK3-NEXT:  1100050:       00 c6 8f e2     add     r12, pc, #0, #12
121// CHECK3-NEXT:  1100054:       20 ca 8c e2     add     r12, r12, #32
122// CHECK3-NEXT:  1100058:       70 f0 bc e5     ldr     pc, [r12, #112]!
123// CHECK3: <$d>:
124// CHECK3-NEXT:  110005c:       d4 d4 d4 d4     .word   0xd4d4d4d4
125