1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[llvm-readobj/elf] - Remove unwrapOrError calls from DumpStyle<ELFT>::printRelocationsHelper.

It removes all `unwrapOrError` calls except the first one, which
is is bit different and can be removed separately.

Differential revision: https://reviews.llvm.org/D85303
This commit is contained in:
Georgii Rymar 2020-08-05 16:41:30 +03:00
parent ee3ce7d78d
commit 9d31094c7b
10 changed files with 216 additions and 72 deletions

View File

@ -249,10 +249,10 @@ Symbols: []
# RUN: yaml2obj %s --docnum=12 -o %t12
# RUN: yaml2obj %s --docnum=13 -o %t13
# RUN: not llvm-readobj -r %t12 2>&1 | FileCheck -DFILE=%t12 --check-prefix=INVALID-RELOC-SH-OFFSET %s
# RUN: not llvm-readobj -r %t13 2>&1 | FileCheck -DFILE=%t13 --check-prefix=INVALID-RELOC-SH-OFFSET %s
# RUN: llvm-readobj -r %t12 2>&1 | FileCheck -DFILE=%t12 --check-prefix=INVALID-RELOC-SH-OFFSET -DTYPE=SHT_REL %s
# RUN: llvm-readobj -r %t13 2>&1 | FileCheck -DFILE=%t13 --check-prefix=INVALID-RELOC-SH-OFFSET -DTYPE=SHT_RELA %s
# INVALID-RELOC-SH-OFFSET: error: '[[FILE]]': section [index 1] has a sh_offset (0x10000) + sh_size (0x0) that is greater than the file size (0x160)
# INVALID-RELOC-SH-OFFSET: warning: '[[FILE]]': unable to read relocations from [[TYPE]] section with index 1: section [index 1] has a sh_offset (0x10000) + sh_size (0x0) that is greater than the file size (0x160)
--- !ELF
FileHeader:

View File

@ -1,7 +1,8 @@
// REQUIRES: x86-registered-target
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -r - 2>&1 | FileCheck %s
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
// RUN: llvm-readobj --relocations %t 2>&1 | FileCheck %s -DFILE=%t
// CHECK: error: '<stdin>': invalid packed relocation header
// CHECK: warning: '[[FILE]]': unable to read relocations from SHT_ANDROID_REL section with index 3: invalid packed relocation header
.section .rela.dyn, "a", @0x60000001
.ascii "APS9"

View File

@ -1,7 +1,8 @@
// REQUIRES: x86-registered-target
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -r - 2>&1 | FileCheck %s
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
// RUN: llvm-readobj --relocations %t 2>&1 | FileCheck %s -DFILE=%t
// CHECK: error: '<stdin>': malformed sleb128, extends past end
// CHECK: warning: '[[FILE]]': unable to read relocations from SHT_ANDROID_REL section with index 3: malformed sleb128, extends past end
.section .rela.dyn, "a", @0x60000001
.ascii "APS2"

View File

@ -1,7 +1,8 @@
// REQUIRES: x86-registered-target
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -r - 2>&1 | FileCheck %s
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
// RUN: llvm-readobj --relocations %t 2>&1 | FileCheck %s -DFILE=%t
// CHECK: error: '<stdin>': malformed sleb128, extends past end
// CHECK: warning: '[[FILE]]': unable to read relocations from SHT_ANDROID_REL section with index 3: malformed sleb128, extends past end
.section .rela.dyn, "a", @0x60000001
.ascii "APS2"

View File

@ -1,7 +1,8 @@
// REQUIRES: x86-registered-target
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -r - 2>&1 | FileCheck %s
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
// RUN: llvm-readobj --relocations %t 2>&1 | FileCheck %s -DFILE=%t
// CHECK: error: '<stdin>': malformed sleb128, extends past end
// CHECK: warning: '[[FILE]]': unable to read relocations from SHT_ANDROID_REL section with index 3: malformed sleb128, extends past end
.section .rela.dyn, "a", @0x60000001
.ascii "APS2"

View File

@ -1,7 +1,8 @@
// REQUIRES: x86-registered-target
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -r - 2>&1 | FileCheck %s
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
// RUN: llvm-readobj --relocations %t 2>&1 | FileCheck %s -DFILE=%t
// CHECK: error: '<stdin>': relocation group unexpectedly large
// CHECK: warning: '[[FILE]]': unable to read relocations from SHT_ANDROID_REL section with index 3: relocation group unexpectedly large
.section .rela.dyn, "a", @0x60000001
.ascii "APS2"

View File

@ -1,7 +1,8 @@
# 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 | llvm-readobj --relocations - | FileCheck --check-prefix=LLVM1 %s
# 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
@ -13,7 +14,7 @@
# LLVM1-NEXT: 0x119F R_X86_64_64 sym2 0xA
# LLVM1-NEXT: }
# RUN: yaml2obj --docnum=1 %s | llvm-readelf -relocations - | FileCheck --check-prefix=GNU1 %s
# 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
@ -32,18 +33,35 @@ FileHeader:
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .rela.dyn
Type: SHT_ANDROID_RELA
Flags: [ SHF_ALLOC ]
Link: .symtab
Content: 41505332088020020108800280010202088180808010818080802002080181808080100802818080802004020C7E048180808010088180808020
- Name: .rela.dyn
Type: SHT_ANDROID_RELA
Flags: [ SHF_ALLOC ]
Link: .symtab
Content: 41505332088020020108800280010202088180808010818080802002080181808080100802818080802004020C7E048180808010088180808020
ShOffset: [[SHOFFSET=<none>]]
Symbols:
- Name: sym1
Binding: STB_GLOBAL
- Name: sym2
Binding: STB_GLOBAL
# RUN: yaml2obj --docnum=2 %s | llvm-readobj --relocations - | FileCheck --check-prefix=LLVM2 %s
## 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: not 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: ]
## FIXME: GNU still reports an error before trying to dump relocations.
# BROKEN-RELA-GNU: error: '[[FILE]]': section [index 1] has a sh_offset (0xffffffff) + sh_size (0x3a) that is greater than the file size (0x238)
# 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
@ -57,7 +75,7 @@ Symbols:
# LLVM2-NEXT: 0xFF0 R_386_RELATIVE - 0x0
# LLVM2-NEXT: }
# RUN: yaml2obj --docnum=2 %s | llvm-readelf -relocations - | FileCheck --check-prefix=GNU2 %s
# 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
@ -78,17 +96,33 @@ FileHeader:
Type: ET_DYN
Machine: EM_386
Sections:
- Name: .rel.dyn
Type: SHT_ANDROID_REL
Flags: [ SHF_ALLOC ]
Link: .symtab
Content: 415053320A80200202088102830408037C08
- Name: .rel.dyn
Type: SHT_ANDROID_REL
Flags: [ SHF_ALLOC ]
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: not 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: ]
## FIXME: GNU still reports an error before trying to dump relocations.
# BROKEN-REL-GNU: error: '[[FILE]]': section [index 1] has a sh_offset (0xffffffff) + sh_size (0x12) that cannot be represented
# RUN: yaml2obj --docnum=3 %s | llvm-readobj --relocations - | FileCheck --check-prefix=LLVM3 %s
#
# LLVM3: Section (1) .rela.dyn {

View File

@ -125,10 +125,11 @@ Sections:
- Name: .text
Type: SHT_PROGBITS
Content: '00FFFFFFFF020000001234567890ABCDEF'
- Name: .rel.text
Type: SHT_REL
Info: .text
ShName: [[SHNAME=<none>]]
- Name: .rel.text
Type: SHT_REL
Info: .text
ShName: [[SHNAME=<none>]]
EntSize: [[ENTSIZEREL=<none>]]
Relocations:
- Symbol: rel_0
Type: R_X86_64_NONE
@ -141,10 +142,11 @@ Sections:
- Offset: 0x9
Symbol: rel_64
Type: R_X86_64_64
- Name: .rela.text
Type: SHT_RELA
Info: .text
ShName: [[SHNAME=<none>]]
- Name: .rela.text
Type: SHT_RELA
Info: .text
ShName: [[SHNAME=<none>]]
EntSize: [[ENTSIZERELA=<none>]]
Relocations:
- Symbol: rela_0
Type: R_X86_64_NONE
@ -194,6 +196,70 @@ Symbols:
Section: .text
Value: 0xFFFFFFFFFFFFFFFF
## Check we report a warning when we are unable to dump relocations for a section.
## Check we continue dumping other relocation sections if any.
## Case A: check the case when relocations can't be read from an SHT_REL section.
# RUN: yaml2obj %s --docnum=1 -DENTSIZEREL=1 -o %t.broken.rel
# RUN: llvm-readobj --relocations %t.broken.rel 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.broken.rel --check-prefix=BROKEN-REL-LLVM
# RUN: llvm-readelf --relocations %t.broken.rel 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.broken.rel --check-prefix=BROKEN-REL-GNU
# BROKEN-REL-LLVM: Relocations [
# BROKEN-REL-LLVM-NEXT: Section (2) .rel.text {
# BROKEN-REL-LLVM-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_REL section with index 2: section [index 2] has an invalid sh_entsize: 1
# BROKEN-REL-LLVM-NEXT: }
# BROKEN-REL-LLVM-NEXT: Section (3) .rela.text {
# BROKEN-REL-LLVM-NEXT: 0x0 R_X86_64_NONE rela_0 0x0
# BROKEN-REL-LLVM-NEXT: 0x1 R_X86_64_PC32 rela_neg 0xFFFFFFFFFFFFFFFF
# BROKEN-REL-LLVM-NEXT: 0x5 R_X86_64_PLT32 rela_pos 0x2
# BROKEN-REL-LLVM-NEXT: 0xFFFFFFFFFFFFFFFF R_X86_64_64 rela_minneg 0x8000000000000000
# BROKEN-REL-LLVM-NEXT: 0x9 R_X86_64_32S rela_maxpos 0x7FFFFFFFFFFFFFFF
# BROKEN-REL-LLVM-NEXT: }
# BROKEN-REL-LLVM-NEXT: ]
# BROKEN-REL-GNU: Relocation section '.rel.text' at offset 0x51 contains 64 entries:
# BROKEN-REL-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
# BROKEN-REL-GNU-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_REL section with index 2: section [index 2] has an invalid sh_entsize: 1
# BROKEN-REL-GNU: Relocation section '.rela.text' at offset 0x91 contains 5 entries:
# BROKEN-REL-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
# BROKEN-REL-GNU-NEXT: 0000000000000000 0000000500000000 R_X86_64_NONE 0000000000000000 rela_0 + 0
# BROKEN-REL-GNU-NEXT: 0000000000000001 0000000600000002 R_X86_64_PC32 0000000000000001 rela_neg - 1
# BROKEN-REL-GNU-NEXT: 0000000000000005 0000000700000004 R_X86_64_PLT32 0000000000000002 rela_pos + 2
# BROKEN-REL-GNU-NEXT: ffffffffffffffff 0000000800000001 R_X86_64_64 0000000000000003 rela_minneg - 8000000000000000
# BROKEN-REL-GNU-NEXT: 0000000000000009 000000090000000b R_X86_64_32S ffffffffffffffff rela_maxpos + 7fffffffffffffff
## Case B: check the case when relocations can't be read from an SHT_RELA section.
# RUN: yaml2obj %s --docnum=1 -DENTSIZERELA=1 -o %t.broken.rela
# RUN: llvm-readobj --relocations %t.broken.rela 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.broken.rela --check-prefix=BROKEN-RELA-LLVM
# RUN: llvm-readelf --relocations %t.broken.rela 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.broken.rela --check-prefix=BROKEN-RELA-GNU
# BROKEN-RELA-LLVM: Relocations [
# BROKEN-RELA-LLVM-NEXT: Section (2) .rel.text {
# BROKEN-RELA-LLVM-NEXT: 0x0 R_X86_64_NONE rel_0 0x0
# BROKEN-RELA-LLVM-NEXT: 0x1 R_X86_64_PC32 rel_neg 0x0
# BROKEN-RELA-LLVM-NEXT: 0x5 R_X86_64_PLT32 rel_pos 0x0
# BROKEN-RELA-LLVM-NEXT: 0x9 R_X86_64_64 rel_64 0x0
# BROKEN-RELA-LLVM-NEXT: }
# BROKEN-RELA-LLVM-NEXT: Section (3) .rela.text {
# BROKEN-RELA-LLVM-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_RELA section with index 3: section [index 3] has an invalid sh_entsize: 1
# BROKEN-RELA-LLVM-NEXT: }
# BROKEN-RELA-LLVM-NEXT: ]
# BROKEN-RELA-GNU: Relocation section '.rel.text' at offset 0x51 contains 4 entries:
# BROKEN-RELA-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
# BROKEN-RELA-GNU-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 rel_0
# BROKEN-RELA-GNU-NEXT: 0000000000000001 0000000200000002 R_X86_64_PC32 0000000000000001 rel_neg
# BROKEN-RELA-GNU-NEXT: 0000000000000005 0000000300000004 R_X86_64_PLT32 0000000000000002 rel_pos
# BROKEN-RELA-GNU-NEXT: 0000000000000009 0000000400000001 R_X86_64_64 ffffffffffffffff rel_64
# BROKEN-RELA-GNU-EMPTY:
# BROKEN-RELA-GNU-NEXT: Relocation section '.rela.text' at offset 0x91 contains 120 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_RELA section with index 3: section [index 3] has an invalid sh_entsize: 1
## Show that ELF32 is dumped correctly.
# RUN: yaml2obj %s --docnum=2 -o %t32
# RUN: llvm-readobj -r %t32 \

View File

@ -1,7 +1,7 @@
## This is a test to test how SHT_RELR sections are dumped.
# RUN: yaml2obj --docnum=1 %s \
# RUN: | llvm-readobj --relocations --raw-relr - \
# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-readobj --relocations --raw-relr %t1 \
# RUN: | FileCheck --check-prefix=RAW-LLVM1 %s
# RAW-LLVM1: Section (1) .relr.dyn {
# RAW-LLVM1-NEXT: 0x10D60
@ -11,9 +11,7 @@
# RAW-LLVM1-NEXT: 0xA700550400009
# RAW-LLVM1-NEXT: }
# RUN: yaml2obj --docnum=1 %s \
# RUN: | llvm-readobj --relocations - \
# RUN: | FileCheck --check-prefix=LLVM1 %s
# RUN: llvm-readobj --relocations %t1 | FileCheck --check-prefix=LLVM1 %s
# LLVM1: Section (1) .relr.dyn {
# LLVM1-NEXT: 0x10D60 R_X86_64_RELATIVE - 0x0
# LLVM1-NEXT: 0x10D68 R_X86_64_RELATIVE - 0x0
@ -38,8 +36,7 @@
# LLVM1-NEXT: 0x20390 R_X86_64_RELATIVE - 0x0
# LLVM1-NEXT: }
# RUN: yaml2obj --docnum=1 %s \
# RUN: | llvm-readelf -relocations -raw-relr - \
# RUN: llvm-readelf --relocations --raw-relr %t1 \
# RUN: | FileCheck --check-prefix=RAW-GNU1 %s
# RAW-GNU1: Relocation section '.relr.dyn' at offset 0x40 contains 5 entries:
# RAW-GNU1: 0000000000010d60
@ -48,9 +45,7 @@
# RAW-GNU1-NEXT: 00000000000f0501
# RAW-GNU1-NEXT: 000a700550400009
# RUN: yaml2obj --docnum=1 %s \
# RUN: | llvm-readelf -relocations - \
# RUN: | FileCheck --check-prefix=GNU1 %s
# RUN: llvm-readelf --relocations %t1 | FileCheck --check-prefix=GNU1 %s
# GNU1: Relocation section '.relr.dyn' at offset 0x40 contains 21 entries:
# GNU1: 0000000000010d60 0000000000000008 R_X86_64_RELATIVE
# GNU1-NEXT: 0000000000010d68 0000000000000008 R_X86_64_RELATIVE
@ -80,7 +75,6 @@ FileHeader:
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .relr.dyn
Type: SHT_RELR
@ -88,9 +82,9 @@ Sections:
Entries: [ 0x0000000000010D60, 0x0000000000000103, 0x0000000000020000,
0x00000000000F0501, 0x000A700550400009 ]
# RUN: yaml2obj --docnum=2 %s \
# RUN: | llvm-readobj --relocations --raw-relr - \
# RUN: | FileCheck --check-prefix=RAW-LLVM2 %s
# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-readobj --relocations --raw-relr %t2 | \
# RUN: FileCheck --check-prefix=RAW-LLVM2 %s
# RAW-LLVM2: Section (1) .relr.dyn {
# RAW-LLVM2-NEXT: 0x10D60
# RAW-LLVM2-NEXT: 0x103
@ -99,9 +93,7 @@ Sections:
# RAW-LLVM2-NEXT: 0x50400009
# RAW-LLVM2-NEXT: }
# RUN: yaml2obj --docnum=2 %s \
# RUN: | llvm-readobj --relocations - \
# RUN: | FileCheck --check-prefix=LLVM2 %s
# RUN: llvm-readobj --relocations %t2 | FileCheck --check-prefix=LLVM2 %s
# LLVM2: Section (1) .relr.dyn {
# LLVM2-NEXT: 0x10D60 R_386_RELATIVE - 0x0
# LLVM2-NEXT: 0x10D64 R_386_RELATIVE - 0x0
@ -119,9 +111,8 @@ Sections:
# LLVM2-NEXT: 0x200F4 R_386_RELATIVE - 0x0
# LLVM2-NEXT: }
# RUN: yaml2obj --docnum=2 %s \
# RUN: | llvm-readelf -relocations -raw-relr - \
# RUN: | FileCheck --check-prefix=RAW-GNU2 %s
# RUN: llvm-readelf --relocations --raw-relr %t2 | \
# RUN: FileCheck --check-prefix=RAW-GNU2 %s
# RAW-GNU2: Relocation section '.relr.dyn' at offset 0x34 contains 5 entries:
# RAW-GNU2: 00010d60
# RAW-GNU2-NEXT: 00000103
@ -129,9 +120,7 @@ Sections:
# RAW-GNU2-NEXT: 000f0501
# RAW-GNU2-NEXT: 50400009
# RUN: yaml2obj --docnum=2 %s \
# RUN: | llvm-readelf -relocations - \
# RUN: | FileCheck --check-prefix=GNU2 %s
# RUN: llvm-readelf --relocations %t2 | FileCheck --check-prefix=GNU2 %s
# GNU2: Relocation section '.relr.dyn' at offset 0x34 contains 14 entries:
# GNU2: 00010d60 00000008 R_386_RELATIVE
# GNU2-NEXT: 00010d64 00000008 R_386_RELATIVE
@ -154,10 +143,39 @@ FileHeader:
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_386
Sections:
- Name: .relr.dyn
Type: SHT_RELR
Flags: [ SHF_ALLOC ]
- Name: .relr.dyn
Type: SHT_RELR
Flags: [ SHF_ALLOC ]
Entries: [ 0x00010D60, 0x00000103, 0x00020000,
0x000F0501, 0x50400009 ]
EntSize: [[ENTSIZE=<none>]]
ShType: [[SHTYPE=<none>]]
## Check we report a warning when we are unable to dump relocations
## for a SHT_RELR/SHT_ANDROID_RELR section.
## Case A: check the case when relocations can't be read from an SHT_RELR section.
# RUN: yaml2obj --docnum=2 -DENTSIZE=1 %s -o %t2.broken
# RUN: llvm-readobj --relocations %t2.broken 2>&1 | \
# RUN: FileCheck -DFILE=%t2.broken --check-prefix=BROKEN-LLVM %s -DSECNAME=SHT_RELR
# RUN: not llvm-readelf --relocations %t2.broken 2>&1 | \
# RUN: FileCheck -DFILE=%t2.broken --check-prefix=BROKEN-GNU %s
# BROKEN-LLVM: Relocations [
# BROKEN-LLVM-NEXT: Section (1) .relr.dyn {
# BROKEN-LLVM-NEXT: warning: '[[FILE]]': unable to read relocations from [[SECNAME]] section with index 1: section [index 1] has an invalid sh_entsize: 1
# BROKEN-LLVM-NEXT: }
# BROKEN-LLVM-NEXT: ]
## FIXME: GNU still reports an error before trying to dump relocations.
# BROKEN-GNU: error: '[[FILE]]': section [index 1] has an invalid sh_entsize: 1
## Case B: check the case when relocations can't be read from an SHT_ANDROID_RELR section.
## SHT_ANDROID_RELR = 0x6fffff00.
# RUN: yaml2obj --docnum=2 -DENTSIZE=1 -DSHTYPE=0x6fffff00 %s -o %t2.broken.android
# RUN: llvm-readobj --relocations %t2.broken.android 2>&1 | \
# RUN: FileCheck -DFILE=%t2.broken.android --check-prefix=BROKEN-LLVM %s -DSECNAME=SHT_ANDROID_RELR
# RUN: not llvm-readelf --relocations %t2.broken.android 2>&1 | \
# RUN: FileCheck -DFILE=%t2.broken.android --check-prefix=BROKEN-GNU %s

View File

@ -5524,33 +5524,54 @@ void DumpStyle<ELFT>::printRelocationsHelper(const ELFFile<ELFT> *Obj,
unsigned SecNdx = &Sec - &cantFail(Obj->sections()).front();
unsigned RelNdx = 0;
auto Warn = [&](Error &&E) {
this->reportUniqueWarning(createError("unable to read relocations from " +
describe(Obj, Sec) + ": " +
toString(std::move(E))));
};
switch (Sec.sh_type) {
case ELF::SHT_REL:
for (const Elf_Rel &R : unwrapOrError(this->FileName, Obj->rels(&Sec)))
printRelReloc(Obj, SecNdx, SymTab, R, ++RelNdx);
if (Expected<Elf_Rel_Range> RangeOrErr = Obj->rels(&Sec)) {
for (const Elf_Rel &R : *RangeOrErr)
printRelReloc(Obj, SecNdx, SymTab, R, ++RelNdx);
} else {
Warn(RangeOrErr.takeError());
}
break;
case ELF::SHT_RELA:
for (const Elf_Rela &R : unwrapOrError(this->FileName, Obj->relas(&Sec)))
printRelaReloc(Obj, SecNdx, SymTab, R, ++RelNdx);
if (Expected<Elf_Rela_Range> RangeOrErr = Obj->relas(&Sec)) {
for (const Elf_Rela &R : *RangeOrErr)
printRelaReloc(Obj, SecNdx, SymTab, R, ++RelNdx);
} else {
Warn(RangeOrErr.takeError());
}
break;
case ELF::SHT_RELR:
case ELF::SHT_ANDROID_RELR: {
Elf_Relr_Range Relrs = unwrapOrError(this->FileName, Obj->relrs(&Sec));
Expected<Elf_Relr_Range> RangeOrErr = Obj->relrs(&Sec);
if (!RangeOrErr) {
Warn(RangeOrErr.takeError());
break;
}
if (opts::RawRelr) {
for (const Elf_Relr &R : Relrs)
for (const Elf_Relr &R : *RangeOrErr)
printRelrReloc(R);
break;
}
for (const Elf_Rel &R : Obj->decode_relrs(Relrs))
for (const Elf_Rel &R : Obj->decode_relrs(*RangeOrErr))
printRelReloc(Obj, SecNdx, SymTab, R, ++RelNdx);
break;
}
case ELF::SHT_ANDROID_REL:
case ELF::SHT_ANDROID_RELA:
for (const Elf_Rela &R :
unwrapOrError(this->FileName, Obj->android_relas(&Sec)))
printRelaReloc(Obj, SecNdx, SymTab, R, ++RelNdx);
if (Expected<std::vector<Elf_Rela>> RelasOrErr = Obj->android_relas(&Sec)) {
for (const Elf_Rela &R : *RelasOrErr)
printRelaReloc(Obj, SecNdx, SymTab, R, ++RelNdx);
} else {
Warn(RelasOrErr.takeError());
}
break;
}
}