1// REQUIRES: arm 2// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t.o 3// RUN: ld.lld %t.o -o %t 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 --print-imm-hex --start-address=0x80000 --stop-address=0x80010 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK1 %s 7// RUN: llvm-objdump -d %t --print-imm-hex --start-address=0x100000 --stop-address=0x100008 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK2 %s 8// RUN: llvm-objdump -d %t --print-imm-hex --start-address=0x180000 --stop-address=0x18000a --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK3 %s 9// RUN: llvm-objdump -d %t --print-imm-hex --start-address=0x500004 --stop-address=0x500008 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK4 %s 10// RUN: llvm-objdump -d %t --print-imm-hex --start-address=0x580000 --stop-address=0x580006 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK5 %s 11// RUN: llvm-objdump -d %t --print-imm-hex --start-address=0x1000004 --stop-address=0x100000c --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK6 %s 12// RUN: llvm-objdump -d %t --print-imm-hex --start-address=0x1100000 --stop-address=0x1100006 --triple=thumbv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK7 %s 13// Test Range extension Thunks for the Thumb conditional branch instruction. 14// This instruction only has a range of 1Mb whereas all the other Thumb wide 15// Branch instructions have 16Mb range. We still place our pre-created Thunk 16// Sections at 16Mb intervals as conditional branches to a target defined 17// in a different section are rare. 18 .syntax unified 19// Define a function aligned on a half megabyte boundary 20 .macro FUNCTION suff 21 .section .text.\suff\(), "ax", %progbits 22 .thumb 23 .balign 0x80000 24 .globl tfunc\suff\() 25 .type tfunc\suff\(), %function 26tfunc\suff\(): 27 bx lr 28 .endm 29 30 .globl _start 31_start: 32 FUNCTION 00 33// Long Range Thunk needed for 16Mb range branch, can reach pre-created Thunk 34// Section 35 bl tfunc33 36// CHECK1: Disassembly of section .text: 37// CHECK1-EMPTY: 38// CHECK1-NEXT: <tfunc00>: 39// CHECK1-NEXT: 80000: 70 47 bx lr 40// CHECK1-NEXT: 80002: 7f f3 ff d7 bl #0xf7fffe 41// CHECK1: <__Thumbv7ABSLongThunk_tfunc05>: 42// CHECK1-NEXT: 80008: 7f f2 fa bf b.w #0x27fff4 <tfunc05> 43// CHECK1: <__Thumbv7ABSLongThunk_tfunc00>: 44// CHECK1-NEXT: 8000c: ff f7 f8 bf b.w #-0x10 <tfunc00> 45 FUNCTION 01 46// tfunc02 is within range of tfunc02 47 beq.w tfunc02 48// tfunc05 is out of range, and we can't reach the pre-created Thunk Section 49// create a new one. 50 bne.w tfunc05 51// CHECK2: <tfunc01>: 52// CHECK2-NEXT: 100000: 70 47 bx lr 53// CHECK2-NEXT: 100002: 3f f0 fd a7 beq.w #0x7fffa <tfunc02> 54// CHECK2-NEXT: 100006: 7f f4 ff a7 bne.w #-0x80002 <__Thumbv7ABSLongThunk_tfunc05> 55 FUNCTION 02 56// We can reach the Thunk Section created for bne.w tfunc05 57 bne.w tfunc05 58 beq.w tfunc00 59// CHECK3: 180000: 70 47 bx lr 60// CHECK3-NEXT: 180002: 40 f4 01 80 bne.w #-0xffffe <__Thumbv7ABSLongThunk_tfunc05> 61// CHECK3-NEXT: 180006: 00 f4 01 80 beq.w #-0xffffe <__Thumbv7ABSLongThunk_tfunc00> 62 FUNCTION 03 63 FUNCTION 04 64 FUNCTION 05 65 FUNCTION 06 66 FUNCTION 07 67 FUNCTION 08 68 FUNCTION 09 69// CHECK4: <__Thumbv7ABSLongThunk_tfunc03>: 70// CHECK4-NEXT: 500004: ff f4 fc bf b.w #-0x300008 <tfunc03> 71 FUNCTION 10 72// We can't reach any Thunk Section, create a new one 73 beq.w tfunc03 74// CHECK5: <tfunc10>: 75// CHECK5-NEXT: 580000: 70 47 bx lr 76// CHECK5-NEXT: 580002: 3f f4 ff a7 beq.w #-0x80002 <__Thumbv7ABSLongThunk_tfunc03> 77 FUNCTION 11 78 FUNCTION 12 79 FUNCTION 13 80 FUNCTION 14 81 FUNCTION 15 82 FUNCTION 16 83 FUNCTION 17 84 FUNCTION 18 85 FUNCTION 19 86 FUNCTION 20 87 FUNCTION 21 88 FUNCTION 22 89 FUNCTION 23 90 FUNCTION 24 91 FUNCTION 25 92 FUNCTION 26 93 FUNCTION 27 94 FUNCTION 28 95 FUNCTION 29 96 FUNCTION 30 97 FUNCTION 31 98// CHECK6: <__Thumbv7ABSLongThunk_tfunc33>: 99// CHECK6-NEXT: 1000004: ff f0 fc bf b.w #0xffff8 <tfunc33> 100// CHECK6: <__Thumbv7ABSLongThunk_tfunc00>: 101// CHECK6-NEXT: 1000008: 7f f4 fa 97 b.w #-0xf8000c <tfunc00> 102 FUNCTION 32 103 FUNCTION 33 104 // We should be able to reach an existing ThunkSection. 105 b.w tfunc00 106// CHECK7: <tfunc33>: 107// CHECK7-NEXT: 1100000: 70 47 bx lr 108// CHECK7-NEXT: 1100002: 00 f7 01 b8 b.w #-0xffffe <__Thumbv7ABSLongThunk_tfunc00> 109