• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 -o %t2
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 %t2 --start-address=1048576 --stop-address=1048588 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK1 %s
7// RUN: llvm-objdump -d %t2 --start-address=2097152 --stop-address=2097154 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK2 %s
8// RUN: llvm-objdump -d %t2 --start-address=3145728 --stop-address=3145730 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK3 %s
9// RUN: llvm-objdump -d %t2 --start-address=4194304 --stop-address=4194310 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK4 %s
10// RUN: llvm-objdump -d %t2 --start-address=16777216 --stop-address=16777270 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK5 %s
11// RUN: llvm-objdump -d %t2 --start-address=17825792 --stop-address=17825808 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK6 %s
12// RUN: llvm-objdump -d %t2 --start-address=20971524 --stop-address=20971532 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK7 %s
13// RUN: llvm-objdump -d %t2 --start-address=31457280 --stop-address=31457286 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK8 %s
14// RUN: llvm-objdump -d %t2 --start-address=35651584 --stop-address=35651594 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK9 %s
15// RUN: llvm-objdump -d %t2 --start-address=36700160 --stop-address=36700170 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK10 %s
16
17// Test the Range extension Thunks for Thumb when all the code is in a single
18// OutputSection. The Thumb unconditional branch b.w and branch and link bl
19// instructions have a range of 16Mb. We create a series of Functions a
20// megabyte apart. We expect range extension thunks to be created when a
21// branch is out of range. Thunks will be reused whenever they are in range
22 .syntax unified
23
24// Define a function aligned on a megabyte boundary
25 .macro FUNCTION suff
26 .section .text.\suff\(), "ax", %progbits
27 .thumb
28 .balign 0x100000
29 .globl tfunc\suff\()
30 .type  tfunc\suff\(), %function
31tfunc\suff\():
32 bx lr
33 .endm
34
35 .section .text, "ax", %progbits
36 .thumb
37 .globl _start
38_start:
39// tfunc00 and tfunc15 are within 16Mb no Range Thunks expected
40 bl tfunc00
41 bl tfunc15
42// tfunc16 is > 16Mb away, expect a Range Thunk to be generated, to go into
43// the first of the pre-created ThunkSections.
44 bl tfunc16
45// CHECK1: Disassembly of section .text:
46// CHECK1-EMPTY:
47// CHECK1-NEXT: <_start>:
48// CHECK1-NEXT:   100000:       ff f0 fe ff     bl      #1048572
49// CHECK1-NEXT:   100004:       ff f3 fc d7     bl      #16777208
50// CHECK1-NEXT:   100008:       ff f2 fc d7     bl      #15728632
51
52 FUNCTION 00
53// CHECK2:  <tfunc00>:
54// CHECK2-NEXT:   200000:       70 47   bx      lr
55        FUNCTION 01
56// CHECK3: <tfunc01>:
57// CHECK3-NEXT:   300000:       70 47   bx      lr
58 FUNCTION 02
59// tfunc28 is > 16Mb away, expect a Range Thunk to be generated, to go into
60// the first of the pre-created ThunkSections.
61        b.w tfunc28
62// CHECK4: <tfunc02>:
63// CHECK4-NEXT:   400000:       70 47   bx      lr
64// CHECK4-NEXT:   400002:       00 f0 01 90     b.w     #12582914 <__Thumbv7ABSLongThunk_tfunc28>
65 FUNCTION 03
66 FUNCTION 04
67 FUNCTION 05
68 FUNCTION 06
69 FUNCTION 07
70 FUNCTION 08
71 FUNCTION 09
72 FUNCTION 10
73 FUNCTION 11
74 FUNCTION 12
75 FUNCTION 13
76 FUNCTION 14
77// Expect precreated ThunkSection here
78// CHECK5: <__Thumbv7ABSLongThunk_tfunc16>:
79// CHECK5-NEXT:  1000004:       ff f1 fc bf     b.w     #2097144 <tfunc16>
80// CHECK5: <__Thumbv7ABSLongThunk_tfunc28>:
81// CHECK5-NEXT:  1000008:       ff f1 fa 97     b.w     #14680052 <tfunc28>
82// CHECK5: <__Thumbv7ABSLongThunk_tfunc32>:
83// CHECK5-NEXT:  100000c:       40 f2 01 0c     movw    r12, #1
84// CHECK5-NEXT:  1000010:       c0 f2 20 2c     movt    r12, #544
85// CHECK5-NEXT:  1000014:       60 47   bx      r12
86// CHECK5: <__Thumbv7ABSLongThunk_tfunc33>:
87// CHECK5-NEXT:  1000016:       40 f2 01 0c     movw    r12, #1
88// CHECK5-NEXT:  100001a:       c0 f2 30 2c     movt    r12, #560
89// CHECK5-NEXT:  100001e:       60 47   bx      r12
90// CHECK5: <__Thumbv7ABSLongThunk_tfunc02>:
91// CHECK5-NEXT:  1000020:       ff f7 ee 97     b.w     #-12582948 <tfunc02>
92 FUNCTION 15
93// tfunc00 and tfunc01 are < 16Mb away, expect no range extension thunks
94 bl tfunc00
95 bl tfunc01
96// tfunc32 and tfunc33 are > 16Mb away, expect range extension thunks in the
97// precreated thunk section
98 bl tfunc32
99 bl tfunc33
100// CHECK6:  <tfunc15>:
101// CHECK6-NEXT:  1100000:       70 47   bx      lr
102// CHECK6-NEXT:  1100002:       ff f4 fd d7     bl      #-15728646
103// CHECK6-NEXT:  1100006:       ff f5 fb d7     bl      #-14680074
104// CHECK6-NEXT:  110000a:       ff f6 ff ff     bl      #-1048578
105// CHECK6-NEXT:  110000e:       00 f7 02 f8     bl      #-1048572
106 FUNCTION 16
107 FUNCTION 17
108 FUNCTION 18
109// Expect another precreated thunk section here
110// CHECK7: <__Thumbv7ABSLongThunk_tfunc15>:
111// CHECK7-NEXT:  1400004:       ff f4 fc bf     b.w     #-3145736 <tfunc15>
112// CHECK7: <__Thumbv7ABSLongThunk_tfunc16>:
113// CHECK7-NEXT:  1400008:       ff f5 fa bf     b.w     #-2097164 <tfunc16>
114 FUNCTION 19
115 FUNCTION 20
116 FUNCTION 21
117 FUNCTION 22
118 FUNCTION 23
119 FUNCTION 24
120 FUNCTION 25
121 FUNCTION 26
122 FUNCTION 27
123 FUNCTION 28
124// tfunc02 is > 16Mb away, expect range extension thunks in precreated thunk
125// section
126// CHECK8:  <tfunc28>:
127// CHECK8-NEXT:  1e00000:       70 47   bx      lr
128// CHECK8-NEXT:  1e00002:       00 f6 0d 90     b.w     #-14680038 <__Thumbv7ABSLongThunk_tfunc02>
129
130 b.w tfunc02
131 FUNCTION 29
132 FUNCTION 30
133 FUNCTION 31
134 FUNCTION 32
135 // tfunc15 and tfunc16 are > 16 Mb away expect Thunks in the nearest
136 // precreated thunk section.
137 bl tfunc15
138 bl tfunc16
139// CHECK9: <tfunc32>:
140// CHECK9:  2200000:    70 47   bx      lr
141// CHECK9-NEXT:  2200002:       ff f5 ff d7     bl      #-14680066
142// CHECK9-NEXT:  2200006:       ff f5 ff d7     bl      #-14680066
143
144 FUNCTION 33
145 bl tfunc15
146 bl tfunc16
147// CHECK10: <tfunc33>:
148// CHECK10:  2300000:   70 47   bx      lr
149// CHECK10-NEXT:  2300002:      ff f4 ff d7     bl      #-15728642
150// CHECK10-NEXT:  2300006:      ff f4 ff d7     bl      #-15728642
151