File: arm-thunk-reuse.s

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (79 lines) | stat: -rw-r--r-- 2,964 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# REQUIRES: arm
# RUN: rm -rf %t && split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=armv7-a-none-eabi --arm-add-build-attributes %t/a.s -o %t/a.o
# RUN: ld.lld -pie -T %t/lds %t/a.o -o %t/a
# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t/a | FileCheck %s
# RUN: llvm-objdump -s --triple=armv7a-none-linux-gnueabi %t/a | FileCheck --check-prefix=CHECK-LE %s

# RUN: llvm-mc -filetype=obj -triple=armv7eb-a-none-eabi --arm-add-build-attributes -mcpu=cortex-a8 %t/a.s -o %t/a.o
# RUN: ld.lld -pie -T %t/lds %t/a.o -o %t/a
# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t/a | FileCheck %s
# RUN: llvm-objdump -s --triple=armv7eb-a-none-eabi %t/a| FileCheck --check-prefix=CHECK-EB %s
# RUN: ld.lld --be8 -pie -T %t/lds %t/a.o -o %t/a
# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t/a | FileCheck %s
# RUN: llvm-objdump -s --triple=armv7eb-a-none-eabi %t/a| FileCheck --check-prefix=CHECK-LE %s

## We create a thunk for dest.
# CHECK-LABEL: <mid>:
# CHECK-NEXT:   2010004:     b       0x2010008 <__ARMV7PILongThunk_dest>
# CHECK-EMPTY:
# CHECK-NEXT:  <__ARMV7PILongThunk_dest>:
# CHECK-NEXT:   2010008:     movw    r12, #65516
# CHECK-NEXT:                movt    r12, #65023
# CHECK-NEXT:                add     r12, r12, pc
# CHECK-NEXT:                bx      r12

## The first instruction can reuse the thunk but the second can't.
## If we reuse the thunk for b, we will get an "out of range" error.
# CHECK-LABEL: <high>:
# CHECK-NEXT:   4010000:      bl      0x2010008 <__ARMV7PILongThunk_dest>
# CHECK-NEXT:                 b       0x4010008 <__ARMV7PILongThunk_dest>
# CHECK-EMPTY:
# CHECK-NEXT:  <__ARMV7PILongThunk_dest>:
# CHECK-NEXT:   4010008:      movw    r12, #65516
# CHECK-NEXT:                 movt    r12, #64511
# CHECK-NEXT:                 add     r12, r12, pc
# CHECK-NEXT:                 bx      r12

# CHECK-EB: Contents of section .text_low:
# CHECK-EB-NEXT: 10000 e320f000 e12fff1e
# CHECK-EB: Contents of section .text_mid:
# CHECK-EB-NEXT: 2010004 eaffffff e30fcfec e34fcdff e08cc00f
# CHECK-EB-NEXT: 2010014 e12fff1c
# CHECK-EB: Contents of section .text_high:
# CHECK-EB-NEXT: 4010000 eb800000 eaffffff e30fcfec e34fcbff
# CHECK-EB-NEXT: 4010010 e08cc00f e12fff1c

# CHECK-LE: Contents of section .text_low:
# CHECK-LE-NEXT: 10000 00f020e3 1eff2fe1
# CHECK-LE: Contents of section .text_mid:
# CHECK-LE-NEXT: 2010004 ffffffea eccf0fe3 ffcd4fe3 0fc08ce0
# CHECK-LE-NEXT: 2010014 1cff2fe1
# CHECK-LE: Contents of section .text_high:
# CHECK-LE-NEXT: 4010000 000080eb ffffffea eccf0fe3 ffcb4fe3
# CHECK-LE-NEXT: 4010010 0fc08ce0 1cff2fe1

#--- a.s
.section .text_low, "ax", %progbits

.globl _start
_start:
  nop
dest:
  bx lr

.section .text_mid, "ax", %progbits
mid:
  b dest

.section .text_high, "ax", %progbits
high:
  bl dest
  b dest

#--- lds
SECTIONS {
  .text_low 0x10000: { *(.text_low) }
  .text_mid 0x2010004 : { *(.text_mid) }
  .text_high 0x4010000 : { *(.text_high) }
}