Commit 1feb410b authored by Andrew Gallagher's avatar Andrew Gallagher Committed by Facebook Github Bot

folly/symbolizer: don't use ELF base address for executables

Summary:
I'm not entirely sure the original motivation for this, but for the current
executable, we've been normalizing addresses from the virtual address referenced
by the first "LOAD" program header instead of 0.  This appears to be a bug, as
it forms invalid addresses into the ELF file.

In the case of the signal handler test, this happens to work with gold, as the
initial section lookup just happens to hit in the `.debug_str` section (as opposed
to the expected `.text` section), and the following name translation then undoes
the base address normalization to get a correct lookup.

While this works for gold, it breaks for LLD and meant we had to opt-out folly
out (D13279459).

Reviewed By: yfeldblum

Differential Revision: D14119804

fbshipit-source-id: 53dcaeb72ed75e58f9a46b15799ce1af5ff80531
parent 7fabe818
......@@ -69,7 +69,6 @@ void SymbolizedFrame::set(
clear();
found = true;
address += file->getBaseAddress();
auto sym = file->getDefinitionByAddress(address);
if (!sym.first) {
return;
......@@ -134,13 +133,6 @@ void Symbolizer::symbolize(
continue;
}
// Get the address at which the object is loaded. We have to use the ELF
// header for the running executable, since its `l_addr' is zero, but we
// should use `l_addr' for everything else---in particular, if the object
// is position-independent, getBaseAddress() (which is p_vaddr) will be 0.
auto const base =
lmap->l_addr != 0 ? lmap->l_addr : elfFile->getBaseAddress();
for (size_t i = 0; i < addrCount && remaining != 0; ++i) {
auto& frame = frames[i];
if (frame.found) {
......@@ -160,8 +152,9 @@ void Symbolizer::symbolize(
}
}
// Get the unrelocated, ELF-relative address.
auto const adjusted = addr - base;
// Get the unrelocated, ELF-relative address by normalizing via the
// address at which the object is loaded.
auto const adjusted = addr - lmap->l_addr;
if (elfFile->getSectionContainingAddress(adjusted)) {
frame.set(elfFile, adjusted, mode_);
......
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