https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105238

--- Comment #4 from Esger Abbink <esgergn at hotmail dot com> ---
We use Ubuntu 20.04 currently for our jenkins images.

With gcc built from master with patch using -fprofile-prefix-map works as
expected:

with a main.cpp in /home/esger/src/application/coverage_test/dir1/source

compiling with:

cd /home/esger/src/application/coverage_test/dir1/source/ && g++-11 --coverage
-fprofile-prefix-map=/home/esger/src/application/coverage_test/dir1=dir2 -c
/home/esger/src/application/coverage_test/dir1/source/main.cpp 

cd /home/esger/src/application/coverage_test/dir1/source/ && g++-11 --coverage
-fprofile-prefix-map=/home/esger/src/application/coverage_test/dir1=dir2 main.o
-o ../bin/a.out

results in a main.gcno in the source directory, and after running
./dir1/bin/a.out from /home/esger/src/application/coverage_test there is a
main.gcda (non-mangled) in dir2/source.


Note that I was not able to produce a meaningful coverage report even for the
simplest/first case of the four above with gcc 11. I think gcovr might not yet
support newer formats used? So I can't currently verify if with
-fprofile-prefix-map the coverage report is ok, but I would assume so.

(Still, I don't quite understand why behavior that was working is now
broken/changed and needs a new option? ie. why is -fprofile-dir mangling the
name, and -fprofile-prefix-map not? and 9.4 behavior with -fprofile-dir still
seems broken when explicitly specifying the default?)


If I perform a small experiment more closely resembling what cmake + ccache do:

cd /home/esger/src/application/coverage_test/dir1/source/ &&
CCACHE_BASEDIR=/home/esger/src/application/coverage_test/dir1 ccache
/usr/bin/g++-11 --coverage
-fprofile-prefix-map=/home/esger/src/application/coverage_test/dir1=.
-fdebug-prefix-map=/home/esger/src/application/coverage_test/dir1=. -c
/home/esger/src/application/coverage_test/dir1/source/main.cpp

cd /home/esger/src/application/coverage_test/dir1/source/ &&
CCACHE_BASEDIR=/home/esger/src/application/coverage_test/dir1 ccache
/usr/bin/g++-11 --coverage
-fprofile-prefix-map=/home/esger/src/application/coverage_test/dir1=.
-fdebug-prefix-map=/home/esger/src/application/coverage_test/dir1=. main.o -o
../bin/a.out

and then from /home/esger/src/application/coverage_test/dir2 run
../dir1/bin/a.out (to simulate a run with a binary built from cached .o and
.gcno run from a different directory) again the gcda is created in the
dir2/source directory with a non-mangled name. yey :)

I can also see the source file paths in the gcno are relative:

main.gcno:note:magic `gcno':version `B20 '
main.gcno:stamp 625107654
main.gcno:checksum 0
main.gcno:cwd: /home/esger/src/application/coverage_test/dir1/source
main.gcno:  01000000:  83:FUNCTION ident=1482908279,
lineno_checksum=0x2c72f060, cfg_checksum=0xc0bbb23e, `_GLOBAL__sub_I__Z5funcAi'
./source/main.cpp:21:1-21:1, artificial
main.gcno:    01410000:   4:BLOCKS 4 blocks
main.gcno:    01430000:  12:ARCS 1 arcs
main.gcno:    01430000:  20:ARCS 2 arcs
main.gcno:    01430000:  12:ARCS 1 arcs
main.gcno:    01450000:  42:LINES
main.gcno:    01450000:  42:LINES
...

So with a patched gcc11, dropping -fprofile-dir and using -fprofile-prefix-map
instead, gcda creation seems ok. The gcno files seem to contain relative paths
to the source file too. However, the gcno file also still contains the
compilation CWD which interferes with caching it and re-using it for different
build dirs. Is there any way to get rid of that?

And of course I still need to verify such created gcda files will actually
result in a proper coverage report. Applying the patch to 9.4 or 10.3 as
vit9696 did should allow me to test that. Will try that tomorrow if I have
time.

Reply via email to