Index: llvm/test/tools/llvm-objdump/X86/Inputs/bss.c =================================================================== --- /dev/null +++ llvm/test/tools/llvm-objdump/X86/Inputs/bss.c @@ -0,0 +1,8 @@ + +int a[100000]; + +int +main() { + return 0; +} + Index: llvm/test/tools/llvm-objdump/X86/bss.test =================================================================== --- /dev/null +++ llvm/test/tools/llvm-objdump/X86/bss.test @@ -0,0 +1,8 @@ +# Check that when BSS is larger than the file llvm-objdump doesn't +# assert with an unexpected end of file error. + +# To rebuild the input: clang bss.c -o bss.exe.elf-x86_64 + +# RUN: llvm-objdump -D %p/Inputs/bss.exe.elf-x86_64 | FileCheck %s + +# CHECK-NOT: The end of the file was unexpectedly encountered Index: llvm/tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- llvm/tools/llvm-objdump/llvm-objdump.cpp +++ llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1223,8 +1223,10 @@ SmallString<40> Comments; raw_svector_ostream CommentStream(Comments); - ArrayRef Bytes = arrayRefFromStringRef( - unwrapOrError(Section.getContents(), Obj->getFileName())); + ArrayRef Bytes = + Section.isBSS() ? 0 + : arrayRefFromStringRef(unwrapOrError( + Section.getContents(), Obj->getFileName())); uint64_t VMAAdjustment = 0; if (shouldAdjustVA(Section))