diff --git a/llvm/test/tools/obj2yaml/Inputs/crt1.o b/llvm/test/tools/obj2yaml/Inputs/crt1.o new file mode 100755 index 000000000000..2b000ab9ae83 Binary files /dev/null and b/llvm/test/tools/obj2yaml/Inputs/crt1.o differ diff --git a/llvm/test/tools/obj2yaml/missing_symtab.test b/llvm/test/tools/obj2yaml/missing_symtab.test new file mode 100644 index 000000000000..b992931a0db9 --- /dev/null +++ b/llvm/test/tools/obj2yaml/missing_symtab.test @@ -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: diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp index 8997a5c4211b..8c94843788f6 100644 --- a/llvm/tools/obj2yaml/elf2yaml.cpp +++ b/llvm/tools/obj2yaml/elf2yaml.cpp @@ -188,6 +188,8 @@ template ErrorOr ELFDumper::dump() { } // Dump symbols + if (!Symtab) + return Y.release(); // if the symbol table is missing return early auto StrTableOrErr = Obj.getStringTableForSymtab(*Symtab); if (!StrTableOrErr) return errorToErrorCode(StrTableOrErr.takeError());