xref: /llvm-project/lld/test/ELF/arm-bl-v4.s (revision 9ea44c6894270546d6d88ef0d3abcf1e1876acae)
1// REQUIRES: arm
2// RUN: rm -rf %t && split-file %s %t
3// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv4-none-linux-gnueabi %t/a.s -o %t/a.o
4// RUN: ld.lld %t/a.o --script %t/far.lds -o %t/a-far
5// RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn --triple=armv4-none-linux-gnueabi %t/a-far | FileCheck %s --check-prefixes=FAR
6// RUN: ld.lld %t/a.o --script %t/near.lds -o %t/a-near
7// RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn --triple=armv4-none-linux-gnueabi %t/a-near | FileCheck %s --check-prefixes=NEAR
8// RUN: ld.lld %t/a.o -pie --script %t/far.lds -o %t/a-far-pie
9// RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn --triple=armv4-none-linux-gnueabi %t/a-far-pie | FileCheck %s --check-prefixes=FAR-PIE
10// RUN: ld.lld %t/a.o -pie --script %t/near.lds -o %t/a-near-pie
11// RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn --triple=armv4-none-linux-gnueabi %t/a-near-pie | FileCheck %s --check-prefixes=NEAR
12
13// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv4eb-none-linux-gnueabi %t/a.s -o %t/a.o
14// RUN: ld.lld %t/a.o --script %t/far.lds -o %t/a-far
15// RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn --triple=armv4eb-none-linux-gnueabi %t/a-far | FileCheck %s --check-prefixes=FAR-EB
16// RUN: ld.lld %t/a.o --script %t/near.lds -o %t/a-near
17// RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn --triple=armv4eb-none-linux-gnueabi %t/a-near | FileCheck %s --check-prefixes=NEAR
18// RUN: ld.lld %t/a.o -pie --script %t/far.lds -o %t/a-far-pie
19// RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn --triple=armv4eb-none-linux-gnueabi %t/a-far-pie | FileCheck %s --check-prefixes=FAR-EB-PIE
20// RUN: ld.lld %t/a.o -pie --script %t/near.lds -o %t/a-near-pie
21// RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn --triple=armv4eb-none-linux-gnueabi %t/a-near-pie | FileCheck %s --check-prefixes=NEAR
22
23/// On Armv4 there is no blx instruction so long branch/exchange looks slightly
24/// different.
25
26//--- a.s
27 .text
28 .syntax unified
29 .cpu    arm7tdmi
30
31 .section .low, "ax", %progbits
32 .arm
33 .globl _start
34 .type   _start,%function
35 .p2align       2
36_start:
37  bl target
38  mov pc, lr
39
40// FAR-LABEL: <_start>:
41// FAR-NEXT:   1000000:      	bl	0x1000008 <__ARMv5LongLdrPcThunk_target> @ imm = #0
42// FAR-NEXT:                	mov pc, lr
43// FAR-EMPTY:
44// FAR-NEXT:  <__ARMv5LongLdrPcThunk_target>:
45// FAR-NEXT:   1000008:      	ldr	pc, [pc, #-4]           @ 0x100000c <__ARMv5LongLdrPcThunk_target+0x4>
46// FAR-NEXT:   100000c: 00 00 00 06  	.word	0x06000000
47
48// FAR-EB-LABEL: <_start>:
49// FAR-EB-NEXT:   1000000:      	bl	0x1000008 <__ARMv5LongLdrPcThunk_target> @ imm = #0
50// FAR-EB-NEXT:                	mov pc, lr
51// FAR-EB-EMPTY:
52// FAR-EB-NEXT:  <__ARMv5LongLdrPcThunk_target>:
53// FAR-EB-NEXT:   1000008:      	ldr	pc, [pc, #-4]           @ 0x100000c <__ARMv5LongLdrPcThunk_target+0x4>
54// FAR-EB-NEXT:   100000c: 06 00 00 00  	.word	0x06000000
55
56// FAR-PIE-LABEL: <_start>:
57// FAR-PIE-NEXT:   1000000:      	bl	0x1000008 <__ARMv4PILongThunk_target> @ imm = #0
58// FAR-PIE-NEXT:                	mov pc, lr
59// FAR-PIE-EMPTY:
60// FAR-PIE-NEXT:  <__ARMv4PILongThunk_target>:
61// FAR-PIE-NEXT:   1000008:      	ldr	r12, [pc]               @ 0x1000010 <__ARMv4PILongThunk_target+0x8>
62// FAR-PIE-NEXT:                	add	pc, pc, r12
63// FAR-PIE-NEXT:   1000010: ec ff ff 04  	.word	0x04ffffec
64
65// FAR-EB-PIE-LABEL: <_start>:
66// FAR-EB-PIE-NEXT:   1000000:      	bl	0x1000008 <__ARMv4PILongThunk_target> @ imm = #0
67// FAR-EB-PIE-NEXT:                	mov pc, lr
68// FAR-EB-PIE-EMPTY:
69// FAR-EB-PIE-NEXT:  <__ARMv4PILongThunk_target>:
70// FAR-EB-PIE-NEXT:   1000008:      	ldr	r12, [pc]               @ 0x1000010 <__ARMv4PILongThunk_target+0x8>
71// FAR-EB-PIE-NEXT:                	add	pc, pc, r12
72// FAR-EB-PIE-NEXT:   1000010: 04 ff ff ec  	.word	0x04ffffec
73
74// NEAR-LABEL: <_start>:
75// NEAR-NEXT:  1000000:      	bl 0x1000008 <target> @ imm = #0
76// NEAR-NEXT:               	mov pc, lr
77
78.section .high, "ax", %progbits
79 .arm
80 .globl target
81 .type target,%function
82target:
83  mov pc, lr
84
85// FAR-LABEL: <target>:
86// FAR-NEXT:   6000000:      	mov pc, lr
87
88// FAR-EB-LABEL: <target>:
89// FAR-EB-NEXT:   6000000:      	mov pc, lr
90
91// FAR-PIE-LABEL: <target>:
92// FAR-PIE-NEXT:   6000000:     mov pc, lr
93
94// FAR-EB-PIE-LABEL: <target>:
95// FAR-EB-PIE-NEXT:   6000000:     mov pc, lr
96
97// NEAR-LABEL: <target>:
98// NEAR-LABEL:  1000008:      	mov pc, lr
99
100//--- far.lds
101SECTIONS {
102  . = SIZEOF_HEADERS;
103  .low 0x01000000 : { *(.low) }
104  .high 0x06000000 : { *(.high) }
105}
106
107//--- near.lds
108SECTIONS {
109  . = SIZEOF_HEADERS;
110  .all 0x01000000 : { *(.low) *(.high) }
111}
112