__bb_exit_func is registered with atexit(), to save the profiling data. I haven't analysed the situation in detail, but this appears to run before functions declared with __attribute__((destructor)), at least. So those don't get profiled (and, slightly more importantly, test coverage misses them). (If this isn't fixed in the next release, it should probably be documented as a limitation and referenced from the gcov manual). Release: gcc version 3.2.1 20020830 (Debian prerelease)
Hello, could you confirm whether this behavior is still the case in gcc 3.3? A testcase of the 'unreliable' behavior would also be much apprecaited. Thanks, Dara
The problem is that the write out for the data is done before global destructors are done.
I am not familiar with global destructors mechanizm, but can we assign each profiled file global destructor that will save profiles only for that file and manage priorities so they are run very last? That would solve this problem as well as the problem with profile being corrupted when dlclose is called... Honza
*** Bug 16855 has been marked as a duplicate of this bug. ***
This bug *still* exists as of i686-apple-darwin10-g++-4.2.1. The problem is apparently the collision of two at_exit() handlers, with C++'s global destructor coming in last.
Author: marxin Date: Tue Sep 27 11:07:11 2016 New Revision: 240529 URL: https://gcc.gnu.org/viewcvs?rev=240529&root=gcc&view=rev Log: gcov: dump in a static dtor instead of in an atexit handler PR gcov-profile/7970 PR gcov-profile/16855 PR gcov-profile/44779 * g++.dg/gcov/pr16855.C: New test. * coverage.c (build_gcov_exit_decl): New function. (coverage_obj_init): Call the function and generate __gcov_exit destructor. * doc/gcov.texi: Document when __gcov_exit function is called. * libgcov-driver.c (__gcov_init): Do not register a atexit handler. (__gcov_exit): Rename from gcov_exit. * libgcov.h (__gcov_exit): Declare. Added: trunk/gcc/testsuite/g++.dg/gcov/pr16855.C Modified: trunk/gcc/ChangeLog trunk/gcc/coverage.c trunk/gcc/doc/gcov.texi trunk/gcc/testsuite/ChangeLog trunk/libgcc/ChangeLog trunk/libgcc/libgcov-driver.c trunk/libgcc/libgcov.h
Fixed on trunk.