Structure of the entire application:
- Shared Library say - low_level.so.
- Static Library say - high_level.a. This static library uses the 'low_level.so' by calling the dlopen function (for loading the low_level.so) and dlsym function (for getting the address where that symbol is loaded into memory).
- Application Program (with 'main' function) - This application links the 'high_level.a' static library which internally calls the required function from the 'low_level.so' library.
Current scenarios (working/not-working)
- The above structure works for the cases when I am not using the lcov/gcov tools for code-coverage.
- I was successful in using the lcov/gcov tools for getting the code-coverage of 'high_level.a' static library.
I tried to get the code-coverage of the 'low_level.so' shared library using the lcov/gcov from the above structure but was not successful, below are the steps tried and error seen:
Added "-fprofile-arcs" "-ftest-coverage" flags while compilation of 'low_level.so' library. And created the library.
Added "-coverage" option for the compilation of 'high_level.a' library. And created the library.
Added 'LFLAGS=-lgcov -coverage' for the Application Program (with 'main' function). And created the executable application.
Now when I tried to executed the above compiled application program, I get below error for dlopen: could not dlopen: /home/test/libXXX.so: undefined symbol: __gcov_merge_add
Questions?:
- Does that mean that dlopen cannot be used with lcov/gcov and we need to actually link the shared library in the static library (by changing the current static library code for the same)? Or is there something that I am missing to be done for making the lcov/gcov work with the dlopen?
Note: All code is in 'C'.
FYI, I searched for the same and found some similar question, which was still lagging a selected best answer: How to find the coverage of a library opened using dlopen()? Also there was no good pointer on the net apart from the option of not using dlopen.
__gcov_merge_add
is required, and the dlopen doesn't try to find it in the "main" application, but in another library. Maybe you need to statically link that into your "low_level.so"? – Mats Petersson