[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
Mon Oct 21 12:22:37 PDT 2019


sidneym updated this revision to Diff 225935.
sidneym added a comment.

Changed getContents to return a zero-length array when the section type was NOBITS.

I looked at the other locations in that file and they all seemed to be set up to avoid dumping bss but not the potential of a non-bss/nobits section.  Adding this to getContents should address those sections and usages by other tools.

I've never used yaml before so this might not be the perfect test but it sure feels better than adding binaries to the test tree.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69192/new/

https://reviews.llvm.org/D69192

Files:
  llvm/include/llvm/Object/ELFObjectFile.h
  llvm/test/tools/llvm-objdump/X86/bss.test


Index: llvm/test/tools/llvm-objdump/X86/bss.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/X86/bss.test
@@ -0,0 +1,25 @@
+## Check that when BSS is larger than the file llvm-objdump doesn't
+## assert with an unexpected end of file error.
+# RUN: yaml2obj %s | llvm-objdump -D - | FileCheck %s
+# CHECK-NOT: The end of the file was unexpectedly encountered
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_EXEC
+  Machine:         EM_X86_64
+  Entry:           0x00000000004003E0
+Sections:
+  - Name:            .bss
+    Type:            SHT_NOBITS
+    Flags:           [ SHF_WRITE, SHF_ALLOC ]
+    Address:         0x0000000000601040
+    AddressAlign:    0x0000000000000010
+    Size:            0x0000000000001000
+DynamicSymbols:
+  - Name:            __libc_start_main
+    Type:            STT_FUNC
+    Binding:         STB_GLOBAL
+  - Name:            __gmon_start__
+    Binding:         STB_WEAK
+...
Index: llvm/include/llvm/Object/ELFObjectFile.h
===================================================================
--- llvm/include/llvm/Object/ELFObjectFile.h
+++ llvm/include/llvm/Object/ELFObjectFile.h
@@ -722,6 +722,8 @@
 Expected<ArrayRef<uint8_t>>
 ELFObjectFile<ELFT>::getSectionContents(DataRefImpl Sec) const {
   const Elf_Shdr *EShdr = getSection(Sec);
+  if (EShdr->sh_type == ELF::SHT_NOBITS)
+    return makeArrayRef((const uint8_t *)base() + EShdr->sh_offset, 0);
   if (std::error_code EC =
           checkOffset(getMemoryBufferRef(),
                       (uintptr_t)base() + EShdr->sh_offset, EShdr->sh_size))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69192.225935.patch
Type: text/x-patch
Size: 1679 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191021/d97447f3/attachment.bin>


More information about the llvm-commits mailing list