From 82ede2f136cdadfb598437e20a9826a71707d674 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 21 Sep 2015 19:17:18 +0000 Subject: [PATCH] Avoid SEGFAULT if a requested symbol section is absent. Patch by Igor Kudrin! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248194 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Object/readobj-absent.test | 2 ++ tools/llvm-readobj/ELFDumper.cpp | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 test/Object/readobj-absent.test diff --git a/test/Object/readobj-absent.test b/test/Object/readobj-absent.test new file mode 100644 index 00000000000..0968f3c3102 --- /dev/null +++ b/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 diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 31e200e436c..99311634403 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -1152,6 +1152,8 @@ void ELFDumper::printRelocation(Elf_Rela Rel, const Elf_Shdr *SymTab) { template void ELFDumper::printSymbolsHelper(bool IsDynamic) { const Elf_Shdr *Symtab = (IsDynamic) ? DotDynSymSec : DotSymtabSec; + if (!Symtab) + return; ErrorOr StrTableOrErr = Obj->getStringTableForSymtab(*Symtab); error(StrTableOrErr.getError()); StringRef StrTable = *StrTableOrErr;