diff options
author | George Rimar <grimar@accesssoftek.com> | 2019-10-21 11:06:38 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2019-10-21 11:06:38 +0000 |
commit | cc870b19ca17467315a5da769d680c24f3153bc8 (patch) | |
tree | 4efb0124c2374a682c395e4c0183f4f2a8fa1dc3 /test | |
parent | f69d71733b06ed87cfa874ac5f9613458ce8c0e0 (diff) |
[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
Diffstat (limited to 'test')
-rw-r--r-- | test/tools/llvm-cxxdump/broken-reloc-sec.test | 20 | ||||
-rw-r--r-- | test/tools/llvm-dwarfdump/elf-broken-reloc-target.yaml | 20 | ||||
-rw-r--r-- | test/tools/llvm-objdump/X86/elf-disassemble-relocs.test | 25 | ||||
-rw-r--r-- | test/tools/llvm-objdump/relocations-elf.test | 6 | ||||
-rw-r--r-- | test/tools/llvm-readobj/stack-sizes.test | 23 |
5 files changed, 89 insertions, 5 deletions
diff --git a/test/tools/llvm-cxxdump/broken-reloc-sec.test b/test/tools/llvm-cxxdump/broken-reloc-sec.test new file mode 100644 index 00000000000..c38786c9f7a --- /dev/null +++ b/test/tools/llvm-cxxdump/broken-reloc-sec.test @@ -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: [] diff --git a/test/tools/llvm-dwarfdump/elf-broken-reloc-target.yaml b/test/tools/llvm-dwarfdump/elf-broken-reloc-target.yaml new file mode 100644 index 00000000000..925d76e32d6 --- /dev/null +++ b/test/tools/llvm-dwarfdump/elf-broken-reloc-target.yaml @@ -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: [] diff --git a/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test b/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test index 04390eb4e30..8450b4e1f39 100644 --- a/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test +++ b/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test @@ -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: [] diff --git a/test/tools/llvm-objdump/relocations-elf.test b/test/tools/llvm-objdump/relocations-elf.test index b79ab9eee04..751dfbb5807 100644 --- a/test/tools/llvm-objdump/relocations-elf.test +++ b/test/tools/llvm-objdump/relocations-elf.test @@ -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 diff --git a/test/tools/llvm-readobj/stack-sizes.test b/test/tools/llvm-readobj/stack-sizes.test index 8786ec66535..3d660fcd256 100644 --- a/test/tools/llvm-readobj/stack-sizes.test +++ b/test/tools/llvm-readobj/stack-sizes.test @@ -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: [] |