arm-ldrlit.s
4.34 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// REQUIRES: arm
// RUN: llvm-mc --triple=armv7a-none-eabi --arm-add-build-attributes -filetype=obj -o %t.o %s
// RUN: echo "SECTIONS { \
// RUN: .rodata.low 0x8012 : { *(.rodata.low) } \
// RUN: .text.low 0x8f00 : { *(.text.low) } \
// RUN: .text.neg 0x9000 : { *(.text.neg) } \
// RUN: .text.pos 0x10000 : { *(.text.pos) } \
// RUN: .text.high 0x10100 : { *(.text.high) } \
// RUN: .data_high 0x1100f : { *(.data.high) } \
// RUN: } " > %t.script
// RUN: ld.lld -n --script %t.script %t.o -o %t
// RUN: llvm-readobj --symbols %t | FileCheck %s --check-prefix=SYMS
// RUN: llvm-objdump -d --no-show-raw-insn --triple=armv7a-none-eabi %t | FileCheck %s
/// Test the various legal cases for the R_ARM_LDR_PC_G0 relocation
/// Range is +- 4095 bytes
/// The Thumb bit for function symbols is ignored
.section .rodata.low, "a", %progbits
dat1:
.byte 0
dat2:
.byte 1
dat3:
.byte 2
dat4:
.byte 3
.section .text.low, "ax", %progbits
.balign 4
.global target1
.type target1, %function
target1:
bx lr
.type target2, %function
target2:
bx lr
.section .text.neg, "ax", %progbits
.balign 4
.global _start
.type _start, %function
_start:
/// ldr r0, dat1
.inst 0xe51f0008
.reloc 0, R_ARM_LDR_PC_G0, dat1
/// ldr r1, dat2
.inst 0xe51f1008
.reloc 4, R_ARM_LDR_PC_G0, dat2
/// ldr r2, dat3
.inst 0xe51f2008
.reloc 8, R_ARM_LDR_PC_G0, dat3
/// ldr r3, dat4
.inst 0xe51f3008
.reloc 0xc, R_ARM_LDR_PC_G0, dat4
/// ldr r0, target1
.inst 0xe51f0008
.reloc 0x10, R_ARM_LDR_PC_G0, target1
/// ldr r1, target2
.inst 0xe51f1008
.reloc 0x14, R_ARM_LDR_PC_G0, target2
.section .text.pos, "ax", %progbits
.balign 4
.global pos
.type pos, %function
pos:
/// ldr r2, target3
.inst 0xe51f2008
.reloc 0, R_ARM_LDR_PC_G0, target3
/// ldr r3, target4
.inst 0xe51f3008
.reloc 4, R_ARM_LDR_PC_G0, target4
/// ldr r0, dat5
.inst 0xe51f0008
.reloc 8, R_ARM_LDR_PC_G0, dat5
/// ldr r1, dat6
.inst 0xe51f1008
.reloc 0xc, R_ARM_LDR_PC_G0, dat6
/// ldr r2, dat7
.inst 0xe51f2008
.reloc 0x10, R_ARM_LDR_PC_G0, dat7
/// ldr r3, dat8
.inst 0xe51f3008
.reloc 0x14, R_ARM_LDR_PC_G0, dat8
/// positive addend in instruction, all others are -4 (PC bias)
///ldr r4, dat5 + 8
.inst 0xe59f4000
.reloc 0x18, R_ARM_LDR_PC_G0, dat5
.section .text.high, "ax", %progbits
.balign 4
.type target3, %function
.global target3
target3:
bx lr
.thumb_func
target4:
bx lr
.section .data.high, "aw", %progbits
dat5:
.byte 0
dat6:
.byte 1
dat7:
.byte 2
dat8:
.byte 3
// SYMS: Name: dat1
// SYMS-NEXT: Value: 0x8012
// SYMS: Name: dat2
// SYMS-NEXT: Value: 0x8013
// SYMS: Name: dat3
// SYMS-NEXT: Value: 0x8014
// SYMS: Name: dat4
// SYMS-NEXT: Value: 0x8015
// CHECK: 00008f00 <target1>:
// CHECK-NEXT: 8f00: bx lr
// CHECK: 00008f04 <target2>:
// CHECK-NEXT: 8f04: bx lr
// CHECK: 00009000 <_start>:
/// 0x9000 + 0x8 - 0xff6 = 0x8012
// CHECK-NEXT: 9000: ldr r0, [pc, #-4086]
/// 0x9004 + 0x8 - 0xff9 = 0x8013
// CHECK-NEXT: 9004: ldr r1, [pc, #-4089]
/// 0x9008 + 0x8 - 0xffc = 0x8014
// CHECK-NEXT: 9008: ldr r2, [pc, #-4092]
/// 0x900c + 0x8 - 0xfff = 0x8015
// CHECK-NEXT: 900c: ldr r3, [pc, #-4095]
/// 0x9010 + 0x8 - 0x118 = 0x8f00
// CHECK-NEXT: 9010: ldr r0, [pc, #-280]
/// 0x9014 + 0x8 - 0x118 = 0x8f04
// CHECK-NEXT: 9014: ldr r1, [pc, #-280]
///
// CHECK: 00010000 <pos>:
/// 0x10000 + 0x8 + 0xf8 = 0x10100
// CHECK-NEXT: 10000: ldr r2, [pc, #248]
/// 0x10004 + 0x8 + 0xf8 = 0x10104
// CHECK-NEXT: 10004: ldr r3, [pc, #248]
/// 0x10008 + 0x8 + 0xfff = 0x1100f
// CHECK-NEXT: 10008: ldr r0, [pc, #4095]
/// 0x1000c + 0x8 + 0xffc = 0x11010
// CHECK-NEXT: 1000c: ldr r1, [pc, #4092]
/// 0x10010 + 0x8 + 0xff9 = 0x11011
// CHECK-NEXT: 10010: ldr r2, [pc, #4089]
/// 0x10014 + 0x8 + 0xff6 = 0x11012
// CHECK-NEXT: 10014: ldr r3, [pc, #4086]
/// 0x10018 + 0x8 + 0xff7 = 0x11017 = dat5 + 8
// CHECK-NEXT: 10018: ldr r4, [pc, #4087]
// CHECK: 00010100 <target3>:
// CHECK-NEXT: 10100: bx lr
// CHECK: 00010104 <target4>:
// CHECK-NEXT: 10104: bx lr
// SYMS: Name: dat5
// SYMS-NEXT: Value: 0x1100F
// SYMS: Name: dat6
// SYMS-NEXT: Value: 0x11010
// SYMS: Name: dat7
// SYMS-NEXT: Value: 0x11011
// SYMS: Name: dat8
// SYMS-NEXT: Value: 0x11012