[PATCH] D69192: llvm-objdump can error out with an unexpected EOF error if .bss is larger than the file being dumped.
Sid Manning via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 18 13:46:04 PDT 2019
sidneym created this revision.
sidneym added reviewers: grimar, MaskRay, rupprecht, bcain.
Herald added subscribers: llvm-commits, seiya.
Herald added a project: LLVM.
llvm-objdump -D this file:
int a[100000];
int
main() {
return 0;
}
Will produce an error, "The end of the file was unexpectedly encountered"
This happens because of a check in Binary.h checkOffset. (Addr + Size > M.getBufferEnd()).
Since the .bss section doesn't occupy space in the file this check fails when the above program is dumped with -D.
This change avoids the reading .bss sections.
I added a test for X86_64 but this isn't target specific.
Repository:
rL LLVM
https://reviews.llvm.org/D69192
Files:
llvm/test/tools/llvm-objdump/X86/Inputs/bss.c
llvm/test/tools/llvm-objdump/X86/Inputs/bss.exe.elf-x86_64
llvm/test/tools/llvm-objdump/X86/bss.test
llvm/tools/llvm-objdump/llvm-objdump.cpp
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<uint8_t> Bytes = arrayRefFromStringRef(
- unwrapOrError(Section.getContents(), Obj->getFileName()));
+ ArrayRef<uint8_t> Bytes =
+ Section.isBSS() ? 0
+ : arrayRefFromStringRef(unwrapOrError(
+ Section.getContents(), Obj->getFileName()));
uint64_t VMAAdjustment = 0;
if (shouldAdjustVA(Section))
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/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;
+}
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69192.225683.patch
Type: text/x-patch
Size: 1462 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191018/ff3aa2bf/attachment.bin>
More information about the llvm-commits
mailing list