[K42-discussion] Cause of cxa_atexit/dso_handle reference

Patrick G. Bridges bridges at cs.unm.edu
Tue Aug 29 03:56:04 EST 2006


On Aug 24, 2006, at 4:23 PM, Bryan S Rosenburg wrote:

>
> Donour Sizemore wrote on 08/24/2006 01:11:58 PM:
> > Bryan S Rosenburg wrote:
> > >
> > > I'm sorry for not being more responsive.  As Orran said, we're  
> really
> > > busy working toward an internal milestone for the next few weeks.
> > >
> > > I'm still in favor of avoiding global objects on general  
> principles, but
> > > not if it involves solving too many case-by-case problems.  I  
> think the
> > > particular DeletedObject case can be solved with a dynamic  
> allocation
> > > using the "primitive" memory allocator.  I've attached a patch  
> below.
> > >  The patch compiles, but I haven't tested it, and I certainly  
> haven't
> > > verified that it avoids the cxa_atexit requirement.
> > >
> > > If there are too many cases, or if there are cases that can't  
> be easily
> > > resolved, I'd fall back on providing a cxa_atexit() that  
> doesn't do
> > > anything.  There's really no point in recording the cleanup  
> functions
> > > when there's no code that will ever call them.
> > >
> > > Here's the patch for dynamically allocating theDeletedObj:
> > >
> >
> > I just tried this patch, but gcc still emits the __cxa_atexit  
> symbol. I
> > have a solution that adds the aforementioned empty atexit function,
> > along with the necessary changes to makefiles. I'll post it shortly.
>
> My patch fixed just one example of a global object that now has a  
> destructor.  No one expected the patch to all by itself eliminate  
> all references to __cxa_atexit.

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();
}
bridges at milhouse:~$ gcc -c test.cc
bridges at milhouse:~$ nm test.o
00000000 B bar
          U __cxa_atexit **********************************
          U __dso_handle **********************************
000000be t _GLOBAL__I_bar
          U __gxx_personality_v0
00000000 T main
000000aa t __tcf_0
          U _Unwind_Resume
0000006a t _Z41__static_initialization_and_destruction_0ii
          U _ZdlPv
00000000 W _ZN3FooC1Ev
00000000 V _ZNSt15basic_streambufIcSt11char_traitsIcEE13_S_pback_sizeE
00000000 V _ZNSt15basic_streambufIwSt11char_traitsIwEE13_S_pback_sizeE
          U _ZNSt8ios_base4InitC1Ev
          U _ZNSt8ios_base4InitD1Ev
          U _Znwj
          U _ZSt4cout
00000004 b _ZSt8__ioinit
          U _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc




More information about the K42-discussion mailing list