mirror of
https://github.com/RPCS3/llvm.git
synced 2026-06-30 21:08:10 -04:00
[llvm/Object] - Make ELFObjectFile::getRelocatedSection return Expected<section_iterator>
It returns just a section_iterator currently and have a report_fatal_error call inside. This change adds a way to return errors and handle them on caller sides. The patch also changes/improves current users and adds test cases. Differential revision: https://reviews.llvm.org/D69167 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375408 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
## Check we report an error when trying to dump an object
|
||||
## which has a relocation section that has a broken sh_info
|
||||
## field, which is larger than the number of sections.
|
||||
|
||||
# RUN: yaml2obj %s -o %t
|
||||
# RUN: not llvm-cxxdump %t 2>&1 | FileCheck %s
|
||||
# CHECK: error: reading file: invalid section index: 255
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_REL
|
||||
Machine: EM_X86_64
|
||||
Sections:
|
||||
- Name: .rela.foo
|
||||
Type: SHT_RELA
|
||||
Link: 0
|
||||
Info: 0xFF
|
||||
Relocations: []
|
||||
@@ -0,0 +1,20 @@
|
||||
## Check we report an error if the relocated section identified by the
|
||||
## sh_info field of a relocation section is invalid.
|
||||
|
||||
# RUN: yaml2obj %s -o %t
|
||||
# RUN: llvm-dwarfdump %t 2>&1 | FileCheck %s -DFILE=%t --check-prefix=ERR
|
||||
|
||||
# ERR: error: failed to get relocated section: invalid section index: 255
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_REL
|
||||
Machine: EM_X86_64
|
||||
Sections:
|
||||
- Name: .rela.debug_info
|
||||
Type: SHT_RELA
|
||||
Link: 0
|
||||
Info: 0xFF
|
||||
Relocations: []
|
||||
@@ -1,8 +1,8 @@
|
||||
## Show that --disassemble + --reloc prints relocations inline and does not dump
|
||||
## the relocation sections.
|
||||
|
||||
# RUN: yaml2obj %s -o %t.o
|
||||
# RUN: llvm-objdump %t.o -d -r | FileCheck %s --implicit-check-not="RELOCATION RECORDS"
|
||||
# RUN: yaml2obj %s --docnum=1 -o %t1.o
|
||||
# RUN: llvm-objdump %t1.o -d -r | FileCheck %s --implicit-check-not="RELOCATION RECORDS"
|
||||
|
||||
# CHECK: 0: e8 00 00 00 00 callq 0 <.text+0x5>
|
||||
# CHECK-NEXT: 0000000000000001: R_X86_64_PC32 foo-4
|
||||
@@ -40,3 +40,24 @@ Sections:
|
||||
Symbols:
|
||||
- Name: foo
|
||||
- Name: bar
|
||||
|
||||
## Check we report an error if the relocated section identified by the
|
||||
## sh_info field of a relocation section is invalid.
|
||||
|
||||
# RUN: yaml2obj %s --docnum=2 -o %t2.o
|
||||
# RUN: not llvm-objdump %t2.o --disassemble --reloc 2>&1 | FileCheck %s -DFILE=%t2.o --check-prefix=ERR
|
||||
|
||||
# ERR: error: '[[FILE]]': section (1): failed to get a relocated section: invalid section index: 255
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_REL
|
||||
Machine: EM_X86_64
|
||||
Sections:
|
||||
- Name: .rela.debug_info
|
||||
Type: SHT_RELA
|
||||
Link: 0
|
||||
Info: 0xFF
|
||||
Relocations: []
|
||||
|
||||
@@ -74,8 +74,8 @@ Symbols:
|
||||
## Check we report an error if the relocated section identified by the
|
||||
## sh_info field of a relocation section is invalid.
|
||||
# RUN: yaml2obj --docnum=2 %s > %t2
|
||||
# RUN: not llvm-objdump --reloc %t2 2>&1 | FileCheck %s --check-prefix=ERR
|
||||
# ERR: LLVM ERROR: Invalid data was encountered while parsing the file
|
||||
# RUN: not llvm-objdump --reloc %t2 2>&1 | FileCheck %s -DFILE=%t2 --check-prefix=ERR
|
||||
# ERR: error: '[[FILE]]': section (1): unable to get a relocation target: invalid section index: 255
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
@@ -86,7 +86,7 @@ FileHeader:
|
||||
Sections:
|
||||
- Name: .rela.foo
|
||||
Type: SHT_RELA
|
||||
Info: 0x255
|
||||
Info: 0xFF
|
||||
Relocations:
|
||||
- Offset: 0x1
|
||||
Type: R_X86_64_NONE
|
||||
|
||||
@@ -641,3 +641,26 @@ Sections:
|
||||
Relocations:
|
||||
- Offset: 0
|
||||
Type: R_X86_64_64
|
||||
|
||||
## Check we report an error when dumping stack sizes if the relocated section
|
||||
## identified by the sh_info field is invalid. Here sh_info value is larger than
|
||||
## the number of sections.
|
||||
|
||||
# RUN: yaml2obj --docnum=13 %s > %t18
|
||||
# RUN: not llvm-readelf --stack-sizes %t18 2>&1 | FileCheck %s -DFILE=%t18 --check-prefix=INVALID-TARGET
|
||||
# RUN: not llvm-readobj --stack-sizes %t18 2>&1 | FileCheck %s -DFILE=%t18 --check-prefix=INVALID-TARGET
|
||||
|
||||
# INVALID-TARGET: error: '[[FILE]]': .rela.stack_sizes: failed to get a relocated section: invalid section index: 255
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS32
|
||||
Data: ELFDATA2MSB
|
||||
Type: ET_REL
|
||||
Machine: EM_X86_64
|
||||
Sections:
|
||||
- Name: .rela.stack_sizes
|
||||
Type: SHT_RELA
|
||||
Link: 0
|
||||
Info: 0xFF
|
||||
Relocations: []
|
||||
|
||||
Reference in New Issue
Block a user