Strip coverage code from binary built by gcc

42 views Asked by At

I have enabled coverage in the CMakeLists.txt in order to find the coverage info using

add_compile_options(--coverage)

I wanted to add this to build system such that after a successful build, the build system runs the unit tests and send the coverage reports(lcov). It worked fine.

The build system strips( strip --strip-all) the debug symbols from debug build and the stripped binary is used in production as well as in test environment. The issue is the coverage code added by compiler could not be stripped from the binary. Hence the binary size is bigger.

I understand that the coverage code added is now part of the binary and strip only strips the debug symbols. Strip can't differentiate coverage code from functionality. Is there a way to strip the coverage code from binary?

The binary size of debug build is

13949142 - Debug build
1014326  - Stripped Debug build

The binary size of debug build that has coverage code

16152614 - Debug build with coverage 
1575174  - Stripped Debug build with coverage 
1

There are 1 answers

0
KamilCuk On

Is there a way to strip the coverage code from binary?

No. You have to recompile without --coverage option.