diff options
author | Pavel Labath <labath@google.com> | 2017-01-31 23:09:46 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2017-01-31 23:09:46 +0000 |
commit | 23ccc29197fdac683e8744f7a9bc05766e6099bb (patch) | |
tree | c11ee2f9f0a15f0b6e1b4e10fc850d7436082685 /lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h | |
parent | 06fcea4cd92ecedb8ddcebbe80650d2e92baf2db (diff) | |
download | bcm5719-llvm-23ccc29197fdac683e8744f7a9bc05766e6099bb.tar.gz bcm5719-llvm-23ccc29197fdac683e8744f7a9bc05766e6099bb.zip |
Open ELF core dumps with more than 64K sections
Summary:
Problem:
There are three filelds in the ELF header - e_phnum, e_shnum, and e_shstrndx -
that could be bigger than 64K and therefore do not fit in 16 bits reserved for
them in the header. If this happens, pretty often there is a special section at
index 0 which contains their real values for these fields in the section header
in the fields sh_info, sh_size, and sh_link respectively.
Fix:
- Rename original fields in the header declaration. We want to have them around
just in case.
- Reintroduce these fields as 32-bit members at the end of the header. By default
they are initialized from the header in Parse() method.
- In Parse(), detect the situation when the header might have been extended into
section info #0 and try to read it from the same data source.
- ObjectFileELF::GetModuleSpecifications accesses some of these fields but the
original parse uses too small data source. Re-parse the header if necessary
using bigger data source.
- ProcessElfCore::CreateInstance uses header with potentially sentinel values,
but it does not access these fields, so a comment here is enough.
Reviewers: labath
Reviewed By: labath
Subscribers: davidb, lldb-commits, mgorny
Differential Revision: https://reviews.llvm.org/D29095
Author: Eugene Birukov <eugenebi@hotmail.com>
llvm-svn: 293714
Diffstat (limited to 'lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h')
-rw-r--r-- | lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h b/lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h index 71b200f1c16..e6738a1ecb2 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h +++ b/lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h @@ -24,6 +24,7 @@ #include "llvm/Support/ELF.h" #include "lldb/lldb-enumerations.h" +#include "lldb/lldb-types.h" namespace lldb_private { class DataExtractor; @@ -65,10 +66,17 @@ struct ELFHeader { elf_half e_machine; ///< Target architecture. elf_half e_ehsize; ///< Byte size of the ELF header. elf_half e_phentsize; ///< Size of a program header table entry. - elf_half e_phnum; ///< Number of program header entries. + elf_half e_phnum_hdr; ///< Number of program header entries. elf_half e_shentsize; ///< Size of a section header table entry. - elf_half e_shnum; ///< Number of section header entries. - elf_half e_shstrndx; ///< String table section index. + elf_half e_shnum_hdr; ///< Number of section header entries. + elf_half e_shstrndx_hdr; ///< String table section index. + + // In some cases these numbers do not fit in 16 bits and they are + // stored outside of the header in section #0. Here are the actual + // values. + elf_word e_phnum; ///< Number of program header entries. + elf_word e_shnum; ///< Number of section header entries. + elf_word e_shstrndx; ///< String table section index. ELFHeader(); @@ -102,6 +110,14 @@ struct ELFHeader { unsigned GetRelocationJumpSlotType() const; //-------------------------------------------------------------------------- + /// Check if there should be header extension in section header #0 + /// + /// @return + /// True if parsing the ELFHeader requires reading header extension + /// and false otherwise. + bool HasHeaderExtension() const; + + //-------------------------------------------------------------------------- /// Parse an ELFHeader entry starting at position \p offset and /// update the data extractor with the address size and byte order /// attributes as defined by the header. @@ -137,6 +153,16 @@ struct ELFHeader { /// The number of bytes forming an address in the ELF file (either 4 or /// 8), else zero if the address size could not be determined. static unsigned AddressSizeInBytes(const uint8_t *magic); + +private: + + //-------------------------------------------------------------------------- + /// Parse an ELFHeader header extension entry. This method is called + /// by Parse(). + /// + /// @param[in] data + /// The DataExtractor to read from. + void ParseHeaderExtension(lldb_private::DataExtractor &data); }; //------------------------------------------------------------------------------ |