Commit bb8d886a authored by Teng Qin's avatar Teng Qin Committed by Facebook Github Bot

Add parsing for indirect functions

Summary:
Currently `folly::symbolizer`'s `getDefinitionByAddress` and `getSymbolByName` only parses `STT_OBJECT` and `STT_FUNC`. There are some standar library functions that uses the GNU indirect function feature that would have been missed:

  ==== For libpthread-2.23.so:
  ====== Symbol system Addr 119d0 Size 8 is a STT_GNU_IFUNC
  ====== Symbol siglongjmp Addr 10700 Size 8 is a STT_GNU_IFUNC
  ====== Symbol longjmp Addr 10700 Size 8 is a STT_GNU_IFUNC
  ====== Symbol __vfork Addr 10af0 Size 8 is a STT_GNU_IFUNC
  ====== Symbol vfork Addr 10af0 Size 8 is a STT_GNU_IFUNC
  ====== Symbol system_ifunc Addr 119d0 Size 8 is a STT_GNU_IFUNC
  ====== Symbol longjmp_ifunc Addr 10700 Size 8 is a STT_GNU_IFUNC
  ====== Symbol vfork_ifunc Addr 10af0 Size 8 is a STT_GNU_IFUNC
  ====== Symbol siglongjmp_ifunc Addr 10700 Size 8 is a STT_GNU_IFUNC
  ====== Symbol __vfork_ifunc Addr 10af0 Size 8 is a STT_GNU_IFUNC
  ====== Symbol __vfork@GLIBC_2.2.5 Addr 10af0 Size 8 is a STT_GNU_IFUNC
  ====== Symbol siglongjmp@GLIBC_2.2.5 Addr 10700 Size 8 is a STT_GNU_IFUNC
  ====== Symbol vfork@GLIBC_2.2.5 Addr 10af0 Size 8 is a STT_GNU_IFUNC
  ====== Symbol system@GLIBC_2.2.5 Addr 119d0 Size 8 is a STT_GNU_IFUNC
  ====== Symbol longjmp@GLIBC_2.2.5 Addr 10700 Size 8 is a STT_GNU_IFUNC

  ==== For libc-2.23.so:
  ====== Symbol __gettimeofday Addr c05e0 Size a8 is a STT_GNU_IFUNC
  ====== Symbol strcpy Addr 8e150 Size 35 is a STT_GNU_IFUNC
  ====== Symbol wmemcmp Addr afb50 Size 37 is a STT_GNU_IFUNC
  ====== Symbol strncmp Addr 8eb30 Size 41 is a STT_GNU_IFUNC
  ====== Symbol stpncpy Addr 929f0 Size 35 is a STT_GNU_IFUNC
  ====== Symbol __mempcpy_chk Addr 11cec0 Size 68 is a STT_GNU_IFUNC
  ====== Symbol strncpy Addr 903d0 Size 35 is a STT_GNU_IFUNC
  ====== Symbol time Addr c0500 Size a8 is a STT_GNU_IFUNC
  ====== Symbol strpbrk Addr 90700 Size 22 is a STT_GNU_IFUNC
  ====== Symbol strspn Addr 90a80 Size 22 is a STT_GNU_IFUNC
  ====== Symbol __stpncpy Addr 929f0 Size 35 is a STT_GNU_IFUNC
  ====== Symbol __strcasecmp Addr 92a80 Size 54 is a STT_GNU_IFUNC
  ====== Symbol memset Addr 92230 Size 41 is a STT_GNU_IFUNC
  ====== Symbol strstr Addr 916b0 Size 21 is a STT_GNU_IFUNC
  ====== Symbol strcspn Addr 8e270 Size 22 is a STT_GNU_IFUNC
  ====== Symbol memcmp Addr 91c40 Size 37 is a STT_GNU_IFUNC
  ====== Symbol mempcpy Addr 923b0 Size 68 is a STT_GNU_IFUNC
  And 80 more...
This Diff adds parsing for `STT_GNU_IFUNC` symbols as well

Reviewed By: yfeldblum

Differential Revision: D6282727

fbshipit-source-id: 71b7c44831e4ddfdccf1e794cb86e049e14227bc
parent ef4c7223
......@@ -28,6 +28,10 @@
#include <folly/Exception.h>
#include <folly/ScopeGuard.h>
#ifndef STT_GNU_IFUNC
#define STT_GNU_IFUNC 10
#endif
namespace folly {
namespace symbolizer {
......@@ -361,7 +365,7 @@ ElfFile::Symbol ElfFile::getDefinitionByAddress(uintptr_t address) const {
};
return iterateSymbolsWithTypes(
section, {STT_OBJECT, STT_FUNC}, findSymbols);
section, {STT_OBJECT, STT_FUNC, STT_GNU_IFUNC}, findSymbols);
};
// Try the .dynsym section first if it exists, it's smaller.
......@@ -400,7 +404,7 @@ ElfFile::Symbol ElfFile::getSymbolByName(const char* name) const {
};
return iterateSymbolsWithTypes(
section, {STT_OBJECT, STT_FUNC}, findSymbols);
section, {STT_OBJECT, STT_FUNC, STT_GNU_IFUNC}, findSymbols);
};
// Try the .dynsym section first if it exists, it's smaller.
......
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