194 lines · plain
1// REQUIRES: arm2// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t3// RUN: ld.lld %t -o %t24// The output file is large, most of it zeroes. We dissassemble only the5// parts we need to speed up the test and avoid a large output file6// RUN: llvm-objdump --no-print-imm-hex -d %t2 --start-address=0x100000 --stop-address=0x10001c --triple=armv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK1 %s7// RUN: llvm-objdump --no-print-imm-hex -d %t2 --start-address=0x200000 --stop-address=0x20000a | FileCheck --check-prefix=CHECK2 %s8// RUN: llvm-objdump --no-print-imm-hex -d %t2 --start-address=0x1000004 --stop-address=0x1000010 --triple=armv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK3 %s9// RUN: llvm-objdump --no-print-imm-hex -d %t2 --start-address=0x1000010 --stop-address=0x100001a | FileCheck --check-prefix=CHECK4 %s10// RUN: llvm-objdump --no-print-imm-hex -d %t2 --start-address=0x1f00004 --stop-address=0x1f0000e | FileCheck --check-prefix=CHECK5 %s11// RUN: llvm-objdump --no-print-imm-hex -d %t2 --start-address=0x2200000 --stop-address=0x2200006 | FileCheck --check-prefix=CHECK6 %s12// RUN: llvm-objdump --no-print-imm-hex -d %t2 --start-address=0x2300000 --stop-address=0x2300008 --triple=armv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK7 %s13// RUN: llvm-objdump --no-print-imm-hex -d %t2 --start-address=0x2e00004 --stop-address=0x2e00010 --triple=armv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK8 %s14// RUN: llvm-objdump --no-print-imm-hex -d %t2 --start-address=0x3300004 --stop-address=0x3300010 | FileCheck --check-prefix=CHECK9 %s15// RUN: llvm-objdump --no-print-imm-hex -d %t2 --start-address=0x4100000 --stop-address=0x410000c --triple=armv7a-linux-gnueabihf | FileCheck --check-prefix=CHECK10 %s16// RUN: llvm-objdump --no-print-imm-hex -d %t2 --start-address=0x4200000 --stop-address=0x4200008 | FileCheck --check-prefix=CHECK11 %s17 18// Test the Range extension Thunks for ARM and Thumb when all the code is in a19// single OutputSection. The ARM branches and branch and link instructions20// have a range of 32Mb, the Thumb unconditional branch and21// branch and link instructions have . We create a series of Functions a22// megabyte apart. We expect range extension thunks to be created when a23// branch is out of range. Thunks will be reused whenever they are in range24 .syntax unified25 26// Define a function aligned on a megabyte boundary27 .macro ARMFUNCTION suff28 .section .text.\suff\(), "ax", %progbits29 .arm30 .balign 0x10000031 .globl afunc\suff\()32 .type afunc\suff\(), %function33afunc\suff\():34 bx lr35 .endm36 37// Define a function aligned on a megabyte boundary38 .macro THUMBFUNCTION suff39 .section .text.\suff\(), "ax", %progbits40 .thumb41 .balign 0x10000042 .globl tfunc\suff\()43 .type tfunc\suff\(), %function44tfunc\suff\():45 bx lr46 .endm47 48 .section .text, "ax", %progbits49 .thumb50 .globl _start51_start:52 53 ARMFUNCTION 0054// Expect ARM bl to be in range (can use blx to change state)55 bl tfunc3156// ARM b and beq are in range but need Thunk to change state to Thumb57 b tfunc3158 beq tfunc3159// afunc32 is out of range of ARM branch and branch and link60 bl afunc3261 b afunc3262 bne afunc3263// CHECK1: <afunc00>:64// CHECK1-NEXT: 100000: e12fff1e bx lr65// CHECK1-NEXT: 100004: fa7bfffd blx 0x2000000 <tfunc31>66// CHECK1-NEXT: 100008: ea3bfffd b 0x1000004 <__ARMv7ABSLongThunk_tfunc31>67// CHECK1-NEXT: 10000c: 0a3bfffc beq 0x1000004 <__ARMv7ABSLongThunk_tfunc31>68// CHECK1-NEXT: 100010: eb7ffffa bl 0x2100000 <afunc32>69// CHECK1-NEXT: 100014: ea7ffff9 b 0x2100000 <afunc32>70// CHECK1-NEXT: 100018: 1a7ffff8 bne 0x2100000 <afunc32>71 THUMBFUNCTION 0172// Expect Thumb bl to be in range (can use blx to change state)73 bl afunc1474// In range but need thunk to change state to Thumb75 b.w afunc1476// CHECK2: <tfunc01>:77// CHECK2-NEXT: 200000: 4770 bx lr78// CHECK2-NEXT: 200002: f0ff c7fe blx 0xf00000 <afunc14>79// CHECK2-NEXT: 200006: f200 9003 b.w 0x1000010 <__Thumbv7ABSLongThunk_afunc14>80 81 ARMFUNCTION 0282 THUMBFUNCTION 0383 ARMFUNCTION 0484 THUMBFUNCTION 0585 ARMFUNCTION 0686 THUMBFUNCTION 0787 ARMFUNCTION 0888 THUMBFUNCTION 0989 ARMFUNCTION 1090 THUMBFUNCTION 1191 ARMFUNCTION 1292 THUMBFUNCTION 1393 ARMFUNCTION 1494// CHECK3: <__ARMv7ABSLongThunk_tfunc31>:95// CHECK3-NEXT: 1000004: e300c001 movw r12, #196// CHECK3-NEXT: 1000008: e340c200 movt r12, #51297// CHECK3-NEXT: 100000c: e12fff1c bx r1298// CHECK4: <__Thumbv7ABSLongThunk_afunc14>:99// CHECK4-NEXT: 1000010: f240 0c00 movw r12, #0100// CHECK4-NEXT: 1000014: f2c0 0cf0 movt r12, #240101// CHECK4-NEXT: 1000018: 4760 bx r12102 THUMBFUNCTION 15103 ARMFUNCTION 16104 THUMBFUNCTION 17105 ARMFUNCTION 18106 THUMBFUNCTION 19107 ARMFUNCTION 20108 THUMBFUNCTION 21109 ARMFUNCTION 22110 THUMBFUNCTION 23111 ARMFUNCTION 24112 THUMBFUNCTION 25113 ARMFUNCTION 26114 THUMBFUNCTION 27115 ARMFUNCTION 28116 THUMBFUNCTION 29117 ARMFUNCTION 30118// Expect precreated Thunk Section here119// CHECK5: <__Thumbv7ABSLongThunk_afunc00>:120// CHECK5-NEXT: 1f00004: f240 0c00 movw r12, #0121// CHECK5-NEXT: 1f00008: f2c0 0c10 movt r12, #16122// CHECK5-NEXT: 1f0000c: 4760 bx r12123 THUMBFUNCTION 31124 ARMFUNCTION 32125 THUMBFUNCTION 33126// Out of range, can only reach closest Thunk Section127 bl afunc00128// CHECK6: <tfunc33>:129// CHECK6-NEXT: 2200000: 4770 bx lr130// CHECK6-NEXT: 2200002: f4ff ffff bl 0x1f00004 <__Thumbv7ABSLongThunk_afunc00>131 ARMFUNCTION 34132// Out of range, can reach earlier Thunk Section133// CHECK7: <afunc34>:134// CHECK7-NEXT: 2300000: e12fff1e bx lr135// CHECK7-NEXT: 2300004: faeffffe blx 0x1f00004 <__Thumbv7ABSLongThunk_afunc00>136 bl afunc00137 THUMBFUNCTION 35138 ARMFUNCTION 36139 THUMBFUNCTION 37140 ARMFUNCTION 38141 THUMBFUNCTION 39142 ARMFUNCTION 40143 THUMBFUNCTION 41144 ARMFUNCTION 42145 THUMBFUNCTION 43146 ARMFUNCTION 44147 THUMBFUNCTION 45148// Expect precreated Thunk Section here149// CHECK8: <__ARMv7ABSLongThunk_tfunc35>:150// CHECK8-NEXT: 2e00004: e300c001 movw r12, #1151// CHECK8-NEXT: 2e00008: e340c240 movt r12, #576152// CHECK8-NEXT: 2e0000c: e12fff1c bx r12153 ARMFUNCTION 46154 THUMBFUNCTION 47155 ARMFUNCTION 48156 THUMBFUNCTION 49157 ARMFUNCTION 50158// Expect precreated Thunk Section here159// CHECK9: <__Thumbv7ABSLongThunk_afunc34>:160// CHECK9-NEXT: 3300004: f240 0c00 movw r12, #0161// CHECK9-NEXT: 3300008: f2c0 2c30 movt r12, #560162// CHECK9-NEXT: 330000c: 4760 bx r12163// CHECK9: <__Thumbv7ABSLongThunk_tfunc35>:164// CHECK9-NEXT: 330000e: f4ff 97f7 b.w 0x2400000 <tfunc35>165 THUMBFUNCTION 51166 ARMFUNCTION 52167 THUMBFUNCTION 53168 ARMFUNCTION 54169 THUMBFUNCTION 55170 ARMFUNCTION 56171 THUMBFUNCTION 57172 ARMFUNCTION 58173 THUMBFUNCTION 59174 ARMFUNCTION 60175 THUMBFUNCTION 61176 ARMFUNCTION 62177 THUMBFUNCTION 63178 ARMFUNCTION 64179// afunc34 is in range, as is tfunc35 but a branch needs a state change Thunk180 bl afunc34181 b tfunc35182// CHECK10: <afunc64>:183// CHECK10-NEXT: 4100000: e12fff1e bx lr184// CHECK10-NEXT: 4100004: eb87fffd bl 0x2300000 <afunc34>185// CHECK10-NEXT: 4100008: eab3fffd b 0x2e00004 <__ARMv7ABSLongThunk_tfunc35>186 THUMBFUNCTION 65187// afunc34 and tfunc35 are both out of range188 bl afunc34189 bl tfunc35190// CHECK11: <tfunc65>:191// CHECK11: 4200000: 4770 bx lr192// CHECK11-NEXT: 4200002: f4ff d7ff bl 0x3300004 <__Thumbv7ABSLongThunk_afunc34>193// CHECK11-NEXT: 4200006: f500 d002 bl 0x330000e <__Thumbv7ABSLongThunk_tfunc35>194