[obj2yaml] Don't crash for input files without symbol table

Summary: Previously we would dereference Symtab without checking for null.

Reviewers: davide, atanasyan, rafael

Reviewed By: davide, atanasyan

Differential Revision: https://reviews.llvm.org/D38080

llvm-svn: 313970
This commit is contained in:
Alexander Richardson 2017-09-22 09:30:40 +00:00
parent 8f719bacd0
commit c46750ef42
3 changed files with 7 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,5 @@
# RUN: obj2yaml %S/Inputs/crt1.o | FileCheck %s
# test that we don't crash when passed object files without a symbol table
# CHECK-LABEL: FileHeader:
# CHECK-LABEL: Sections:
# CHECK-LABEL: Symbols:

View File

@ -188,6 +188,8 @@ template <class ELFT> ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
} }
// Dump symbols // Dump symbols
if (!Symtab)
return Y.release(); // if the symbol table is missing return early
auto StrTableOrErr = Obj.getStringTableForSymtab(*Symtab); auto StrTableOrErr = Obj.getStringTableForSymtab(*Symtab);
if (!StrTableOrErr) if (!StrTableOrErr)
return errorToErrorCode(StrTableOrErr.takeError()); return errorToErrorCode(StrTableOrErr.takeError());