In this post, I will cover gcov run time data formats & the impact of this on gcov usage.
gcov run-time data format change
The first time I tried getting code coverage for a kernel module, I didn't get any gcda files in /sys/kernel/debug/gcov. Only a reset file was present. When I debugged the issue, I found the root cause - an issue arising from gcov's run time data format change introduced in gcc 4.7.
A new gcov run time data format is introduced in gcc 4.7. The new format has more efficient data structures used for profiling than the earlier format.
Impact on gcov usage
Due to this format change, run time coverage information collection can be broken.
The application code instrumentation facility is provided by gcc's compile flags. The gcov run time data collection engine is provided by libcov in case of user space applications or additional kernel code in case of kernel modules.
To accommodate gcov run time format change, both gcc version as well as libgcov/kernel-gcov-code should be moved together. Otherwise, run time coverage information collection can be broken due to incompatibility between instrumented code & the gcov run time data collection engine.
- Impact on User space Applications: As libgcov is part of gcc installation, we can safely assume that both gcc's instrumentation capability as well as gcov run time data collection engine are always moved together. So, one will not see any impact while using gcov on user space applications.
- Impact on Kernel modules or Kernel: In case of kernel, kernel-gcov-code provides gcov run time data collection engine. The support for newer gcov run time format is added to kernel in 3.13 version. And the gcc version installed on the system is controlled by user. So, there is a significant possibility that gcc version & kernel-gcov-code become incompatible. Here are the possibilities:
Scenario1 : gcc version < 4.7, kernel-gcov-code < 3.11: compatible formats
Scenario 2: gcc version < 4.7,
kernel-gcov-code > 3.11: incompatible, but linux kernel has backward
compatibility for past gcc versions. Selet "Auto detect"..
Scenario 3 : gcc version >=4.7,
kernel-gcov-code < 3.11: incompatible formats, run time data collection
broken
Scenario 4: gcc version>=4.7, kernel
version>3.11: compatible formats
I hit scenario 3. I solved it by upgrading my kernel to 3.13.5. Before recompiling 3.13.5 kernel, I selected "Autodetect Gcov format" in "make menuconfig". The exact steps are detailed in my other post at How to - Linux Kernel Compilation in Ubuntu VM/VirtualBox.
May be, gcc could have provided a facility to compile with
earlier gcov formats.
How to find your gcc version?
Refer my other post at My cheatsheet for gcc
How to find your linux kernel version?
Refer "OS Info" section in my other post at Linux System Info Commands