是什么导致无法在DWARFperf调用堆栈中展开?
在由 生成perf record --call-graph dwarf和打印的回溯中perf script,我一直得到可能有 5% 的调用堆栈的错误地址,即展开失败。一个例子是
my_bin 770395 705462.825887: 3560360 cycles:
7f0398b9b7e2 __vsnprintf_internal+0x12 (/usr/lib/x86_64-linux-gnu/libc-2.32.so)
7ffcdb6fbfdf [unknown] ([stack])
my_bin 770395 705462.827040: 3447195 cycles:
7f0398ba1624 __GI__IO_default_xsputn+0x104 (inlined)
7ffcdb6fb7af [unknown] ([stack])
它是从此代码生成的(使用 编译g++ -O3 -g -fno-omit-frame-pointer my_bin.cpp -o my_bin):
#include <cstdio>
#include <iostream>
int __attribute__ ((noinline)) libc_string(int x) {
char buf[64] = {0};
// Some nonsense workload using libc
int res = 0;
for (int i = 0; i < x; ++i) {
res += snprintf(buf, 64, "%d %d %d Can I bring my friends to tea?", (i%10), (i%3)*10, i+2);
res = res % 128;
}
return res;
}
int main() {
int result = libc_string(20000000);
std::cout << result << "n";
}
我很确定我的程序在堆栈中不应该有可执行代码,所以这些地址似乎是错误的。它不仅是一个程序,而且我分析过的大多数程序都有大约 5% 的错误调用堆栈。这些调用堆栈大多只有两个堆栈帧,最里面的一个有时在像 Eigen 这样的库中(即使它们通常具有正确的调用堆栈),有时在 C++ STL 或 libc 中。我已经看到展开结束于unknown, [stack], [heap], anon, //anon, libstdc++.so.6.0.28, 或<my_bin>。
我在 Ubuntu 18.04、20.04 和 20.10 上看到过这个。
这只发生在 DWARF 展开时。如何解决这个问题?