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/unittests/ObjectFile/ELF/TestELFHeader.cpp | |
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/unittests/ObjectFile/ELF/TestELFHeader.cpp')
-rw-r--r-- | lldb/unittests/ObjectFile/ELF/TestELFHeader.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lldb/unittests/ObjectFile/ELF/TestELFHeader.cpp b/lldb/unittests/ObjectFile/ELF/TestELFHeader.cpp new file mode 100644 index 00000000000..279ea0a34d3 --- /dev/null +++ b/lldb/unittests/ObjectFile/ELF/TestELFHeader.cpp @@ -0,0 +1,62 @@ +//===-- TestELFHeader.cpp ---------------------------------------*- C++ -*-===// +// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "Plugins/ObjectFile/ELF/ELFHeader.h" +#include "lldb/Core/DataExtractor.h" +#include "gtest/gtest.h" + +using namespace lldb; +using namespace lldb_private; + + +TEST(ELFHeader, ParseHeaderExtension) { + uint8_t data[] = { + // e_ident + 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + + // e_type, e_machine, e_version, e_entry + 0x03, 0x00, 0x3e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x90, 0x48, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x00, + + // e_phoff, e_shoff + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + + // e_flags, e_ehsize, e_phentsize, e_phnum, e_shentsize, e_shnum, + // e_shstrndx + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x38, 0x00, 0xff, 0xff, 0x40, 0x00, + 0x00, 0x00, 0xff, 0xff, + + // sh_name, sh_type, sh_flags + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + + // sh_addr, sh_offset + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + + // sh_size, sh_link, sh_info + 0x23, 0x45, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x56, 0x78, 0x00, + 0x12, 0x34, 0x56, 0x00, + + // sh_addralign, sh_entsize + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + }; + + DataExtractor extractor(data, sizeof data, eByteOrderLittle, 8); + elf::ELFHeader header; + offset_t offset = 0; + ASSERT_TRUE(header.Parse(extractor, &offset)); + EXPECT_EQ(0x563412u, header.e_phnum); + EXPECT_EQ(0x785634u, header.e_shstrndx); + EXPECT_EQ(0x674523u, header.e_shnum); +} |