packed-relocs.test
10.2 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# The binary blobs in this file were created like this:
# llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu Inputs/elf-packed-relocs1.s -o - | obj2yaml | grep Content:
# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-readobj --relocations %t1 | FileCheck --check-prefix=LLVM1 %s
# LLVM1: Section (1) .rela.dyn {
# LLVM1-NEXT: 0x1100 R_X86_64_RELATIVE - 0x0
# LLVM1-NEXT: 0x1180 R_X86_64_RELATIVE - 0x0
# LLVM1-NEXT: 0x1188 R_X86_64_64 sym1 0x0
# LLVM1-NEXT: 0x1190 R_X86_64_64 sym2 0x0
# LLVM1-NEXT: 0x1191 R_X86_64_64 sym1 0x8
# LLVM1-NEXT: 0x1193 R_X86_64_64 sym2 0xC
# LLVM1-NEXT: 0x1197 R_X86_64_64 sym1 0xA
# LLVM1-NEXT: 0x119F R_X86_64_64 sym2 0xA
# LLVM1-NEXT: }
# RUN: llvm-readelf --relocations %t1 | FileCheck --check-prefix=GNU1 %s
# GNU1: Relocation section '.rela.dyn' at offset 0x40 contains 8 entries:
# GNU1: 0000000000001100 0000000000000008 R_X86_64_RELATIVE 0
# GNU1-NEXT: 0000000000001180 0000000000000008 R_X86_64_RELATIVE 0
# GNU1-NEXT: 0000000000001188 0000000100000001 R_X86_64_64 0000000000000000 sym1 + 0
# GNU1-NEXT: 0000000000001190 0000000200000001 R_X86_64_64 0000000000000000 sym2 + 0
# GNU1-NEXT: 0000000000001191 0000000100000001 R_X86_64_64 0000000000000000 sym1 + 8
# GNU1-NEXT: 0000000000001193 0000000200000001 R_X86_64_64 0000000000000000 sym2 + c
# GNU1-NEXT: 0000000000001197 0000000100000001 R_X86_64_64 0000000000000000 sym1 + a
# GNU1-NEXT: 000000000000119f 0000000200000001 R_X86_64_64 0000000000000000 sym2 + a
# elf-packed-relocs1.s
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .rela.dyn
Type: SHT_ANDROID_RELA
Flags: [ SHF_ALLOC ]
Link: [[LINK=.symtab]]
Content: 41505332088020020108800280010202088180808010818080802002080181808080100802818080802004020C7E048180808010088180808020
ShOffset: [[SHOFFSET=<none>]]
Symbols:
- Name: sym1
Binding: STB_GLOBAL
- Name: sym2
Binding: STB_GLOBAL
## Check we report a warning when we are unable to dump relocations for a SHT_ANDROID_RELA section.
# RUN: yaml2obj --docnum=1 -DSHOFFSET=0xffffffff %s -o %t1.broken
# RUN: llvm-readobj --relocations %t1.broken 2>&1 | FileCheck -DFILE=%t1.broken --check-prefix=BROKEN-RELA-LLVM %s
# RUN: llvm-readelf --relocations %t1.broken 2>&1 | FileCheck -DFILE=%t1.broken --check-prefix=BROKEN-RELA-GNU %s
# BROKEN-RELA-LLVM: Relocations [
# BROKEN-RELA-LLVM-NEXT: Section (1) .rela.dyn {
# BROKEN-RELA-LLVM-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_ANDROID_RELA section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x3a) that is greater than the file size (0x238)
# BROKEN-RELA-LLVM-NEXT: }
# BROKEN-RELA-LLVM-NEXT: ]
# BROKEN-RELA-GNU: warning: '[[FILE]]': unable to get the number of relocations in SHT_ANDROID_RELA section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x3a) that is greater than the file size (0x238)
# BROKEN-RELA-GNU: Relocation section '.rela.dyn' at offset 0xffffffff contains <?> entries:
# BROKEN-RELA-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
# BROKEN-RELA-GNU-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_ANDROID_RELA section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x3a) that is greater than the file size (0x238)
## Check we report a warning when the sh_link field of the SHT_ANDROID_RELA section is broken.
# RUN: yaml2obj --docnum=1 -DLINK=0xffffffff %s -o %t1.broken.link
# RUN: llvm-readobj --relocations %t1.broken.link 2>&1 | \
# RUN: FileCheck -DFILE=%t1.broken.link --check-prefix=BROKEN-RELA-LINK-LLVM %s
# RUN: llvm-readelf --relocations %t1.broken.link 2>&1 | \
# RUN: FileCheck -DFILE=%t1.broken.link --check-prefix=BROKEN-RELA-LINK-GNU %s
# BROKEN-RELA-LINK-LLVM: Relocations [
# BROKEN-RELA-LINK-LLVM-NEXT: Section (1) .rela.dyn {
# BROKEN-RELA-LINK-LLVM-NEXT: warning: '[[FILE]]': unable to locate a symbol table for SHT_ANDROID_RELA section with index 1: invalid section index: 4294967295
# BROKEN-RELA-LINK-LLVM-NEXT: }
# BROKEN-RELA-LINK-LLVM-NEXT: ]
# BROKEN-RELA-LINK-GNU: Relocation section '.rela.dyn' at offset 0x40 contains 8 entries:
# BROKEN-RELA-LINK-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
# BROKEN-RELA-LINK-GNU-NEXT: warning: '[[FILE]]': unable to locate a symbol table for SHT_ANDROID_RELA section with index 1: invalid section index: 4294967295
# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-readobj --relocations %t2 | FileCheck --check-prefix=LLVM2 %s
# LLVM2: Section (1) .rel.dyn {
# LLVM2-NEXT: 0x1008 R_386_32 sym1 0x0
# LLVM2-NEXT: 0x1010 R_386_GOT32 sym2 0x0
# LLVM2-NEXT: 0x100C R_386_RELATIVE - 0x0
# LLVM2-NEXT: 0x1008 R_386_RELATIVE - 0x0
# LLVM2-NEXT: 0x1004 R_386_RELATIVE - 0x0
# LLVM2-NEXT: 0x1000 R_386_RELATIVE - 0x0
# LLVM2-NEXT: 0xFFC R_386_RELATIVE - 0x0
# LLVM2-NEXT: 0xFF8 R_386_RELATIVE - 0x0
# LLVM2-NEXT: 0xFF4 R_386_RELATIVE - 0x0
# LLVM2-NEXT: 0xFF0 R_386_RELATIVE - 0x0
# LLVM2-NEXT: }
# RUN: llvm-readelf --relocations %t2 | FileCheck --check-prefix=GNU2 %s
# GNU2: Relocation section '.rel.dyn' at offset 0x34 contains 10 entries:
# GNU2: 00001008 00000101 R_386_32 00000000 sym1
# GNU2-NEXT: 00001010 00000203 R_386_GOT32 00000000 sym2
# GNU2-NEXT: 0000100c 00000008 R_386_RELATIVE
# GNU2-NEXT: 00001008 00000008 R_386_RELATIVE
# GNU2-NEXT: 00001004 00000008 R_386_RELATIVE
# GNU2-NEXT: 00001000 00000008 R_386_RELATIVE
# GNU2-NEXT: 00000ffc 00000008 R_386_RELATIVE
# GNU2-NEXT: 00000ff8 00000008 R_386_RELATIVE
# GNU2-NEXT: 00000ff4 00000008 R_386_RELATIVE
# GNU2-NEXT: 00000ff0 00000008 R_386_RELATIVE
# elf-packed-relocs2.s
--- !ELF
FileHeader:
Class: ELFCLASS32
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_386
Sections:
- Name: .rel.dyn
Type: SHT_ANDROID_REL
Flags: [ SHF_ALLOC ]
Link: [[LINK=.symtab]]
Content: 415053320A80200202088102830408037C08
ShOffset: [[SHOFFSET=<none>]]
Symbols:
- Name: sym1
Binding: STB_GLOBAL
- Name: sym2
Binding: STB_GLOBAL
## Check we report a warning when we are unable to dump relocations for a SHT_ANDROID_REL section.
# RUN: yaml2obj --docnum=2 -DSHOFFSET=0xffffffff %s -o %t2.broken
# RUN: llvm-readobj --relocations %t2.broken 2>&1 | FileCheck -DFILE=%t2.broken --check-prefix=BROKEN-REL-LLVM %s
# RUN: llvm-readelf --relocations %t2.broken 2>&1 | FileCheck -DFILE=%t2.broken --check-prefix=BROKEN-REL-GNU %s
# BROKEN-REL-LLVM: Relocations [
# BROKEN-REL-LLVM-NEXT: Section (1) .rel.dyn {
# BROKEN-REL-LLVM-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_ANDROID_REL section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x12) that cannot be represented
# BROKEN-REL-LLVM-NEXT: }
# BROKEN-REL-LLVM-NEXT: ]
# BROKEN-REL-GNU: warning: '[[FILE]]': unable to get the number of relocations in SHT_ANDROID_REL section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x12) that cannot be represented
# BROKEN-REL-GNU: Relocation section '.rel.dyn' at offset 0xffffffff contains <?> entries:
# BROKEN-REL-GNU-NEXT: Offset Info Type Sym. Value Symbol's Name
# BROKEN-REL-GNU-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_ANDROID_REL section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x12) that cannot be represented
## Check we report a warning when the sh_link field of the SHT_ANDROID_REL section is broken.
# RUN: yaml2obj --docnum=2 -DLINK=0xffffffff %s -o %t2.broken.link
# RUN: llvm-readobj --relocations %t2.broken.link 2>&1 | \
# RUN: FileCheck -DFILE=%t2.broken.link --check-prefix=BROKEN-REL-LINK-LLVM %s
# RUN: llvm-readelf --relocations %t2.broken.link 2>&1 | \
# RUN: FileCheck -DFILE=%t2.broken.link --check-prefix=BROKEN-REL-LINK-GNU %s
# BROKEN-REL-LINK-LLVM: Relocations [
# BROKEN-REL-LINK-LLVM-NEXT: Section (1) .rel.dyn {
# BROKEN-REL-LINK-LLVM-NEXT: warning: '[[FILE]]': unable to locate a symbol table for SHT_ANDROID_REL section with index 1: invalid section index: 4294967295
# BROKEN-REL-LINK-LLVM-NEXT: }
# BROKEN-REL-LINK-LLVM-NEXT: ]
# BROKEN-REL-LINK-GNU: Relocation section '.rel.dyn' at offset 0x34 contains 10 entries:
# BROKEN-REL-LINK-GNU-NEXT: Offset Info Type Sym. Value Symbol's Name
# BROKEN-REL-LINK-GNU-NEXT: warning: '[[FILE]]': unable to locate a symbol table for SHT_ANDROID_REL section with index 1: invalid section index: 4294967295
# RUN: yaml2obj --docnum=3 %s | llvm-readobj --relocations - | FileCheck --check-prefix=LLVM3 %s
#
# LLVM3: Section (1) .rela.dyn {
# LLVM3-NEXT: 0x1100 R_X86_64_RELATIVE - 0x0
# LLVM3-NEXT: 0x1180 R_X86_64_RELATIVE - 0x8
# LLVM3-NEXT: 0x1200 R_X86_64_64 sym1 0x0
# LLVM3-NEXT: 0x1208 R_X86_64_64 sym2 0x0
# LLVM3-NEXT: 0x1210 R_X86_64_64 sym1 0x0
# LLVM3-NEXT: 0x1218 R_X86_64_64 sym2 0x8
# LLVM3-NEXT: }
# RUN: yaml2obj --docnum=3 %s | llvm-readelf -relocations - | FileCheck --check-prefix=GNU3 %s
# GNU3: Relocation section '.rela.dyn' at offset 0x40 contains 6 entries:
# GNU3: 0000000000001100 0000000000000008 R_X86_64_RELATIVE 0
# GNU3-NEXT: 0000000000001180 0000000000000008 R_X86_64_RELATIVE 8
# GNU3-NEXT: 0000000000001200 0000000100000001 R_X86_64_64 0000000000000000 sym1 + 0
# GNU3-NEXT: 0000000000001208 0000000200000001 R_X86_64_64 0000000000000000 sym2 + 0
# GNU3-NEXT: 0000000000001210 0000000100000001 R_X86_64_64 0000000000000000 sym1 + 0
# GNU3-NEXT: 0000000000001218 0000000200000001 R_X86_64_64 0000000000000000 sym2 + 8
# elf-packed-relocs3.s
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .rela.dyn
Type: SHT_ANDROID_RELA
Flags: [ SHF_ALLOC ]
Link: .symtab
Content: 415053320680200208800208008001080802008001818080801008818080802002080881808080100008818080802008
Symbols:
- Name: sym1
Binding: STB_GLOBAL
- Name: sym2
Binding: STB_GLOBAL