Index: test/tools/llvm-objdump/non-archive-object.test =================================================================== --- test/tools/llvm-objdump/non-archive-object.test +++ test/tools/llvm-objdump/non-archive-object.test @@ -0,0 +1,28 @@ +# RUN: yaml2obj %s > %t +# RUN: llvm-objdump --archive-headers %t > %t.out1 +# RUN: llvm-objdump -a %t > %t.out2 +# RUN: cmp %t.out1 %t.out2 +# RUN: FileCheck %s --input-file=%t.out1 + +# If this test not crashed, then this test passed. +# CHECK: file format ELF64-x86-64 + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000010 + Size: 64 + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000010 + Content: "01234567" + Size: 4 + Index: tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- tools/llvm-objdump/llvm-objdump.cpp +++ tools/llvm-objdump/llvm-objdump.cpp @@ -2228,8 +2228,9 @@ << "\n"; } -static void printArchiveChild(StringRef Filename, const Archive::Child &C) { - Expected ModeOrErr = C.getAccessMode(); +static void printArchiveChild(StringRef Filename, const Archive::Child *C) { + if (C == nullptr) return; + Expected ModeOrErr = C->getAccessMode(); if (!ModeOrErr) { errs() << "ill-formed archive entry.\n"; consumeError(ModeOrErr.takeError()); @@ -2248,24 +2249,24 @@ outs() << " "; - Expected UIDOrErr = C.getUID(); + Expected UIDOrErr = C->getUID(); if (!UIDOrErr) report_error(Filename, UIDOrErr.takeError()); unsigned UID = UIDOrErr.get(); outs() << format("%d/", UID); - Expected GIDOrErr = C.getGID(); + Expected GIDOrErr = C->getGID(); if (!GIDOrErr) report_error(Filename, GIDOrErr.takeError()); unsigned GID = GIDOrErr.get(); outs() << format("%-d ", GID); - Expected Size = C.getRawSize(); + Expected Size = C->getRawSize(); if (!Size) report_error(Filename, Size.takeError()); outs() << format("%6" PRId64, Size.get()) << " "; - StringRef RawLastModified = C.getRawLastModified(); + StringRef RawLastModified = C->getRawLastModified(); unsigned Seconds; if (RawLastModified.getAsInteger(10, Seconds)) outs() << "(date: \"" << RawLastModified @@ -2279,10 +2280,10 @@ } StringRef Name = ""; - Expected NameOrErr = C.getName(); + Expected NameOrErr = C->getName(); if (!NameOrErr) { consumeError(NameOrErr.takeError()); - Expected RawNameOrErr = C.getRawName(); + Expected RawNameOrErr = C->getRawName(); if (!RawNameOrErr) report_error(Filename, NameOrErr.takeError()); Name = RawNameOrErr.get(); @@ -2306,7 +2307,7 @@ } if (ArchiveHeaders && !MachOOpt) - printArchiveChild(a->getFileName(), *c); + printArchiveChild(ArchiveName, c); if (Disassemble) DisassembleObject(o, Relocations); if (Relocations && !Disassemble) @@ -2360,7 +2361,7 @@ << "\n\n"; if (ArchiveHeaders && !MachOOpt) - printArchiveChild(A->getFileName(), *C); + printArchiveChild(ArchiveName, C); if (SymbolTable) printCOFFSymbolTable(I); }