On Fri, 11 Aug 2017, Mark Kettenis wrote: > The diff below implements __cxa_thread_atexit(). Calls to this function > are emitted by the compiler to schedule running desctructors for > thread_local objects when a thread terminates or calls exit(3). The > Linux implementation prevents unloading of shared libraries that > registered such destructors to prevent things from crashing. This diff > does not implement that functionality yet. I plan to add that later. > I expect this to be a bit of a corner case. > > I've chosen to implement __cxa_thread_atexit() directly instead of > __cxa_thread_atexit_impl(). I think that is cleaner. It means we > don't need to make changes to libc++ for this to start working. It > looks like modern libstdc++ version will detect __cxa_thread_atexit(). > > This adds a member to the "TIB". Tis means that you'll need to > install the new headers and rebuild ld.so before rebuilding libpthread > and libc. > > This will require a libc minor bump. But maybe it could ride the > scheduled major bump?
Either seems fine. Couple comments below... > --- include/tib.h 20 Apr 2017 16:07:52 -0000 1.4 > +++ include/tib.h 11 Aug 2017 14:20:30 -0000 > @@ -135,6 +135,7 @@ > */ > > struct tib { > + void *tib_atexit; > int tib_thread_flags; /* internal to libpthread */ > pid_t tib_tid; > int tib_cantcancel; > @@ -182,6 +183,7 @@ struct tib { > int tib_cantcancel; > pid_t tib_tid; > int tib_thread_flags; /* internal to libpthread */ > + void *tib_atexit; > #if !defined(__LP64__) && !defined(__i386) > int __tib_padding; /* padding for 8byte alignment */ > #endif To keep this structure a multiple of 8 in size, the padding conditionals need to swap around, so that the extra member is only present on i386. HOWEVER, looking again at _dl_tib_allocate(), I already taught it to round up the sizes for correct alignment of the structs! I think __tib_padding can go away now. ... > +DEF_STRONG(__cxa_thread_atexit); ... > +PROTO_NORMAL(__cxa_thread_atexit); It's not actually called inside libc, right? If not, you can delete DEF_STRONG() and use PROTO_STD_DEPRECATED() intead of PROTO_NORMAL() (case IIb1 in libc/include/README) Philip