Commit 576eeaee authored by Mark Williams's avatar Mark Williams Committed by Facebook Github Bot

Allow folly::symbolizer::ElfFile to work with cores

Summary:
In cores we're only interested in the ElfPhdrs (and there generally
aren't any sections), so apart from some asserts, the code already
does everything we need.

Reviewed By: paulbiss

Differential Revision: D19161810

fbshipit-source-id: fe6e2f34413d61067156858fc652ffffd910433c
parent be4b8793
...@@ -237,7 +237,8 @@ ElfFile::OpenResult ElfFile::init() noexcept { ...@@ -237,7 +237,8 @@ ElfFile::OpenResult ElfFile::init() noexcept {
} }
// We only support executable and shared object files // We only support executable and shared object files
if (elfHeader.e_type != ET_EXEC && elfHeader.e_type != ET_DYN) { if (elfHeader.e_type != ET_EXEC && elfHeader.e_type != ET_DYN &&
elfHeader.e_type != ET_CORE) {
return {kInvalidElfFile, "invalid ELF file type"}; return {kInvalidElfFile, "invalid ELF file type"};
} }
...@@ -250,7 +251,9 @@ ElfFile::OpenResult ElfFile::init() noexcept { ...@@ -250,7 +251,9 @@ ElfFile::OpenResult ElfFile::init() noexcept {
} }
if (elfHeader.e_shentsize != sizeof(ElfShdr)) { if (elfHeader.e_shentsize != sizeof(ElfShdr)) {
return {kInvalidElfFile, "invalid section header entry size"}; if (elfHeader.e_shentsize != 0 || elfHeader.e_type != ET_CORE) {
return {kInvalidElfFile, "invalid section header entry size"};
}
} }
// Program headers are sorted by load address, so the first PT_LOAD // Program headers are sorted by load address, so the first PT_LOAD
......
...@@ -46,8 +46,8 @@ using ElfSym = ElfW(Sym); ...@@ -46,8 +46,8 @@ using ElfSym = ElfW(Sym);
* ELF file parser. * ELF file parser.
* *
* We handle native files only (32-bit files on a 32-bit platform, 64-bit files * We handle native files only (32-bit files on a 32-bit platform, 64-bit files
* on a 64-bit platform), and only executables (ET_EXEC) and shared objects * on a 64-bit platform), and only executables (ET_EXEC) shared objects
* (ET_DYN). * (ET_DYN) and core files (ET_CORE).
*/ */
class ElfFile { class ElfFile {
public: public:
...@@ -300,8 +300,9 @@ class ElfFile { ...@@ -300,8 +300,9 @@ class ElfFile {
// I don't have a use-case for that right now, just assert that // I don't have a use-case for that right now, just assert that
// nobody wants this. We can always add it later. // nobody wants this. We can always add it later.
FOLLY_SAFE_CHECK( FOLLY_SAFE_CHECK(
elfHeader().e_type == ET_EXEC || elfHeader().e_type == ET_DYN, elfHeader().e_type == ET_EXEC || elfHeader().e_type == ET_DYN ||
"Only exectuables and shared objects are supported"); elfHeader().e_type == ET_CORE,
"Only exectuables, shared objects and cores are supported");
FOLLY_SAFE_CHECK( FOLLY_SAFE_CHECK(
addr >= section.sh_addr && addr >= section.sh_addr &&
(addr + sizeof(T)) <= (section.sh_addr + section.sh_size), (addr + sizeof(T)) <= (section.sh_addr + section.sh_size),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment