• 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: echo "SECTIONS { \
4// RUN:       .text 0x100000 : { *(.text) } \
5// RUN:       .textl : { *(.text_l0*) *(.text_l1*) *(.text_l2*) *(.text_l3*) } \
6// RUN:       .texth : { *(.text_h0*) *(.text_h1*) *(.text_h2*) *(.text_h3*) } \
7// RUN:       }" > %t.script
8// RUN: ld.lld --script %t.script %t -o %t2
9// The output file is large, most of it zeroes. We dissassemble only the
10// parts we need to speed up the test and avoid a large output file
11// RUN: llvm-objdump -d %t2 --start-address=1048576 --stop-address=1048594 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK1 %s
12// RUN: llvm-objdump -d %t2 --start-address=2097152 --stop-address=2097160 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK2 %s
13// RUN: llvm-objdump -d %t2 --start-address=11534340 --stop-address=11534350 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK3 %s
14// RUN: llvm-objdump -d %t2 --start-address=34603008 --stop-address=34603034 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK4 %s
15// RUN: llvm-objdump -d %t2 --start-address=35651584 --stop-address=35651598 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK5 %s
16// RUN: llvm-objdump -d %t2 --start-address=68157440 --stop-address=68157472 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK6 %s
17
18// Test the range extensions in a linker script where there are several
19// OutputSections requiring range extension Thunks. We should be able to reuse
20// Thunks between OutputSections but our placement of new Thunks is done on a
21// per OutputSection basis
22 .syntax unified
23
24// Define a function that we can match with .text_l* aligned on a megabyte
25// boundary
26 .macro FUNCTIONL suff
27 .section .text_l\suff\(), "ax", %progbits
28 .thumb
29 .balign 0x100000
30 .globl tfuncl\suff\()
31 .type  tfuncl\suff\(), %function
32tfuncl\suff\():
33 bx lr
34 .endm
35
36// Define a function that we can match with .text_h* aligned on a megabyte
37// boundary
38 .macro FUNCTIONH suff
39 .section .text_h\suff\(), "ax", %progbits
40 .thumb
41 .balign 0x100000
42 .globl tfunch\suff\()
43 .type  tfunch\suff\(), %function
44tfunch\suff\():
45 bx lr
46 .endm
47
48 .section .text, "ax", %progbits
49 .thumb
50 .globl _start
51_start:
52 bl tfuncl00
53 // Expect a range extension thunk in .text OutputSection
54 bl tfunch31
55// CHECK1: Disassembly of section .text:
56// CHECK1-EMPTY:
57// CHECK1-NEXT: <_start>:
58// CHECK1-NEXT:   100000:       ff f0 fe ff     bl      #1048572
59// CHECK1-NEXT:   100004:       00 f0 00 f8     bl      #0
60// CHECK1: <__Thumbv7ABSLongThunk_tfunch31>:
61// CHECK1-NEXT:   100008:       40 f2 01 0c     movw    r12, #1
62// CHECK1-NEXT:   10000c:       c0 f2 10 4c     movt    r12, #1040
63// CHECK1-NEXT:   100010:       60 47   bx      r12
64 FUNCTIONL 00
65 // Create a range extension thunk in .textl
66 bl tfuncl24
67 // We can reuse existing thunk in .text
68 bl tfunch31
69// CHECK2: Disassembly of section .textl:
70// CHECK2-EMPTY:
71// CHECK2-NEXT: <tfuncl00>:
72// CHECK2-NEXT:   200000:	70 47 	bx	lr
73// CHECK2-NEXT:   200002:	ff f0 ff df 	bl	#9437182
74// CHECK2-NEXT:   200006:	ff f6 ff ff 	bl	#-1048578
75 FUNCTIONL 01
76 FUNCTIONL 02
77 FUNCTIONL 03
78 FUNCTIONL 04
79 FUNCTIONL 05
80 FUNCTIONL 06
81 FUNCTIONL 07
82 FUNCTIONL 08
83 FUNCTIONL 09
84// CHECK3: <__Thumbv7ABSLongThunk_tfuncl24>:
85// CHECK3-NEXT:   b00004:      ff f2 fc 97     b.w     #15728632 <tfuncl24>
86 FUNCTIONL 10
87 FUNCTIONL 11
88 FUNCTIONL 12
89 FUNCTIONL 13
90 FUNCTIONL 14
91 FUNCTIONL 15
92 FUNCTIONL 16
93 FUNCTIONL 17
94 FUNCTIONL 18
95 FUNCTIONL 19
96 FUNCTIONL 20
97 FUNCTIONL 21
98 FUNCTIONL 22
99 FUNCTIONL 23
100 FUNCTIONL 24
101 FUNCTIONL 25
102 FUNCTIONL 26
103 FUNCTIONL 27
104 FUNCTIONL 28
105 FUNCTIONL 29
106 FUNCTIONL 30
107 FUNCTIONL 31
108 // Create range extension thunks in .textl
109 bl tfuncl00
110 bl tfuncl24
111 // Shouldn't need a thunk
112 bl tfunch00
113// CHECK4:  2100002:    00 f0 05 f8     bl      #10
114// CHECK4-NEXT:  2100006:       ff f4 fb f7     bl      #-7340042
115// CHECK4-NEXT:  210000a:       ff f0 f9 ff     bl      #1048562
116// CHECK4: <__Thumbv7ABSLongThunk_tfuncl00>:
117// CHECK4-NEXT:  2100010:       40 f2 01 0c     movw    r12, #1
118// CHECK4-NEXT:  2100014:       c0 f2 20 0c     movt    r12, #32
119// CHECK4-NEXT:  2100018:       60 47   bx      r12
120 FUNCTIONH 00
121 // Can reuse existing thunks in .textl
122 bl tfuncl00
123 bl tfuncl24
124 // Shouldn't need a thunk
125        bl tfuncl31
126// CHECK5:  Disassembly of section .texth:
127// CHECK5-EMPTY:
128// CHECK5-NEXT: <tfunch00>:
129// CHECK5-NEXT:  2200000:       70 47   bx      lr
130// CHECK5-NEXT:  2200002:       00 f7 05 f8     bl      #-1048566
131// CHECK5-NEXT:  2200006:       ff f7 fb df     bl      #-8388618
132// CHECK5-NEXT:  220000a:       ff f6 f9 ff     bl      #-1048590
133 FUNCTIONH 01
134 FUNCTIONH 02
135 FUNCTIONH 03
136 FUNCTIONH 04
137 FUNCTIONH 05
138 FUNCTIONH 06
139 FUNCTIONH 07
140 FUNCTIONH 08
141 FUNCTIONH 09
142 FUNCTIONH 10
143 FUNCTIONH 11
144 FUNCTIONH 12
145 FUNCTIONH 13
146 FUNCTIONH 14
147 FUNCTIONH 15
148 FUNCTIONH 16
149 FUNCTIONH 17
150 FUNCTIONH 18
151 FUNCTIONH 19
152 FUNCTIONH 20
153 FUNCTIONH 21
154 FUNCTIONH 22
155 FUNCTIONH 23
156 FUNCTIONH 24
157 FUNCTIONH 25
158 FUNCTIONH 26
159 FUNCTIONH 27
160 FUNCTIONH 28
161 FUNCTIONH 29
162 FUNCTIONH 30
163 FUNCTIONH 31
164// expect Thunks in .texth
165 bl tfuncl00
166 bl tfunch00
167// CHECK6: <tfunch31>:
168// CHECK6-NEXT:  4100000:       70 47   bx      lr
169// CHECK6-NEXT:  4100002:       00 f0 03 f8     bl      #6
170// CHECK6-NEXT:  4100006:       00 f0 06 f8     bl      #12
171// CHECK6: <__Thumbv7ABSLongThunk_tfuncl00>:
172// CHECK6-NEXT:  410000c:       40 f2 01 0c     movw    r12, #1
173// CHECK6-NEXT:  4100010:       c0 f2 20 0c     movt    r12, #32
174// CHECK6-NEXT:  4100014:       60 47   bx      r12
175// CHECK6: <__Thumbv7ABSLongThunk_tfunch00>:
176// CHECK6-NEXT:  4100016:       40 f2 01 0c     movw    r12, #1
177// CHECK6-NEXT:  410001a:       c0 f2 20 2c     movt    r12, #544
178// CHECK6-NEXT:  410001e:       60 47   bx      r12
179