aboutsummaryrefslogtreecommitdiff
path: root/src/common/linux/file_id.cc
diff options
context:
space:
mode:
authorPeter Collingbourne <pcc@google.com>2017-05-24 16:25:09 -0700
committerMike Frysinger <vapier@chromium.org>2017-05-25 00:14:08 +0000
commitfbfd41af5fc63e0baa8f2ffbf87ded6d74f98233 (patch)
treee0446c1b639cde10f764be874bcfbe4e3d8d5630 /src/common/linux/file_id.cc
parentWrap config.h include in HAVE_CONFIG_H. (diff)
downloadbreakpad-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/common/linux/file_id.cc')
-rw-r--r--src/common/linux/file_id.cc22
1 files changed, 7 insertions, 15 deletions
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**)&note_section, &note_size, &elfclass) ||
+ (const void**)&note_section, &note_size) ||
note_size == 0) &&
(!FindElfSection(elf_mapped_base, ".note.gnu.build-id", SHT_NOTE,
- (const void**)&note_section, &note_size, &elfclass) ||
+ (const void**)&note_section, &note_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;
}