Domanda

Structure of the entire application:

  1. Shared Library say - low_level.so.
  2. 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).
  3. 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)

  1. The above structure works for the cases when I am not using the lcov/gcov tools for code-coverage.
  2. I was successful in using the lcov/gcov tools for getting the code-coverage of 'high_level.a' static library.
  3. 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?:

  1. 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.

È stato utile?

Soluzione 2

Thanks Mat for giving some input and thoughts.

Inline to that and doing some trial and error, I finally was able to solve the problem by adding the "-fprofile-arcs" and "-ftest-coverage" options as linker flags also in addition to compiler flags while compilation of 'low_level.so' library.

Altri suggerimenti

I solved this by adding -lgcov to shared library linking.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top