From 1bcd34c4da5e08d339dd1c59a6d4806919fd6727 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Fri, 18 Oct 2013 19:03:30 -0400 Subject: [PATCH] libdebug: Improve handling of stripped binaries. - When searching for the symbol table, first see if the normal SHT_SYMTAB section is present. If not, fall back to trying to use SHT_DYNSYM if present. This allows us to resolve non-static functions/symbols in stripped binaries for the purposes of crash reports/disassembly. --- src/kits/debug/Image.cpp | 19 +++++++++++++++---- src/kits/debug/Image.h | 3 +++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/kits/debug/Image.cpp b/src/kits/debug/Image.cpp index b2f23d3a3e..239820ffba 100644 --- a/src/kits/debug/Image.cpp +++ b/src/kits/debug/Image.cpp @@ -305,9 +305,6 @@ ImageFile::_LoadFile(const char* path, addr_t* _textAddress, size_t* _textSize, return B_NOT_AN_EXECUTABLE; } - elf_shdr* sectionHeaders - = (elf_shdr*)(fMappedFile + elfHeader->e_shoff); - // find the text and data segment -- we need load address and size *_textAddress = 0; *_textSize = 0; @@ -328,12 +325,26 @@ ImageFile::_LoadFile(const char* path, addr_t* _textAddress, size_t* _textSize, } } + status_t error = _FindTableInSection(elfHeader, SHT_SYMTAB); + if (error != B_OK) + error = _FindTableInSection(elfHeader, SHT_DYNSYM); + + return error; +} + + +status_t +ImageFile::_FindTableInSection(elf_ehdr* elfHeader, uint16 sectionType) +{ + elf_shdr* sectionHeaders + = (elf_shdr*)(fMappedFile + elfHeader->e_shoff); + // find the symbol table for (int32 i = 0; i < elfHeader->e_shnum; i++) { elf_shdr* sectionHeader = (elf_shdr*) ((uint8*)sectionHeaders + i * elfHeader->e_shentsize); - if (sectionHeader->sh_type == SHT_SYMTAB) { + if (sectionHeader->sh_type == sectionType) { elf_shdr& stringHeader = *(elf_shdr*) ((uint8*)sectionHeaders + sectionHeader->sh_link * elfHeader->e_shentsize); diff --git a/src/kits/debug/Image.h b/src/kits/debug/Image.h index 4d4be64951..2d5cbbef8d 100644 --- a/src/kits/debug/Image.h +++ b/src/kits/debug/Image.h @@ -96,6 +96,9 @@ private: addr_t* _textAddress, size_t* _textSize, addr_t* _dataAddress, size_t* _dataSize); + status_t _FindTableInSection(elf_ehdr* elfHeader, + uint16 sectionType); + private: int fFD; off_t fFileSize;