3

I've got some server in c++ (commands acquired from build-system):

g++ -o obj/server.o -c -m64 -isystem/opt/boost/include -Wall -Werror -march=core2 -ftest-coverage -fprofile-arcs -DGCOV_ENABLED= -Iinclude -I/opt/hydraOST/lzopro/include -I/usr/include/libxml2 -Idaemon/include src/server.cpp g++ -o bin/server.exe -rdynamic -ftest-coverage -fprofile-arcs -m64 -Wl,-rpath=\$ORIGIN -Wl,-rpath=/opt/hydraOST/lzopro/lib obj/server.o (+ other libs) 

As it's daemon and I'm stopping it with signal but to enforce dumping gcov data before kill $PID I'm using gdb:

gdb -p $PID -batch -x gcov/dumpGcovData 

where contents of gcov/dumpGcovData:

call __gcov_flush() thread apply all call __gcov_flush() 

I know that linking should be with -lgcov but as it was working in that way so I didn't change it in build system. The problem occured just after added -rdynamic flag (without that flag it worked properly).

2 Answers 2

1

I know that linking should be with -lgcov

That is incorrect: gcc will add -lgcov automatically given your flags; no explicit -lgcov needed.

The problem occured just after added -rdynamic flag (without that flag it worked properly).

I can't imagine what -rdynamic may have to do with the problem. A trivial test case shows that it works either way, so either your claim of "it stopped working with addition of -rdynamic" is wrong, or there is some more complicated interaction going on (which I am not reproducing in my trivial test).

You may want to begin by

  1. Verifying that in fact re-linking server.exe without -rdynamic as the only change makes it work again.
  2. Showing the output from g++ -o bin/server.exe ... -Wl,-y,__gcov_flush and readelf -s bin/server.exe | grep __gcov_flush. Here is what it should look like:

    g++ -ftest-coverage -fprofile-arcs cov.c -g -rdynamic -Wl,-y,__gcov_flush /usr/lib/gcc/x86_64-linux-gnu/4.4.3/libgcov.a(_gcov.o): definition of __gcov_flush readelf -s a.out | grep gcov_fl 66: 00000000004023c0 131 FUNC LOCAL HIDDEN 14 __gcov_flush 
Sign up to request clarification or add additional context in comments.

3 Comments

Ad.1 Yes, after removed -rdynamic flag coverage has been generated. I will do experiment with readelf, but when I had it compiled then nm showed that '__gcov_flush' was defined in server.exe (so invoking with __gcov_flush should work...)
"I can't imagine what -rdynamic may have to do with the problem" - yes, thats my main problem - note that there is also other binary that just ends normally and gcda file is generated properly. I suppose that -rdynamic just caused that somehow invoking __gcov_flush by gdb does not work... but have no idea why(?)
@ddzialak "have any idea why?" -- The output from commands in #2 may provide clues. Please run them and update your question with the output. Then someone may have an idea why. Alternatively, try to create a minimal test case that shows the problem.
1

After added -Wl,-y,__gcov_flush it printed out line (and flag -rdynamic does not matter):

/usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcov.a(_gcov.o): definition of __gcov_flush 

Unfortunately, looks like -rdynamic flag does not afftect the output:

with -rdynamic:

readelf -s server.exe | grep gcov_flush 1203: 0000000000808370 107 FUNC LOCAL HIDDEN 12 __gcov_flush 

and without -rdynamic:

readelf -s server.exe | grep gcov_flush 1203: 0000000000808380 107 FUNC LOCAL HIDDEN 12 __gcov_flush 

Anyway, I've got very simple solution (or rather workaround): add -rdynamic ONLY if its build not for gcov:

if CONFIG == gcov: addFlags(["-ftest-coverage", "-fprofile-arcs"]) else: addFlags(["-rdynamic"]) 

So, main problem seems to be not solved, anyway got some workaround (works for me, because I rather don't use gcov config for debugging - just for generating coverage report). Anyway, thanks for help!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.