This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: Bug in __register_exitproc() in __atexit.c
- From: Jeff Johnston <jjohnstn at redhat dot com>
- To: Freddie Chopin <freddie_chopin at op dot pl>
- Cc: newlib at sourceware dot org
- Date: Mon, 21 Dec 2015 11:55:50 -0500 (EST)
- Subject: Re: Bug in __register_exitproc() in __atexit.c
- Authentication-results: sourceware.org; auth=none
- References: <2471870 dot RvHy4mPbXA at infernus> <2274723 dot ifptzzOHlV at infernus> <898376226 dot 41789490 dot 1450304723705 dot JavaMail dot zimbra at redhat dot com> <1523649 dot Yj9FtBBTXT at infernus>
Thanks Freddie. Patches applied. I hope to cut the yearly snapshot either today
or tomorrow before I leave on vacation.
-- Jeff J.
----- Original Message -----
> On Wednesday 16 of December 2015 17:25:23 Jeff Johnston wrote:
> > Use the same tactic that is used in __atexit.c.
> >
> > Declare a static structure in a new .c file and create a const pointer to
> > it
> > called __on_exit_args. (see libc/reent/impure.c for an example of how this
> > is done for the reent struct).
> >
> > In __register_exitproc, declare it as weak and refer to it when needed due
> > to the flags.
> >
> > In on_exit and __cxa_exit, use the flags to determine when to declare a
> > dummy global variable such that you have:
> >
> > #if defined(FLAGS_NEEDED...)
> > const void *__some_dummy_var = &__on_exit_args;
> > #endif
> >
> > Applications that link in on_exit or __cxa_exit will drag in the struct if
> > configured with the flags. Other applications will not get the added bloat
> > of the struct.
> >
> > I have a simple example library if it is still unclear.
>
> OK, I've done it as described by Jeff and it works (; When only atexit() is
> used, then the static instance of _on_exit_args struct is not linked. When
> either on_exit() or __cxa_atexit() are used, then the static instance is
> linked into the executable.
>
> The static instance of _on_exit_args struct is used when "small reent"
> configuration is used. In theory it could be limited to "reent small" and "no
> dynamic allocation in atexit()", but the approach I took seemed more
> appropriate. on_exit()'s description in newlib's docs says that there are 32
> statically allocated slots, so with this fix this is really true for all
> configurations.
>
> I attach two patches that implement relevant changes - the first one actually
> adds the static instance of _on_exit_args struct, while the second one is a
> fix for malloc() usage in __register_exitproc(). The second patch is mostly
> identical to what I sent previously, but with changed commit message (there's
> no problem with _on_exit_args after the first patch is applied).
>
> I've verified that all 8 combinations of relevant options (reent small,
> dynamic alloc in atexit, global atexit) can be compiled.
>
> Regards,
> FCh