For example I have test program located in 'test/main.cc', which just contain one empty main function. 1. Compiling it g++ --coverage -c -o test/main.o test/main.cc g++ --coverage -o main test/main.o 2. Running ./main 3. Trying to run gcov (with no success) % gcov ./test/main.cc main.gcno:cannot open graph file % (cd test ; gcov main.cc) File 'test/main.cc' Lines executed:100.00% of 1 test/main.cc:creating 'main.cc.gcov' test/main.cc:cannot open source file So there is no way to run gcov successfully. In first case, when running from toplevel directory, it simply can't find main.gcno (it is searching it in current directory but it should search in directory 'test' because full source name is test/main.cc). In second case, when running from 'test' directory it can't find the source. It is searching for test/main.cc, but current directory already 'test'.
The proper GCC flags are -fprofile-arcs and -ftest-coverage. The gcov documentation does not reference --coverage anywhere.
--coverage documented in gcc manual `--coverage' This option is used to compile and link code instrumented for coverage analysis. The option is a synonym for `-fprofile-arcs' `-ftest-coverage' (when compiling) and `-lgcov' (when linking). See the documentation for those options for more details. So it is no matter what to specify either --coverage or -fprofile-arcs -ftest-coverage
This is incredibly old and I can't see how this would be a gentoo only bug. Please bring this upstream if you wish to pursue it since if it was expected behaviour it would have been fixed by now.