diff options
author | Peter Collingbourne <pcc@google.com> | 2017-05-24 16:25:09 -0700 |
---|---|---|
committer | Mike Frysinger <vapier@chromium.org> | 2017-05-25 00:14:08 +0000 |
commit | fbfd41af5fc63e0baa8f2ffbf87ded6d74f98233 (patch) | |
tree | e0446c1b639cde10f764be874bcfbe4e3d8d5630 /src | |
parent | Wrap config.h include in HAVE_CONFIG_H. (diff) | |
download | breakpad-fbfd41af5fc63e0baa8f2ffbf87ded6d74f98233.tar.xz |
Simplify ELF parser code.
The layout of Elf32_Nhdr and Elf64_Nhdr is the same, so remove
templating and code that extracts the elfclass from the ELF file.
Testing: "make check" and breakpad_unittests when patched into
chromium.
Bug: chromium:716484
Change-Id: I41442cfff48afc6ae1a5b604d22b67550a910376
Reviewed-on: https://chromium-review.googlesource.com/514450
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/client/linux/minidump_writer/linux_dumper.cc | 9 | ||||
-rw-r--r-- | src/common/linux/elfutils.cc | 14 | ||||
-rw-r--r-- | src/common/linux/elfutils.h | 12 | ||||
-rw-r--r-- | src/common/linux/file_id.cc | 22 |
4 files changed, 17 insertions, 40 deletions
diff --git a/src/client/linux/minidump_writer/linux_dumper.cc b/src/client/linux/minidump_writer/linux_dumper.cc index 3b8c80ab..8de32d44 100644 --- a/src/client/linux/minidump_writer/linux_dumper.cc +++ b/src/client/linux/minidump_writer/linux_dumper.cc @@ -352,17 +352,16 @@ bool ElfFileSoNameFromMappedFile( const void* segment_start; size_t segment_size; - int elf_class; - if (!FindElfSection(elf_base, ".dynamic", SHT_DYNAMIC, - &segment_start, &segment_size, &elf_class)) { + if (!FindElfSection(elf_base, ".dynamic", SHT_DYNAMIC, &segment_start, + &segment_size)) { // No dynamic section return false; } const void* dynstr_start; size_t dynstr_size; - if (!FindElfSection(elf_base, ".dynstr", SHT_STRTAB, - &dynstr_start, &dynstr_size, &elf_class)) { + if (!FindElfSection(elf_base, ".dynstr", SHT_STRTAB, &dynstr_start, + &dynstr_size)) { // No dynstr section return false; } diff --git a/src/common/linux/elfutils.cc b/src/common/linux/elfutils.cc index a79391c1..0ff2c3dc 100644 --- a/src/common/linux/elfutils.cc +++ b/src/common/linux/elfutils.cc @@ -122,8 +122,7 @@ bool FindElfSection(const void *elf_mapped_base, const char *section_name, uint32_t section_type, const void **section_start, - size_t *section_size, - int *elfclass) { + size_t *section_size) { assert(elf_mapped_base); assert(section_start); assert(section_size); @@ -135,10 +134,6 @@ bool FindElfSection(const void *elf_mapped_base, return false; int cls = ElfClass(elf_mapped_base); - if (elfclass) { - *elfclass = cls; - } - const char* elf_base = static_cast<const char*>(elf_mapped_base); @@ -158,8 +153,7 @@ bool FindElfSection(const void *elf_mapped_base, bool FindElfSegment(const void *elf_mapped_base, uint32_t segment_type, const void **segment_start, - size_t *segment_size, - int *elfclass) { + size_t *segment_size) { assert(elf_mapped_base); assert(segment_start); assert(segment_size); @@ -171,10 +165,6 @@ bool FindElfSegment(const void *elf_mapped_base, return false; int cls = ElfClass(elf_mapped_base); - if (elfclass) { - *elfclass = cls; - } - const char* elf_base = static_cast<const char*>(elf_mapped_base); diff --git a/src/common/linux/elfutils.h b/src/common/linux/elfutils.h index f34ba831..bcc74ea4 100644 --- a/src/common/linux/elfutils.h +++ b/src/common/linux/elfutils.h @@ -81,14 +81,12 @@ int ElfClass(const void* elf_base); // Attempt to find a section named |section_name| of type |section_type| // in the ELF binary data at |elf_mapped_base|. On success, returns true // and sets |*section_start| to point to the start of the section data, -// and |*section_size| to the size of the section's data. If |elfclass| -// is not NULL, set |*elfclass| to the ELF file class. +// and |*section_size| to the size of the section's data. bool FindElfSection(const void *elf_mapped_base, const char *section_name, uint32_t section_type, const void **section_start, - size_t *section_size, - int *elfclass); + size_t *section_size); // Internal helper method, exposed for convenience for callers // that already have more info. @@ -104,13 +102,11 @@ FindElfSectionByName(const char* name, // Attempt to find the first segment of type |segment_type| in the ELF // binary data at |elf_mapped_base|. On success, returns true and sets // |*segment_start| to point to the start of the segment data, and -// and |*segment_size| to the size of the segment's data. If |elfclass| -// is not NULL, set |*elfclass| to the ELF file class. +// and |*segment_size| to the size of the segment's data. bool FindElfSegment(const void *elf_mapped_base, uint32_t segment_type, const void **segment_start, - size_t *segment_size, - int *elfclass); + size_t *segment_size); // Convert an offset from an Elf header into a pointer to the mapped // address in the current process. Takes an extra template parameter diff --git a/src/common/linux/file_id.cc b/src/common/linux/file_id.cc index 311e0302..728f0bc8 100644 --- a/src/common/linux/file_id.cc +++ b/src/common/linux/file_id.cc @@ -61,10 +61,11 @@ FileID::FileID(const char* path) : path_(path) {} // These functions are also used inside the crashed process, so be safe // and use the syscall/libc wrappers instead of direct syscalls or libc. -template<typename ElfClass> static bool ElfClassBuildIDNoteIdentifier(const void *section, size_t length, wasteful_vector<uint8_t>& identifier) { - typedef typename ElfClass::Nhdr Nhdr; + static_assert(sizeof(ElfClass32::Nhdr) == sizeof(ElfClass64::Nhdr), + "Elf32_Nhdr and Elf64_Nhdr should be the same"); + typedef typename ElfClass32::Nhdr Nhdr; const void* section_end = reinterpret_cast<const char*>(section) + length; const Nhdr* note_header = reinterpret_cast<const Nhdr*>(section); @@ -96,25 +97,16 @@ static bool FindElfBuildIDNote(const void* elf_mapped_base, wasteful_vector<uint8_t>& identifier) { void* note_section; size_t note_size; - int elfclass; if ((!FindElfSegment(elf_mapped_base, PT_NOTE, - (const void**)¬e_section, ¬e_size, &elfclass) || + (const void**)¬e_section, ¬e_size) || note_size == 0) && (!FindElfSection(elf_mapped_base, ".note.gnu.build-id", SHT_NOTE, - (const void**)¬e_section, ¬e_size, &elfclass) || + (const void**)¬e_section, ¬e_size) || note_size == 0)) { return false; } - if (elfclass == ELFCLASS32) { - return ElfClassBuildIDNoteIdentifier<ElfClass32>(note_section, note_size, - identifier); - } else if (elfclass == ELFCLASS64) { - return ElfClassBuildIDNoteIdentifier<ElfClass64>(note_section, note_size, - identifier); - } - - return false; + return ElfClassBuildIDNoteIdentifier(note_section, note_size, identifier); } // Attempt to locate the .text section of an ELF binary and generate @@ -126,7 +118,7 @@ static bool HashElfTextSection(const void* elf_mapped_base, void* text_section; size_t text_size; if (!FindElfSection(elf_mapped_base, ".text", SHT_PROGBITS, - (const void**)&text_section, &text_size, NULL) || + (const void**)&text_section, &text_size) || text_size == 0) { return false; } |