Skip to content

Commit d86079f

Browse files
authored
[llvm-readelf] Print more information for RELR
llvm-readelf/llvm-readobj print RELR as REL relocations with a fixed type (e.g. `R_*_RELATIVE`). GNU readelf printed only addresses and have recently switched to a more descritive style that includes a symbolic address column (symbolized using .symtab/.strtab) (milestone: binutils 2.43). This patch implements the new GNU style, which seems superior to the current REL style and essentially obsoletes LLVM-specific --raw-relr (`printRelrReloc`). Pull Request: llvm#89162
1 parent 854cc89 commit d86079f

File tree

4 files changed

+239
-88
lines changed

4 files changed

+239
-88
lines changed

lld/test/ELF/pack-dyn-relocs.s

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -328,31 +328,31 @@
328328
// RELR64-NEXT: 0000000000030510 0000000200000101 R_AARCH64_ABS64 0000000000000000 zed2 + 0
329329
// RELR64-EMPTY:
330330
// RELR64-NEXT: Relocation section '.relr.dyn' at offset {{.*}} contains 24 entries:
331-
// RELR64-NEXT: Offset Info Type Symbol's Value Symbol's Name
332-
// RELR64-NEXT: 0000000000030490 0000000000000403 R_AARCH64_RELATIVE
333-
// RELR64-NEXT: 0000000000030498 0000000000000403 R_AARCH64_RELATIVE
334-
// RELR64-NEXT: 00000000000304a0 0000000000000403 R_AARCH64_RELATIVE
335-
// RELR64-NEXT: 00000000000304a8 0000000000000403 R_AARCH64_RELATIVE
336-
// RELR64-NEXT: 00000000000304b0 0000000000000403 R_AARCH64_RELATIVE
337-
// RELR64-NEXT: 00000000000304b8 0000000000000403 R_AARCH64_RELATIVE
338-
// RELR64-NEXT: 00000000000304c0 0000000000000403 R_AARCH64_RELATIVE
339-
// RELR64-NEXT: 00000000000304c8 0000000000000403 R_AARCH64_RELATIVE
340-
// RELR64-NEXT: 00000000000304d8 0000000000000403 R_AARCH64_RELATIVE
341-
// RELR64-NEXT: 00000000000304e0 0000000000000403 R_AARCH64_RELATIVE
342-
// RELR64-NEXT: 00000000000304e8 0000000000000403 R_AARCH64_RELATIVE
343-
// RELR64-NEXT: 00000000000304f0 0000000000000403 R_AARCH64_RELATIVE
344-
// RELR64-NEXT: 00000000000304f8 0000000000000403 R_AARCH64_RELATIVE
345-
// RELR64-NEXT: 0000000000030500 0000000000000403 R_AARCH64_RELATIVE
346-
// RELR64-NEXT: 0000000000030508 0000000000000403 R_AARCH64_RELATIVE
347-
// RELR64-NEXT: 0000000000030520 0000000000000403 R_AARCH64_RELATIVE
348-
// RELR64-NEXT: 0000000000030528 0000000000000403 R_AARCH64_RELATIVE
349-
// RELR64-NEXT: 0000000000030530 0000000000000403 R_AARCH64_RELATIVE
350-
// RELR64-NEXT: 0000000000030538 0000000000000403 R_AARCH64_RELATIVE
351-
// RELR64-NEXT: 0000000000030540 0000000000000403 R_AARCH64_RELATIVE
352-
// RELR64-NEXT: 0000000000030548 0000000000000403 R_AARCH64_RELATIVE
353-
// RELR64-NEXT: 0000000000030550 0000000000000403 R_AARCH64_RELATIVE
354-
// RELR64-NEXT: 0000000000030558 0000000000000403 R_AARCH64_RELATIVE
355-
// RELR64-NEXT: 0000000000030560 0000000000000403 R_AARCH64_RELATIVE
331+
// RELR64-NEXT: Symbolic Address
332+
// RELR64-NEXT: $d.0{{$}}
333+
// RELR64-NEXT: $d.0 + 0x8
334+
// RELR64-NEXT: $d.0 + 0x10
335+
// RELR64-NEXT: $d.0 + 0x18
336+
// RELR64-NEXT: $d.0 + 0x20
337+
// RELR64-NEXT: $d.0 + 0x28
338+
// RELR64-NEXT: $d.0 + 0x30
339+
// RELR64-NEXT: $d.0 + 0x38
340+
// RELR64-NEXT: $d.0 + 0x48
341+
// RELR64-NEXT: $d.0 + 0x50
342+
// RELR64-NEXT: $d.0 + 0x58
343+
// RELR64-NEXT: $d.0 + 0x60
344+
// RELR64-NEXT: $d.0 + 0x68
345+
// RELR64-NEXT: $d.0 + 0x70
346+
// RELR64-NEXT: $d.0 + 0x78
347+
// RELR64-NEXT: $d.0 + 0x90
348+
// RELR64-NEXT: $d.0 + 0x98
349+
// RELR64-NEXT: $d.0 + 0xa0
350+
// RELR64-NEXT: $d.0 + 0xa8
351+
// RELR64-NEXT: $d.0 + 0xb0
352+
// RELR64-NEXT: $d.0 + 0xb8
353+
// RELR64-NEXT: $d.0 + 0xc0
354+
// RELR64-NEXT: $d.0 + 0xc8
355+
// RELR64-NEXT: $d.0 + 0xd0
356356
// RELR64-EMPTY:
357357
// RELR64-NEXT: Hex dump of section '.data':
358358
// RELR64-NEXT: 0x00030490 90040300 00000000 91040300 00000000 .

lld/test/ELF/partition-pack-dyn-relocs.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
// CHECK-EMPTY:
3030

3131
// CHECK: Relocation section '.relr.dyn'
32-
// CHECK-NEXT: Offset
33-
// PART0-NEXT: 000000000000[[DATA_SEGMENT]]378 {{.*}} R_X86_64_RELATIVE
34-
// PART1-NEXT: 000000000000[[DATA_SEGMENT]]340 {{.*}} R_X86_64_RELATIVE
32+
// CHECK-NEXT: Address Symbolic Address
33+
// PART0-NEXT: 000000000000[[DATA_SEGMENT]]378 p0{{$}}
34+
// PART1-NEXT: 000000000000[[DATA_SEGMENT]]340 p1{{$}}
3535
// CHECK-EMPTY:
3636

3737
.section .llvm_sympart,"",@llvm_sympart

llvm/test/tools/llvm-readobj/ELF/relr-relocs.test

Lines changed: 101 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,39 @@
4747
# RAW-GNU1-NEXT: 00000000000f0501
4848
# RAW-GNU1-NEXT: 000a700550400009
4949

50-
# RUN: llvm-readelf --relocations %t1 | FileCheck --check-prefix=GNU1 %s
51-
# GNU1: Relocation section '.relr.dyn' at offset 0x40 contains 21 entries:
52-
# GNU1: 0000000000010d60 0000000000000008 R_X86_64_RELATIVE
53-
# GNU1-NEXT: 0000000000010d68 0000000000000008 R_X86_64_RELATIVE
54-
# GNU1-NEXT: 0000000000010da0 0000000000000008 R_X86_64_RELATIVE
55-
# GNU1-NEXT: 0000000000020000 0000000000000008 R_X86_64_RELATIVE
56-
# GNU1-NEXT: 0000000000020040 0000000000000008 R_X86_64_RELATIVE
57-
# GNU1-NEXT: 0000000000020050 0000000000000008 R_X86_64_RELATIVE
58-
# GNU1-NEXT: 0000000000020080 0000000000000008 R_X86_64_RELATIVE
59-
# GNU1-NEXT: 0000000000020088 0000000000000008 R_X86_64_RELATIVE
60-
# GNU1-NEXT: 0000000000020090 0000000000000008 R_X86_64_RELATIVE
61-
# GNU1-NEXT: 0000000000020098 0000000000000008 R_X86_64_RELATIVE
62-
# GNU1-NEXT: 0000000000020210 0000000000000008 R_X86_64_RELATIVE
63-
# GNU1-NEXT: 00000000000202a8 0000000000000008 R_X86_64_RELATIVE
64-
# GNU1-NEXT: 00000000000202d8 0000000000000008 R_X86_64_RELATIVE
65-
# GNU1-NEXT: 00000000000202e8 0000000000000008 R_X86_64_RELATIVE
66-
# GNU1-NEXT: 00000000000202f8 0000000000000008 R_X86_64_RELATIVE
67-
# GNU1-NEXT: 0000000000020308 0000000000000008 R_X86_64_RELATIVE
68-
# GNU1-NEXT: 0000000000020358 0000000000000008 R_X86_64_RELATIVE
69-
# GNU1-NEXT: 0000000000020360 0000000000000008 R_X86_64_RELATIVE
70-
# GNU1-NEXT: 0000000000020368 0000000000000008 R_X86_64_RELATIVE
71-
# GNU1-NEXT: 0000000000020380 0000000000000008 R_X86_64_RELATIVE
72-
# GNU1-NEXT: 0000000000020390 0000000000000008 R_X86_64_RELATIVE
50+
# RUN: llvm-readelf --relocations %t1 | FileCheck --check-prefix=GNU1 --match-full-lines --strict-whitespace %s
51+
# GNU1:Relocation section '.relr.dyn' at offset 0x40 contains 21 entries:
52+
# GNU1-NEXT:Index: Entry Address Symbolic Address
53+
# GNU1-NEXT:0000: 0000000000010d60 0000000000010d60
54+
# GNU1-NEXT:0001: 0000000000000103 0000000000010d68
55+
# GNU1-NEXT: 0000000000010da0 base + 0x30
56+
# GNU1-NEXT:0002: 0000000000020000 0000000000020000 foo
57+
# GNU1-NEXT:0003: 00000000000f0501 0000000000020040 foo + 0x40
58+
# GNU1-NEXT: 0000000000020050 foo + 0x50
59+
# GNU1-NEXT: 0000000000020080 foo + 0x80
60+
# GNU1-NEXT: 0000000000020088 foo + 0x88
61+
# GNU1-NEXT: 0000000000020090 foo + 0x90
62+
# GNU1-NEXT: 0000000000020098 foo + 0x98
63+
# GNU1-NEXT:0004: 000a700550400009 0000000000020210 bar + 0x10
64+
# GNU1-NEXT: 00000000000202a8 bar + 0xa8
65+
# GNU1-NEXT: 00000000000202d8 bar + 0xd8
66+
# GNU1-NEXT: 00000000000202e8 bar + 0xe8
67+
# GNU1-NEXT: 00000000000202f8 bar + 0xf8
68+
# GNU1-NEXT: 0000000000020308 bar + 0x108
69+
# GNU1-NEXT: 0000000000020358 bar + 0x158
70+
# GNU1-NEXT: 0000000000020360 bar + 0x160
71+
# GNU1-NEXT: 0000000000020368 bar + 0x168
72+
# GNU1-NEXT: 0000000000020380 bar + 0x180
73+
# GNU1-NEXT: 0000000000020390 bar + 0x190
74+
# GNU1-NOT:{{.}}
75+
76+
## The addresses are not symbolized in the absence of .symtab.
77+
# RUN: llvm-objcopy --strip-all %t1 %t1.stripped
78+
# RUN: llvm-readelf --relocations %t1.stripped | FileCheck --check-prefix=GNU1S --match-full-lines --strict-whitespace %s
79+
# GNU1S:Relocation section '.relr.dyn' at offset 0x40 contains 21 entries:
80+
# GNU1S-NEXT:Index: Entry Address Symbolic Address
81+
# GNU1S-NEXT:0000: 0000000000010d60 0000000000010d60
82+
# GNU1S-NEXT:0001: 0000000000000103 0000000000010d68
7383

7484
--- !ELF
7585
FileHeader:
@@ -83,6 +93,18 @@ Sections:
8393
Flags: [ SHF_ALLOC ]
8494
Entries: [ 0x0000000000010D60, 0x0000000000000103, 0x0000000000020000,
8595
0x00000000000F0501, 0x000A700550400009 ]
96+
Symbols:
97+
- Name: bar
98+
Value: 0x20200
99+
Section: .relr.dyn
100+
- Name: foo
101+
Value: 0x20000
102+
Section: .relr.dyn
103+
- Name: base
104+
Value: 0x10d70
105+
Section: .relr.dyn
106+
- Name: ignored
107+
Value: 0x20210
86108

87109
# RUN: yaml2obj --docnum=2 %s -o %t2
88110
# RUN: llvm-readobj --relocations --raw-relr %t2 | \
@@ -124,22 +146,24 @@ Sections:
124146
# RAW-GNU2-NEXT: 000f0501
125147
# RAW-GNU2-NEXT: 50400009
126148

127-
# RUN: llvm-readelf --relocations %t2 | FileCheck --check-prefix=GNU2 %s
128-
# GNU2: Relocation section '.relr.dyn' at offset 0x34 contains 14 entries:
129-
# GNU2: 00010d60 00000008 R_386_RELATIVE
130-
# GNU2-NEXT: 00010d64 00000008 R_386_RELATIVE
131-
# GNU2-NEXT: 00010d80 00000008 R_386_RELATIVE
132-
# GNU2-NEXT: 00020000 00000008 R_386_RELATIVE
133-
# GNU2-NEXT: 00020020 00000008 R_386_RELATIVE
134-
# GNU2-NEXT: 00020028 00000008 R_386_RELATIVE
135-
# GNU2-NEXT: 00020040 00000008 R_386_RELATIVE
136-
# GNU2-NEXT: 00020044 00000008 R_386_RELATIVE
137-
# GNU2-NEXT: 00020048 00000008 R_386_RELATIVE
138-
# GNU2-NEXT: 0002004c 00000008 R_386_RELATIVE
139-
# GNU2-NEXT: 00020088 00000008 R_386_RELATIVE
140-
# GNU2-NEXT: 000200d4 00000008 R_386_RELATIVE
141-
# GNU2-NEXT: 000200ec 00000008 R_386_RELATIVE
142-
# GNU2-NEXT: 000200f4 00000008 R_386_RELATIVE
149+
# RUN: llvm-readelf --relocations %t2 | FileCheck --check-prefix=GNU2 --match-full-lines --strict-whitespace %s
150+
# GNU2:Relocation section '.relr.dyn' at offset 0x34 contains 14 entries:
151+
# GNU2-NEXT:Index: Entry Address Symbolic Address
152+
# GNU2-NEXT:0000: 00010d60 00010d60 .relr.dyn
153+
# GNU2-NEXT:0001: 00000103 00010d64 .relr.dyn + 0x4
154+
# GNU2-NEXT: 00010d80 .relr.dyn + 0x20
155+
# GNU2-NEXT:0002: 00020000 00020000 .relr.dyn + 0xf2a0
156+
# GNU2-NEXT:0003: 000f0501 00020020 .relr.dyn + 0xf2c0
157+
# GNU2-NEXT: 00020028 .relr.dyn + 0xf2c8
158+
# GNU2-NEXT: 00020040 .relr.dyn + 0xf2e0
159+
# GNU2-NEXT: 00020044 .relr.dyn + 0xf2e4
160+
# GNU2-NEXT: 00020048 .relr.dyn + 0xf2e8
161+
# GNU2-NEXT: 0002004c .relr.dyn + 0xf2ec
162+
# GNU2-NEXT:0004: 50400009 00020088 .relr.dyn + 0xf328
163+
# GNU2-NEXT: 000200d4 .relr.dyn + 0xf374
164+
# GNU2-NEXT: 000200ec .relr.dyn + 0xf38c
165+
# GNU2-NEXT: 000200f4 .relr.dyn + 0xf394
166+
# GNU2-NOT:{{.}}
143167

144168
--- !ELF
145169
FileHeader:
@@ -156,6 +180,11 @@ Sections:
156180
EntSize: [[ENTSIZE=<none>]]
157181
ShType: [[SHTYPE=<none>]]
158182
Link: [[LINK=<none>]]
183+
Symbols:
184+
- Name: .relr.dyn
185+
Type: STT_SECTION
186+
Value: 0x10D60
187+
Section: .relr.dyn
159188

160189
## Check we report a warning when we are unable to dump relocations
161190
## for a SHT_RELR/SHT_ANDROID_RELR/SHT_AARCH64_AUTH_RELR section.
@@ -175,7 +204,6 @@ Sections:
175204

176205
# BROKEN-GNU: warning: '[[FILE]]': unable to get the number of relocations in [[SECNAME]] section with index 1: section [index 1] has invalid sh_entsize: expected 4, but got 1
177206
# BROKEN-GNU: Relocation section '.relr.dyn' at offset 0x34 contains <?> entries:
178-
# BROKEN-GNU-NEXT: Offset Info Type Sym. Value Symbol's Name
179207
# BROKEN-GNU-NEXT: warning: '[[FILE]]': unable to read relocations from [[SECNAME]] section with index 1: section [index 1] has invalid sh_entsize: expected 4, but got 1
180208

181209
## Case B: check the case when relocations can't be read from an SHT_ANDROID_RELR section.
@@ -218,3 +246,36 @@ Sections:
218246
# RUN: FileCheck -DFILE=%t2.has.link --check-prefix=RAW-LLVM2 %s
219247
# RUN: llvm-readelf --relocations --raw-relr %t2.has.link 2>&1 | \
220248
# RUN: FileCheck -DFILE=%t2.has.link --check-prefix=RAW-GNU2 %s
249+
250+
## .symtab is invalid. Check we report a warning and print entries without symbolization.
251+
# RUN: yaml2obj --docnum=3 -DENTSIZE=1 %s -o %t3.err1
252+
# RUN: llvm-readelf -r %t3.err1 2>&1 | FileCheck -DFILE=%t3.err1 --check-prefixes=GNU3,GNU3-ERR1 --match-full-lines %s
253+
# RUN: yaml2obj --docnum=3 -DLINK=0xff %s -o %t3.err2
254+
# RUN: llvm-readelf -r %t3.err2 2>&1 | FileCheck -DFILE=%t3.err2 --check-prefixes=GNU3,GNU3-ERR2 --match-full-lines %s
255+
256+
# GNU3:Index: Entry Address Symbolic Address
257+
# GNU3-ERR1-NEXT:{{.*}}warning: '[[FILE]]': unable to read symbols from the SHT_SYMTAB section: section [index 2] has invalid sh_entsize: expected 24, but got 1
258+
# GNU3-ERR2-NEXT:{{.*}}warning: '[[FILE]]': unable to get the string table for the SHT_SYMTAB section: invalid section index: 255
259+
# GNU3-NEXT:0000: 0000000000010d60 0000000000010d60
260+
# GNU3-NEXT:0001: 0000000000000103 0000000000010d68
261+
# GNU3-NEXT: 0000000000010da0
262+
# GNU3-NOT:{{.}}
263+
264+
--- !ELF
265+
FileHeader:
266+
Class: ELFCLASS64
267+
Data: ELFDATA2LSB
268+
Type: ET_DYN
269+
Machine: EM_X86_64
270+
Sections:
271+
- Name: .relr.dyn
272+
Type: SHT_RELR
273+
Flags: [ SHF_ALLOC ]
274+
Entries: [ 0x0000000000010D60, 0x0000000000000103 ]
275+
- Name: .symtab
276+
Type: SHT_SYMTAB
277+
Link: [[LINK=.strtab]]
278+
EntSize: [[ENTSIZE=0x18]]
279+
Symbols:
280+
- Name: bar
281+
Value: 0x10D60

0 commit comments

Comments
 (0)