1

Steps to Reproduce the issue

#include<iostream>
int main(){
    std::cout <<  "Hello World" << std::endl;
}
  1. Write main.cpp

  2. Download Toolchain from this link

  3. Compile with below commands.

    • . /opt/poky/1.6/environment-setup-armv7a-vfp-neon-poky-linux-gnueabi
    • arm-poky-linux-gnueabi-g++ main.cpp -o main --coverage
  4. Will get an error like below.

Error

/opt/poky/1.6.1/sysroots/i686-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.8.3/ld: cannot find -lgcov collect2: error: ld returned 1 exit status

Problem Statement

How to generate a libgcov.so file for ARM poky toolchain?

-fprofile-args --coverage -ftest-coverage

I'm able to generate a the code coverage report using x86 linux g++ compiler by installing

- sudo apt-get install gcovr
- g++ main.cpp -o main --coverage

Is there any source code or git repository from which I can generate the libgcov.so file for the ARM poky toolchain? Or Is there any solution to get the coverage of a program from ARM poky toolchain?

I have tried cloning and compiling the below repository as a library but the issue is not resolved.

https://github.com/reeteshranjan/libgcov-embedded

How to generate the code coverage report file for a program written using ARM toolchain(poky 1.6) on Ubuntu 18.04?

amon
  • 57,091
  • 2
  • 89
  • 149
Thomas Easo
  • 3,457
  • 3
  • 21
  • 32
  • 1
    `Is there any source code` https://github.com/gcovr/gcovr – KamilCuk May 13 '21 at 08:28
  • After adding the -coverage flag, we are getting gcno files but not gcda file. Gcda file is having the coverage information which is not getting generated hence the coverage is shown as 0 – Thomas Easo May 13 '21 at 13:28
  • Gcda file Is not generated since it’s throwing a linker error unable to find -lgcov – Thomas Easo May 13 '21 at 13:37
  • 1
    Gcov is part of GCC, and can't really be distributed separately. If the linker fails to resolve this, this could indicate that your cross-compilation configuration is broken. I haven't done so myself, but I know of people who have used gcov and gcovr on ARM successfully. There is no GCC 8.25, maybe that's part of the problem? Most recent 8.x release is 8.4. – amon May 13 '21 at 22:30
  • Thank you @amon for your valuable update. Yes you are right the gcc version might be wrong. Is there any way to check whether my toolchain is having gcov enabled or not? or any other verbose logging from which i can get detailed information about the exact issue. gcno files are generated during compilation phase but the issue is during the "Compilation phase" but not gcda files[https://www.researchgate.net/publication/240634031_Gcov_on_an_embedded_system] – Thomas Easo May 14 '21 at 02:03
  • The current version (in may 2021) of GCC is [GCC 11](https://gcc.gnu.org/gcc-11/). It is [free software](https://www.gnu.org/philosophy/free-sw.en.html) - you can download its source code and compile it – Basile Starynkevitch May 14 '21 at 04:32
  • Your Yocto 1.6 toolchain is 7 years old, it is likely that issues have been fixed in newer versions. I've tagged the question with Yocto to get visibility from experts, but I doubt the community is interested in supporting such old versions. – amon May 14 '21 at 08:00
  • Hi @amon which version would be the best fit higher version of poky which i can use from the above link? http://downloads.yoctoproject.org/releases/yocto/ http://downloads.yoctoproject.org/releases/yocto/yocto-3.3/toolchain/x86_64/ – Thomas Easo May 14 '21 at 09:01
  • Sorry, I know some things about gcov but nothing about Yocto. – amon May 14 '21 at 10:15
  • Yes @amon. I took yocto3.1.6/sysroots/armv7vet2hf-neon-poky-linux-gnueabi and it has compliled and it is generating the gcno and gcda files but the contents are empty where as default g++ is giving the files properly. Is there any gcc options to enable verbose logging or debugging for detailed information about gcov compilation? – Thomas Easo May 14 '21 at 10:32
  • That's progress! To clarify: does the .gcda file have size zero, does `gcov /path/to/your.gcda` produce errors/unsuitable output, or is gcovr doing something odd? If the .gcda files are empty, this indicates the `__gcov_exit()` destructor is not being called properly in the executable. In the Blasum 2007 paper you linked, they had to call this function manually. Gcov will require suitable [cross-profiling config](https://gcc.gnu.org/onlinedocs/gcc/Cross-profiling.html#Cross-profiling). Gcovr just aggregates reports and cannot work without gcov. – amon May 14 '21 at 11:10
  • Yes @amon, We are making good progress. Its giving output as "no function found". $ gcov main.gcna main.gcno:version 'B02*', prefer 'A75*' main.gcno:no functions found $ gcov main.gcno main.gcno:version 'B02*', prefer 'A75*' main.gcno:no functions found – Thomas Easo May 14 '21 at 21:17
  • 1
    You must use the gcov binary from the cross-compilation toolchain, not the gcov from your default GCC installation. If you invoked the compiler as `/some/path/g++-8` you need to use `/some/path/gcov-8`. When you later use gcovr, you must also provide this path as the `--gcov-executable`. This will get rid of the version warning, but if the "no function found" error persists then the .gcda is still empty. – amon May 14 '21 at 21:30
  • Thanks @amon. The program is working with the latest poky(3.3) along with your suggestions. It is not working with the old poky(1.6) since libgcov.a file is not present in /opt/poky/1.6/sysroots/armv7a-vfp-neon-poky-linux-gnuea.bi/usr/lib/arm-poky-linux/4.8.2/ directory. Where as in 3.3, libgcov.a file is present in /opt/poky/3.3/sysroots/armv7vet2hf-neon-poky-linux-gnueabi/usr/lib/arm-poky-linux-gnueabi/10.2.0/libgcov.a. Is the way of gcov handling is different from gcc 4.8.2 and gcc10.2.0? – Thomas Easo May 14 '21 at 23:33
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/232427/discussion-between-thomas-easo-and-amon). Currently you can submit the solution so that your efforts are appreciated. We can still try to solve for 1.6 as well in chat discussion group @amon – Thomas Easo May 14 '21 at 23:47

1 Answers1

0
  1. Build the application using yocto build system

    bitbake

  2. Copy the libgcov.so generated from /tmp/deploy/ into /opt/poky/1.6.1/sysroots/i686-pokysdk-linux/usr/lib/

  3. Trigger the build using g++

Thomas Easo
  • 3,457
  • 3
  • 21
  • 32