[PATCH] D67962: [llvm-readobj] - Don't crash when dumping .stack_sizes and unable to find a relocation resolver.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 24 06:29:38 PDT 2019
grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: seiya, rupprecht.
The crash might happen when we have either a broken or unsupported object
and trying to resolve relocations when dumping the .stack_sizes section.
For the test case I used a 32-bits ELF header and a 64-bit relocation.
In this case a null pointer is returned by the code instead of the relocation
resolver function and then we crash.
https://reviews.llvm.org/D67962
Files:
test/tools/llvm-readobj/stack-sizes.test
tools/llvm-readobj/ELFDumper.cpp
Index: tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- tools/llvm-readobj/ELFDumper.cpp
+++ tools/llvm-readobj/ELFDumper.cpp
@@ -4935,7 +4935,7 @@
auto Contents = unwrapOrError(this->FileName, StackSizesSec.getContents());
DataExtractor Data(Contents, Obj->isLittleEndian(), sizeof(Elf_Addr));
for (const RelocationRef &Reloc : RelocSec.relocations()) {
- if (!IsSupportedFn(Reloc.getType()))
+ if (!IsSupportedFn || !IsSupportedFn(Reloc.getType()))
reportError(createStringError(
object_error::parse_failed,
"unsupported relocation type in section %s: %s",
Index: test/tools/llvm-readobj/stack-sizes.test
===================================================================
--- test/tools/llvm-readobj/stack-sizes.test
+++ test/tools/llvm-readobj/stack-sizes.test
@@ -596,3 +596,29 @@
Value: 0x10
Type: STT_FUNC
Binding: STB_GLOBAL
+
+## Check that we report an error when we find a relocation that has a valid type, but
+## cannot be resolved. Here we have a 32-bit object, but 64-bit relocation.
+
+# RUN: yaml2obj --docnum=12 %s > %t17
+# RUN: not llvm-readelf --stack-sizes %t17 2>&1 | FileCheck %s -DFILE=%t17 --check-prefix=UNSUPPRELOC2
+# RUN: not llvm-readobj --stack-sizes %t17 2>&1 | FileCheck %s -DFILE=%t17 --check-prefix=UNSUPPRELOC2
+
+# UNSUPPRELOC2: error: '[[FILE]]': unsupported relocation type in section .rela.stack_sizes: R_X86_64_64
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .stack_sizes
+ Type: SHT_PROGBITS
+ Content: "00"
+ - Name: .rela.stack_sizes
+ Type: SHT_RELA
+ Info: .stack_sizes
+ Relocations:
+ - Offset: 0
+ Type: R_X86_64_64
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67962.221527.patch
Type: text/x-patch
Size: 1846 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190924/8cdac41f/attachment.bin>
More information about the llvm-commits
mailing list