[Bug gcov-profile/44779] The gcov library does not adequately handle functions with constructor/destructor attributes
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44779 Martin Liška changed: What|Removed |Added Status|REOPENED|RESOLVED Resolution|--- |FIXED --- Comment #9 from Martin Liška --- Fixed on trunk.
[Bug gcov-profile/44779] The gcov library does not adequately handle functions with constructor/destructor attributes
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44779 --- Comment #8 from Martin Liška --- Author: marxin Date: Tue Sep 27 11:07:11 2016 New Revision: 240529 URL: https://gcc.gnu.org/viewcvs?rev=240529=gcc=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
[Bug gcov-profile/44779] The gcov library does not adequately handle functions with constructor/destructor attributes
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44779 Martin Liška changed: What|Removed |Added Status|RESOLVED|REOPENED Resolution|INVALID |--- Assignee|unassigned at gcc dot gnu.org |marxin at gcc dot gnu.org --- Comment #7 from Martin Liška --- Looks I've got working solution for situation 2).
[Bug gcov-profile/44779] The gcov library does not adequately handle functions with constructor/destructor attributes
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44779 Martin Liška changed: What|Removed |Added Status|WAITING |RESOLVED CC||marxin at gcc dot gnu.org Resolution|--- |INVALID --- Comment #6 from Martin Liška --- (In reply to Jay Vaughan from comment #0) > I am developing a software system which has the requirement (as it is > safety-critical), that we report full coverage of our modules as part of the > validation process. > > One aspect of this software system is the inclusion of a library - lets call > it libguardian - which is wrapped around all applications being run on our > custom system, using LD_PRELOAD. The purpose of libguardian is to obtain > valid conditions for continued launch prior to the execution of main() by > the runtime in the wrapped application. To this end, libguardian defines a > constructor and destructor pair of functions that obtain the valid > conditions required for continued launch, and clean up/report on exit of the > application. > > This libguardian, and associated applications, works perfectly fine. > However, it is not possible to capture coverage information for these > functions due to limits in gcov. > > The constructor/destructor methods are defined thus: > > > #define GUARDIAN_CONSTRUCTOR_DESTRUCTOR_PRIORITY 65535 > /* NOTE: this priority can also be 101! */ > > void guardian_constructor(void) __attribute__ > ((constructor(GUARDIAN_CONSTRUCTOR_DESTRUCTOR_PRIORITY))); > > void guardian_destructor(void) __attribute__ > ((destructor(GUARDIAN_CONSTRUCTOR_DESTRUCTOR_PRIORITY))); > > > If the guardian_constructor() finds conditions unsavory for continued > execution in our environment, it exit()'s immediately. In this circumstance, > coverage is lost (or not provided) by gcov's atexit/destructor methods, as > it appears that *priority* of known constructors is not accounted for in the > gcov library, nor is there an atexit() handler that can adequately sort > these priorities. Well, there are two scenarios that happen for your test-case: 1) guardian_constructor exits: as the function is called via LD_PRELOAD, libgcov is not yet registered and cannot produce any *.gcda files. It's unrelated to priorities of dtors/atexit handlers 2) _SHOULD_CONSTRUCTOR_DIE_ is undefined: all works fine except guardian_exiter: LD_PRELOAD=./testlib.so ./testapp ++ GUARDIAN CONSTRUCTOR STAGE: [15226] This is a number between 1 and 10: 1 This is a number between 1 and 10: 2 This is a number between 1 and 10: 3 This is a number between 1 and 10: 4 This is a number between 1 and 10: 5 This is a number between 1 and 10: 6 This is a number between 1 and 10: 7 This is a number between 1 and 10: 8 This is a number between 1 and 10: 9 This is a number between 1 and 10: 10 ** gcov init is called gcov init is called ^^ That was the constructor ^^ This is main() in the testapp() By now, the testlib should have reported its own progress in counting 1 to 10. Next comes the destructor ::: gcov_exit is called -- GUARDIAN DESTRUCTOR STAGE: ** gcov_exit is called !! GUARDIAN EXIT HANDLER REACHED !! gcov testlib.c File 'testlib.c' Lines executed:78.57% of 14 Creating 'testlib.c.gcov' gcov testapp.c File 'testapp.c' Lines executed:100.00% of 3 Creating 'testapp.c.gcov' As you can see, I added dumping of gcov_init/gcov_exit. The only functions which is not seen by coverage is: #: 16:static void guardian_exiter(void) -: 17:{ #: 18:fprintf(stderr, "!! GUARDIAN EXIT HANDLER REACHED !!\n"); #: 19:} That's kind of expected behavior because atexit handlers are executed in reverse order to how they were registered. I would recommend to not utilize atexit handler and do the necessary work in guardian_destructor. Due to aforementioned explanation, I'm closing the PR as invalid.
[Bug gcov-profile/44779] The gcov library does not adequately handle functions with constructor/destructor attributes
--- Comment #1 from rguenth at gcc dot gnu dot org 2010-07-02 09:16 --- Can you provide a testcase that when executed shows the issue? -- rguenth at gcc dot gnu dot org changed: What|Removed |Added Status|UNCONFIRMED |WAITING http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44779
[Bug gcov-profile/44779] The gcov library does not adequately handle functions with constructor/destructor attributes
--- Comment #2 from jay dot vaughan at thalesgroup dot com 2010-07-02 11:29 --- Created an attachment (id=21066) -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21066action=view) Makefile for testcase. This the Makefile for a testunit that will demonstrate this behaviour. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44779
[Bug gcov-profile/44779] The gcov library does not adequately handle functions with constructor/destructor attributes
--- Comment #3 from jay dot vaughan at thalesgroup dot com 2010-07-02 11:30 --- Created an attachment (id=21067) -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21067action=view) This is the test application program sources for the testunit. This file is the test application, to be wrapped by the test library, to demonstrate the behaviour of this bug. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44779
[Bug gcov-profile/44779] The gcov library does not adequately handle functions with constructor/destructor attributes
--- Comment #4 from jay dot vaughan at thalesgroup dot com 2010-07-02 11:31 --- Created an attachment (id=21068) -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21068action=view) This is the test library sources for the testunit. This file is the test library, which is wrapped around the application, to demonstrate the behaviour of this bug. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44779
[Bug gcov-profile/44779] The gcov library does not adequately handle functions with constructor/destructor attributes
--- Comment #5 from jay dot vaughan at thalesgroup dot com 2010-07-02 11:32 --- To use the sources provided as a test unit: 1. First, 'make clean'. 2. Then, 'make test.app' - notice the coverage of the constructor/destructor functions. 3. Then, 'make test.lib' - notice coverage. -- jay dot vaughan at thalesgroup dot com changed: What|Removed |Added CC||jay dot vaughan at ||thalesgroup dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44779