[K42-discussion] Cause of cxa_atexit/dso_handle reference

Bryan S Rosenburg rosnbrg at us.ibm.com
Tue Aug 29 04:28:57 EST 2006


Patrick Bridges wrote on 08/28/2006 01:56:04 PM:
> 
> I think Donour's point was that your patch doesn't prevent gcc from 
> generating the reference to cxa_atexit. Simply making the object at 
> runtime doesn't get rid of the call to cxa_atexit. Any global 
> *reference* to an object with a destructor appears to generate a call 
> to cxa_atexit and the associated reference to dso_handle. Consider 
> the following example:
> 
> bridges at milhouse:~$ cat test.cc
> #include <iostream>
> using namespace std;
> 
> class Foo {
>      public:
>          Foo() { cout << "hello from my constructor"; }
>          ~Foo() { cout << "hello from my destructor"; }
> };
> 
> Foo *bar;
> 
> int main(int argc, char **argv) {
> 
>          bar = new Foo();
> }

I'm ready to give up on this battle and go with an empty cxa_atexit.

But I don't think there's any way the compiler can generate code that 
makes an exit-time call to a destructor for an object that is merely 
referenced by a global variable.  How could the compiler possibly know 
that the object still exists when the program exits?

I think the calls to cxa_atexit in your test program result from the use 
of <iostream> and cout.

As I said, I'm willing to give up on eliminating global objects.  I'd be 
happier, though, if we at least knew the magnitude of the problem.  How 
many object files in the build tree have references to cxa_atexit?

- Bryan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ozlabs.org/pipermail/k42-discussion/attachments/20060828/15fff915/attachment.htm 


More information about the K42-discussion mailing list