[PATCH] D13024: [llvm-readobj] Avoid SEGFAULT if a requested symbol section is absent

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 08:39:53 PDT 2015

ikudrin created this revision.
ikudrin added a reviewer: rafael.
ikudrin added a subscriber: llvm-commits.

Some files can have no dynamic symbols section. Others can even have no regular symbol section. The tool shouldn't crash if it's requested to show such sections.



Index: tools/llvm-readobj/ELFDumper.cpp
--- tools/llvm-readobj/ELFDumper.cpp
+++ tools/llvm-readobj/ELFDumper.cpp
@@ -1152,6 +1152,8 @@
 template<class ELFT>
 void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic) {
   const Elf_Shdr *Symtab = (IsDynamic) ? DotDynSymSec : DotSymtabSec;
+  if (!Symtab)
+    return;
   ErrorOr<StringRef> StrTableOrErr = Obj->getStringTableForSymtab(*Symtab);
   StringRef StrTable = *StrTableOrErr;
Index: test/Object/readobj-absent.test
--- /dev/null
+++ test/Object/readobj-absent.test
@@ -0,0 +1,2 @@
+// Don't crash if required information is absent
+RUN: llvm-readobj -dyn-symbols %p/Inputs/trivial-object-test.elf-x86-64

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13024.35259.patch
Type: text/x-patch
Size: 835 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150921/849b9fcd/attachment.bin>

More information about the llvm-commits mailing list