When I use the valgrind bbv tool, I encountered a problem. The instruction count of the same executable file valgrind is quite different from that of pmu. Such as SPEC2006 omnetpp, the instruction count is about 57190 billion by valgrind, but that is 57290 billion by pmu. The environment in which the program runs is the same.
Then we wrote a simple program to verify this, the result is that valgrind's instruction count is about 800 less. The test code:
#include <unistd.h> int main(void) { unsigned int i = 0, sum = 0; sum += i; return 0; }valgrind --tool=exp-bbv ./withmain
Total instructions: 5232simpleperf stat -e instructions:u ./withmain(just count instructions in usespace)
Performance counter statistics:
6,043 instructions:u # (100%)
2. Then we found the functions like _start and _init is UNKNOWN in valgrind, and the symbol size of that functions is zero. Valgrind seems to ignore them during command analysis.
I found that there are such descriptions of this kind of glibc function in m_main.c:
If linking of the final executables is done with glibc present, then Valgrind starts at main() above as usual, and all of the following code is irrelevant. However, this is not the intended mode of use. The plan is to avoid linking against glibc, by giving gcc the flags -nodefaultlibs -lgcc -nostartfiles at startup.
Q:
1) Anyone known why can't valgrind analyze these functions?
2) The descriptions above mean that we have to avoid using the glibc function? Is there any other way to resolve this difference of instruction count?
3) Why size of some function symbol(such as _start, _init, etc) is zero in elf file? but when I objdump that file, I can see the whole code of that functions.
3. The program environment:
- Operating environment: Andriod10 (aarch64 Linux 4.14)
- CPU core: armv8 CotexA55
- Cross-Compiler: gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu (both valgrind and test code compile by this cross tool, --static, -g -O3 and other para already tried). I have tried gcc-4.8.2 that have same problem.