3

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.

3
  • I don't know the answer, but it seems like the problem is that __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"? Sep 12, 2013 at 13:17
  • Thanks for the thought Mats. The 'low_level.so' is being called by 'high_level.a'. I tried to add the -coverage option while compilation of the 'high_level.a'. But still the dlopen is not picking it up. "Main" application is anyhow is just calling functions of 'high_level.a' and is not directly calling functions of 'low_level.so'.
    – Rajen
    Sep 13, 2013 at 3:54
  • My point is that it seems like the coverage functionality would need to be in with the low_level.so... But I don't know exactly how this works, I'm just interpreting from the error message you get. Sep 13, 2013 at 13:22

2 Answers 2

1

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

0
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.