-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ELF][ARM] Add support for architecture v6m thunks
ARM Architecture v6m is used by the smallest microcontrollers such as the cortex-m0. It is Thumb only (no Thumb 2) which prevents it from using the existing Thumb 2 range extension thunks as these use the Thumb 2 movt/movw instructions. Range extension thunks are not usually needed for microcontrollers due to the small amount of flash and ram on the device, however if code is copied from flash into ram then a range extension thunk is required to call that code. This change adds support for v6m range extension thunks. The procedure call standard APCS permits a thunk to corrupt the intra-procedural scratch register r12 (referred to as ip in the APCS). Most Thumb instructions do not permit access to high registers (r8 - r15) so the thunks must spill some low registers (r0 - r7) to perform the control transfer. Fixes pr39922 Differential Revision: https://reviews.llvm.org/D55555 llvm-svn: 349337
- Loading branch information
Showing
3 changed files
with
153 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // REQUIRES: arm | ||
| // RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv6m-none-eabi %s -o %t | ||
| // RUN: echo "SECTIONS { \ | ||
| // RUN: . = SIZEOF_HEADERS; \ | ||
| // RUN: .text_low : { *(.text_low) *(.text_low2) } \ | ||
| // RUN: .text_high 0x2000000 : { *(.text_high) *(.text_high2) } \ | ||
| // RUN: } " > %t.script | ||
| // RUN: ld.lld --script %t.script %t -o %t2 | ||
| // RUN: llvm-objdump -d %t2 -triple=armv6m-none-eabi | FileCheck %s | ||
| // RUN: ld.lld --script %t.script %t -o %t3 --pie | ||
| // RUN: llvm-objdump -d %t3 -triple=armv6m-none-eabi | FileCheck -check-prefix=CHECK-PI %s | ||
|
|
||
| // Range extension thunks for Arm Architecture v6m. Only Thumb instructions | ||
| // are permitted which limits the access to instructions that can access the | ||
| // high registers (r8 - r15), this means that the thunks have to spill | ||
| // low registers (r0 - r7) in order to perform the transfer of control. | ||
|
|
||
| .syntax unified | ||
| .section .text_low, "ax", %progbits | ||
| .thumb | ||
| .type _start, %function | ||
| .balign 4 | ||
| .globl _start | ||
| _start: | ||
| bl far | ||
|
|
||
| .section .text_high, "ax", %progbits | ||
| .globl far | ||
| .type far, %function | ||
| far: | ||
| bx lr | ||
|
|
||
| // CHECK: Disassembly of section .text_low: | ||
| // CHECK-NEXT: _start: | ||
| // CHECK-NEXT: 94: 00 f0 00 f8 bl #0 | ||
| // CHECK: __Thumbv6MABSLongThunk_far: | ||
| // CHECK-NEXT: 98: 03 b4 push {r0, r1} | ||
| // CHECK-NEXT: 9a: 01 48 ldr r0, [pc, #4] | ||
| // CHECK-NEXT: 9c: 01 90 str r0, [sp, #4] | ||
| // CHECK-NEXT: 9e: 01 bd pop {r0, pc} | ||
| // CHECK: a0: 01 00 00 02 .word 0x02000001 | ||
| // CHECK: Disassembly of section .text_high: | ||
| // CHECK-NEXT: far: | ||
| // CHECK-NEXT: 2000000: 70 47 bx lr | ||
|
|
||
| // CHECK-PI: Disassembly of section .text_low: | ||
| // CHECK-PI-NEXT: _start: | ||
| // CHECK-PI-NEXT: 130: 00 f0 00 f8 bl #0 | ||
| // CHECK-PI: __Thumbv6MPILongThunk_far: | ||
| // CHECK-PI-NEXT: 134: 01 b4 push {r0} | ||
| // CHECK-PI-NEXT: 136: 02 48 ldr r0, [pc, #8] | ||
| // CHECK-PI-NEXT: 138: 84 46 mov r12, r0 | ||
| // CHECK-PI-NEXT: 13a: 01 bc pop {r0} | ||
| // pc = pc (0x13c + 4) + r12 (1fffec1) = 0x2000001 = .far | ||
| // CHECK-PI-NEXT: 13c: e7 44 add pc, r12 | ||
| // CHECK-PI-NEXT: 13e: c0 46 mov r8, r8 | ||
| // CHECK-PI: 140: c1 fe ff 01 .word 0x01fffec1 | ||
|
|
||
| // CHECK-PI: Disassembly of section .text_high: | ||
| // CHECK-PI-NEXT: far: | ||
| // CHECK-PI-NEXT: 2000000: 70 47 bx lr |