__cxa_atexit and __cxa_finalize implementation

Peter S. Mazinger ps.m at gmx.net
Fri Sep 16 12:44:29 UTC 2005


On Fri, 16 Sep 2005, Peter S. Mazinger wrote:

> On Thu, 15 Sep 2005, Stephen Warren wrote:
> 
> Attached are my patches:
> nonshared:
> -adds support generally for any files to uclibc_nonshared.a
> -creates the needed linker script
> -it does not check for existence of files (fails if no nonshared_obj.* 
> file is present)
> 
> atexit:
> adds atexit to nonshared lib, applies after the cxa_atexit... patch
> 
> Be aware, this will for sure kill most of the apps (all that used atexit() 
> ) it will be an incompatible change to uClibc.

I have "created" a compat old_atexit (really a copy of the new atexit, 
but not hidden), with weak_alias to atexit (that could allow updating)

How will the linker script react for newly built binaries?
/* GROUP ( /lib/libc.so.0 /usr/lib/uclibc_nonshared.a )
Will the weak atexit from libc.so.0 be taken, or the hidden atexit from 
nonshared.a? I am hoping for the latter case ...

Peter
> 
> > Peter S. Mazinger wrote:
> > > On Thu, 15 Sep 2005, Stephen Warren wrote:
> > > 
> > >>Peter S. Mazinger wrote:
> > >>
> > >>>>>Please redo your patch as follows:
> > >>>>>1. the functions that have to go into *libc_nonshared.a should be in 
> > >>>>>separate objects (ifdef L_* is ok, if you use the same source)
> > >>>>>2. for hiding use attribute_hidden (it takes care of the case that gcc 
> > >>>>>does not support it, then it becomes visible)
> > >>>>
> > >>>>Sounds great. I'll try to work on this soon:-)
> > >>
> > >>Found a few minutes during a build. Attached is the latest patch.
> > >>
> > >>Item 1 on your list was already in place - libc/stdlib/atexit.o wants to
> > >>go in the new .a file. (This comes from libc/stdlib/atexit.c with
> > >>L_atexit defined). Everything else built from that .c file can go in
> > >>"libc.so"
> > > 
> > > should atexit.o go also into libc.so or only into nonshared.a?
> > > (if libc uses it itself, then it should also go into libc.so)
> > 
> > grep says libc.so doesn't use atexit internally, except for possibly
> > some stuff in these files
> > 
> > libc/sysdeps/linux/m68k/crt0.S
> > libc/sysdeps/linux/h8300/crt0.S
> > libc/sysdeps/linux/nios/crt0.c (same stuff, but commented)
> > 
> > For example (from 68k):
> > 
> > /*
> >  *      this was needed for gcc/g++-builds,  atexit was not getting included
> >  *      for some stupid reason,  this gets us a compiler
> >  */
> > empty_func:
> >         rts
> > #if defined(__HAVE_ELF__)
> >         .weak atexit
> >         atexit = empty_func
> > #else
> >         .set atexit,empty_func
> > #endif
> > 
> > I have no idea what this does or why!
> > 
> 
> 

-- 
Peter S. Mazinger <ps dot m at gmx dot net>           ID: 0xA5F059F2
Key fingerprint = 92A4 31E1 56BC 3D5A 2D08  BB6E C389 975E A5F0 59F2
-------------- next part --------------
--- uClibc-0.9.28/libc/stdlib/atexit.c.mps	2005-09-16 14:26:28 +0200
+++ uClibc-0.9.28/libc/stdlib/atexit.c	2005-09-16 14:29:02 +0200
@@ -101,14 +101,19 @@
 extern int __cxa_atexit (cxaefuncp, void *arg, void *dso_handle);
 
 
-#ifdef L_atexit
+/* remove old_atexit after 0.9.29 */
+#if defined(L_atexit) || defined(L_old_atexit)
 extern void *__dso_handle __attribute__ ((__weak__));
 
 /*
  * register a function to be called at normal program termination
  * (the registered function takes no arguments)
  */
+#ifdef L_atexit
 int attribute_hidden atexit(aefuncp func)
+#else
+int old_atexit(aefuncp func)
+#endif
 {
     /*
      * glibc casts aefuncp to cxaefuncp.
@@ -118,6 +123,9 @@
     return __cxa_atexit((cxaefuncp)func, NULL,
                         &__dso_handle == NULL ? NULL : __dso_handle);
 }
+#ifndef L_atexit
+weak_alias(old_atexit,atexit);
+#endif
 #endif
 
 #ifdef L_on_exit
--- uClibc-0.9.28/libc/stdlib/Makefile.mps	2005-09-16 14:28:40 +0200
+++ uClibc-0.9.28/libc/stdlib/Makefile	2005-09-16 14:20:05 +0200
@@ -79,7 +79,7 @@
 # wcstod wcstof wcstold
 
 MSRC2 = atexit.c
-MOBJ2 = on_exit.o __cxa_atexit.o __cxa_finalize.o __exit_handler.o exit.o
+MOBJ2 = old_atexit.c on_exit.o __cxa_atexit.o __cxa_finalize.o __exit_handler.o exit.o
 
 CSRC = \
 	abort.c getenv.c mkdtemp.c mktemp.c realpath.c mkstemp.c mkstemp64.c \


More information about the uClibc mailing list