Use _r_debug instead of /proc/<pid>/maps for folly::symbolizer
authorMax Wang <mwang@fb.com>
Thu, 11 Aug 2016 18:22:46 +0000 (11:22 -0700)
committerFacebook Github Bot 0 <facebook-github-bot-0-bot@fb.com>
Thu, 11 Aug 2016 18:23:37 +0000 (11:23 -0700)
commitddeb302ab4b34ff93a72bafbd7c51f120179f233
tree276c5ce5e71c9a85c21996b86156d8146656f422
parent7ef3c1b23149d7ad32eb685a7e4832358ff5792e
Use _r_debug instead of /proc/<pid>/maps for folly::symbolizer

Summary:
Using _r_debug offers a number of benefits:
- It allows us to symbolize addresses in data segments like .bss that
  are marked "[heap]" in /proc/<pid>/maps.
- It requires a lot less code.

It also fixes a preexisting bug where we would fail to symbolize
addresses that fell in any section past the first in any position-
independent objects.  Since `elfFile->getBaseAddress()` should always
return 0 for any PIEs, we wouldn't correctly adjust the address to be
ELF-relative when performing symbol lookup.  (For the first section,
we just used the start of the range we found in /perf/<pid>/maps.)

There is a minor downside:
- We have to open an ELF header for each object in order to check if a
  given address is in the range of some segment.  Before, we used
  /proc/<pid>/maps to make the range check, and only opened the header
  once we knew it was the one we wanted.  In the common case, however,
  where the addresses are from our own executable, we don't open any
  more files than before (and, in fact, one fewer).

Reviewed By: luciang

Differential Revision: D3695872

fbshipit-source-id: 9bdcc77da4d658ffad5c671f9b8ea65a471ed64f
folly/experimental/symbolizer/Symbolizer.cpp