Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / arm-thumb-blx.s
blob19520a6542b3fd310e82e52e39a53e9ebbaf2ebc
1 // REQUIRES: arm
2 // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t
3 // RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %S/Inputs/arm-thumb-blx-targets.s -o %ttarget
4 // RUN: echo "SECTIONS { \
5 // RUN: .R_ARM_CALL24_callee1 : { *(.R_ARM_CALL24_callee_low) } \
6 // RUN: .R_ARM_CALL24_callee2 : { *(.R_ARM_CALL24_callee_thumb_low) } \
7 // RUN: .caller : { *(.text) } \
8 // RUN: .R_ARM_CALL24_callee3 : { *(.R_ARM_CALL24_callee_high) } \
9 // RUN: .R_ARM_CALL24_callee4 : { *(.R_ARM_CALL24_callee_thumb_high) } } " > %t.script
10 // RUN: ld.lld --script %t.script %t %ttarget -o %t2
11 // RUN: llvm-objdump -d %t2 | FileCheck %s
12 // Test BLX instruction is chosen for Thumb BL/BLX instruction and ARM callee
13 // 2 byte nops are used to test the pc-rounding behaviour. As a BLX from a
14 // 2 byte aligned destination is defined as Align(PC,4) + immediate:00
15 // FIXME: llvm-mc has problems assembling BLX unless the destination is
16 // external. The targets of the BL and BLX instructions are in arm-thumb-blx-target.s
17 .syntax unified
18 .section .text, "ax",%progbits
19 .thumb
20 .globl _start
21 .balign 0x10000
22 .type _start,%function
23 _start:
24 blx callee_low
25 nop
26 bl callee_low
27 nop
28 blx callee_high
29 nop
30 bl callee_high
31 nop
32 blx blx_far
33 nop
34 bl blx_far
35 nop
36 // Expect BLX to thumb target to be written out as a BL
37 blx callee_thumb_low
38 nop
39 blx callee_thumb_high
40 bx lr
42 // CHECK: Disassembly of section .R_ARM_CALL24_callee1:
43 // CHECK-EMPTY:
44 // CHECK-NEXT-ARM: callee_low:
45 // CHECK-NEXT-ARM: b4: 1e ff 2f e1 bx lr
47 // CHECK: Disassembly of section .R_ARM_CALL24_callee2:
48 // CHECK-EMPTY:
49 // CHECK-NEXT-THUMB: callee_thumb_low:
50 // CHECK-NEXT-THUMB: 100: 70 47 bx lr
52 // CHECK: Disassembly of section .caller:
53 // CHECK-EMPTY:
54 // CHECK: <_start>:
55 // Align(0x10000,4) - 0xff50 (65360) + 4 = 0xb4 = callee_low
56 // CHECK-NEXT-THUMB: 10000: f0 f7 58 e8 blx #-65360
57 // CHECK-NEXT-THUMB: 10004: 00 bf nop
58 // Align(0x10006,4) - 0xff54 (65364) + 4 = 0xb4 = callee_low
59 // CHECK-NEXT-THUMB: 10006: f0 f7 56 e8 blx #-65364
60 // CHECK-NEXT-THUMB: 1000a: 00 bf nop
61 // Align(0x1000c,4) + 0xf0 (240) + 4 = 0x10100 = callee_high
62 // CHECK-NEXT-THUMB: 1000c: 00 f0 78 e8 blx #240
63 // CHECK-NEXT-THUMB: 10010: 00 bf nop
64 // Align(0x10012,4) + 0xec (236) + 4 = 0x10100 = callee_high
65 // CHECK-NEXT-THUMB: 10012: 00 f0 76 e8 blx #236
66 // CHECK-NEXT-THUMB: 10016: 00 bf nop
67 // Align(0x10018,4) + 0xfffffc (16777212) = 0x1010018 = blx_far
68 // CHECK-NEXT-THUMB: 10018: ff f3 fe c7 blx #16777212
69 // CHECK-NEXT-THUMB: 1001c: 00 bf nop
70 // Align(0x1001e,4) + 0xfffff8 (16777208) = 0x1010018 = blx_far
71 // CHECK-NEXT-THUMB: 1001e: ff f3 fc c7 blx #16777208
72 // CHECK-NEXT-THUMB: 10022: 00 bf nop
73 // 10024 - 0xff28 (65320) + 4 = 0x100 = callee_thumb_low
74 // CHECK-NEXT-THUMB: 10024: f0 f7 6c f8 bl #-65320
75 // CHECK-NEXT-THUMB: 10028: 00 bf nop
76 // 1002a + 0x1d2 (466) + 4 = 0x10200 = callee_thumb_high
77 // CHECK-NEXT-THUMB: 1002a: 00 f0 e9 f8 bl #466
78 // CHECK-NEXT-THUMB: 1002e: 70 47 bx lr
81 // CHECK: Disassembly of section .R_ARM_CALL24_callee3:
82 // CHECK-EMPTY:
83 // CHECK-NEXT-ARM: callee_high:
84 // CHECK-NEXT-ARM: 10100: 1e ff 2f e1 bx lr
86 // CHECK: Disassembly of section .R_ARM_CALL24_callee4:
87 // CHECK-EMPTY:
88 // CHECK-NEXT-THUMB:callee_thumb_high:
89 // CHECK-NEXT-THUMB: 10200: 70 47 bx lr