Bug in __register_exitproc() in __atexit.c
Jeff Johnston
jjohnstn@redhat.com
Mon Dec 21 18:01:00 GMT 2015
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
More information about the Newlib
mailing list