[lsb-discuss] atexit()

Nick Stoughton nick at usenix.org
Fri Oct 19 10:31:29 PDT 2007

On Fri, 2007-10-19 at 10:08 -0400, Robert Schweikert wrote:
> I ran a quick trial and there is definitely some magic going on with 
> gcc. The magic happens at link time. Consider the following simple code:
> -> cat atExistTest.c
> #include <stdlib.h>
> void myExitFunc()
> {
> }
> int callExitFunc()
> {
>     return atexit(myExitFunc);
> }
> When compiled to an object file the atexit() call remains:
> -> nm -Bg atExistTest.o | grep atexit
>                  U atexit

Try readelf -a:
$ readelf -a exittest | grep atexit
08049698  00000107 R_386_JUMP_SLOT   00000000   __cxa_atexit
     1: 00000000    87 FUNC    GLOBAL DEFAULT  UND
__cxa_atexit at GLIBC_2.1.3 (2)
    47: 00000000    87 FUNC    GLOBAL DEFAULT  UND
    56: 08048480    61 FUNC    GLOBAL HIDDEN   12 atexit

> taking this a step further to the assembly level atexit still shows up.
> ->  cat atExistTest.s | grep atexit
>         call    atexit
Glibc hides the atexit symbol (using a .hidden asm directive) so that no
definition but the one locally in the executable or DSO is used. This
directive overrides the default visibility (which is set normally set by
the symbol's binding: local, global or weak).  The .hidden directive
sets the visibility to `hidden' which means that the symbols are not
visible to other components.  

> However, once we generate the executable (or so) the plain atexit 
> disappears:
> -> nm -Bg atexitLib.so | grep atexit
>                  U __cxa_atexit@@GLIBC_2.2.5
> Thus atexit() appears to have a weird state with respect to the LSB 
> specification, looks like we should map the atexit() source interface to 
> __cxa_atexit binary interface w.r.t. appchk. I don't like specifying 
> anything starting with __ but we may not have a choice here since the 
> symbol does show up and appchk would certainly complain.

atexit() should be a source only function, with __cxa_atexit as a binary
only (it already is, and has been in the LSB since 1.0 I believe, though
I rewrote the page for 1.3). Interestingly, we (I) made a mistake on the
__cxa_atexit page, where we (I) claim "Note: atexit() is not in the
binary standard; it is only in the source standard." ... atexit is not
in 3.1!

> Robert

More information about the lsb-discuss mailing list