[perf-prof] Adjust source position addresses according to ELF header size

The "perf inject" command will place the generated function into a .text
section, placed directly after the ELF header. As a result, source position
addresses need to be adjusted according to the size of the ELF header, which is
0x40 for 64 bit architectures and 0x34 on 32 bit architectures.

We would previously adjust the addresses with 0x40 regardless of the
architecture.

BUG=

Review-Url: https://codereview.chromium.org/2783203005
Cr-Commit-Position: refs/heads/master@{#44325}
This commit is contained in:
pierre.langlois 2017-04-03 01:15:35 -07:00 committed by Commit bot
parent a3be9e78c1
commit 3258b2690e
2 changed files with 13 additions and 7 deletions

View File

@ -322,13 +322,11 @@ void PerfJitLogger::LogWriteDebugInfo(Code* code, SharedFunctionInfo* shared) {
SourcePositionInfo info(GetSourcePositionInfo(code_handle, function_handle,
iterator.source_position()));
PerfJitDebugEntry entry;
// TODO(danno): There seems to be a bug in the dwarf handling of JIT code in
// the perf tool. It seems to erroneously believe that the first instruction
// of functions is at offset 0x40 when displayed in "perf report". To
// compensate for this, add a magic constant to the position addresses when
// writing them out.
entry.address_ =
reinterpret_cast<intptr_t>(code_start + iterator.code_offset() + 0x40);
// The entry point of the function will be placed straight after the ELF
// header when processed by "perf inject". Adjust the position addresses
// accordingly.
entry.address_ = reinterpret_cast<intptr_t>(
code_start + iterator.code_offset() + kElfHeaderSize);
entry.line_number_ = info.line + 1;
entry.column_ = info.column + 1;
LogWriteBytes(reinterpret_cast<const char*>(&entry), sizeof(entry));

View File

@ -91,6 +91,14 @@ class PerfJitLogger : public CodeEventLogger {
#endif
}
#if V8_TARGET_ARCH_32_BIT
static const int kElfHeaderSize = 0x34;
#elif V8_TARGET_ARCH_64_BIT
static const int kElfHeaderSize = 0x40;
#else
#error Unknown target architecture pointer size
#endif
// Per-process singleton file. We assume that there is one main isolate;
// to determine when it goes away, we keep reference count.
static base::LazyRecursiveMutex file_mutex_;