1// REQUIRES: arm
2// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv6-none-linux-gnueabi %s -o %t
3// RUN: ld.lld %t -o %t2
4// RUN: llvm-objdump -d --triple=armv6-none-linux-gnueabi --start-address=0x21000 --stop-address=0x21008 %t2 | FileCheck --check-prefix=CHECK-ARM1 %s
5// RUN: llvm-objdump -d --triple=thumbv6-none-linux-gnueabi %t2 --start-address=0x21008 --stop-address=0x2100c | FileCheck --check-prefix=CHECK-THUMB1 %s
6// RUN: llvm-objdump -d --triple=armv6-none-linux-gnueabi --start-address=0x22100c --stop-address=0x221014 %t2 | FileCheck --check-prefix=CHECK-ARM2 %s
7// RUN: llvm-objdump -d --triple=thumbv6-none-linux-gnueabi %t2 --start-address=0x622000 --stop-address=0x622002 | FileCheck --check-prefix=CHECK-THUMB2 %s
8
9/// On Arm v6 the range of a Thumb BL instruction is only 4 megabytes as the
10/// extended range encoding is not supported. The following example has a Thumb
11/// BL that is out of range on ARM v6 and requires a range extension thunk.
12/// As v6 does not support MOVT or MOVW instructions the Thunk must not
13/// use these instructions either.
14
15
16/// ARM v6 supports blx so we shouldn't see the blx not supported warning.
17// CHECK-NOT: warning: lld uses blx instruction, no object with architecture supporting feature detected.
18 .text
19 .syntax unified
20 .cpu    arm1176jzf-s
21 .globl _start
22 .type   _start,%function
23 .balign 0x1000
24_start:
25  bl thumbfunc
26  bx lr
27
28// CHECK-ARM1: Disassembly of section .text:
29// CHECK-ARM1-EMPTY:
30// CHECK-ARM1-NEXT: <_start>:
31// CHECK-ARM1-NEXT:    21000:   00 00 00 fa     blx     0x21008 <thumbfunc>
32// CHECK-ARM1-NEXT:    21004:   1e ff 2f e1     bx      lr
33 .thumb
34 .section .text.2, "ax", %progbits
35 .globl thumbfunc
36 .type thumbfunc,%function
37thumbfunc:
38 bl farthumbfunc
39
40// CHECK-THUMB1: <thumbfunc>:
41// CHECK-THUMB1-NEXT:    21008:	00 f2 00 e8 	blx	0x22100c <__ARMv5ABSLongThunk_farthumbfunc>
42/// 6 Megabytes, enough to make farthumbfunc out of range of caller
43/// on a v6 Arm, but not on a v7 Arm.
44
45 .section .text.3, "ax", %progbits
46 .space 0x200000
47// CHECK-ARM2: <__ARMv5ABSLongThunk_farthumbfunc>:
48// CHECK-ARM2-NEXT:   22100c:   04 f0 1f e5     ldr     pc, [pc, #-4]
49// CHECK-ARM2: <$d>:
50// CHECK-ARM2-NEXT:   221010:   01 20 62 00     .word   0x00622001
51 .section .text.4, "ax", %progbits
52 .space 0x200000
53
54 .section .text.5, "ax", %progbits
55 .space 0x200000
56
57 .thumb
58 .section .text.6, "ax", %progbits
59 .balign 0x1000
60 .globl farthumbfunc
61 .type farthumbfunc,%function
62farthumbfunc:
63 bx lr
64// CHECK-THUMB2: <farthumbfunc>:
65// CHECK-THUMB2-NEXT:   622000:        70 47   bx      lr
66