[PATCH] D90903: [llvm-readelf/obj] - Allow dumping of ELF header even if some elements are corrupt.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 5 22:47:22 PST 2020


grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: rupprecht, hiraditya, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
grimar requested review of this revision.

For creating `ELFObjectFile` instances we have the factory method
`ELFObjectFile<ELFT>::create(MemoryBufferRef Object)`.

The problem of this method is that it scans the section header to locate some sections.
When a file is truncated or has broken fields in the ELF header, this approach does
not allow us to create the `ELFObjectFile` and dump the ELF header.

This is https://bugs.llvm.org/show_bug.cgi?id=40804

This patch suggests a solution - it allows to delay scaning sections in the
`ELFObjectFile<ELFT>::create`. It now allows user code to call an object
initialization (`initContent()`) later. With that it is possible,
for example, for dumpers just to dump the file header and exit.
By default initialization is still performed as before, what helps to keep
the logic of existent callers untouched.

I've experimented with different approaches when worked on this patch.
I think this approach is better than doing initialization of sections (i.e. scan of them)
on demand, because normally users of `ELFObjectFile` API expect to work with a valid object.
In most cases when a section header table can't be read (because of an error), we don't
have to continue to work with object. So we probably don't need to implement a more complex API.


https://reviews.llvm.org/D90903

Files:
  llvm/include/llvm/Object/Binary.h
  llvm/include/llvm/Object/ELFObjectFile.h
  llvm/include/llvm/Object/ObjectFile.h
  llvm/include/llvm/Object/SymbolicFile.h
  llvm/lib/Object/Binary.cpp
  llvm/lib/Object/ELFObjectFile.cpp
  llvm/lib/Object/ObjectFile.cpp
  llvm/lib/Object/SymbolicFile.cpp
  llvm/test/Object/invalid.test
  llvm/test/tools/llvm-readobj/ELF/file-headers.test
  llvm/test/tools/yaml2obj/ELF/section-headers.yaml
  llvm/tools/llvm-readobj/ELFDumper.cpp
  llvm/tools/llvm-readobj/ObjDumper.h
  llvm/tools/llvm-readobj/llvm-readobj.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90903.303335.patch
Type: text/x-patch
Size: 26358 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201106/301a24fc/attachment.bin>


More information about the llvm-commits mailing list