Bug in __register_exitproc() in __atexit.c
Tue Dec 22 02:53:00 GMT 2015
Enjoy your vacation Jeff. It has been a busy year for newlib.
Personally I am very happy to see Cygwin and RTEMS share more in newlib as well as the FreeBSD alignment. It helps increase the number of configurations using the same lines of code. And that has positive impacts.
On December 21, 2015 10:55:50 AM CST, Jeff Johnston <email@example.com> wrote:
>Thanks Freddie. Patches applied. I hope to cut the yearly snapshot
>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
>> > it
>> > called __on_exit_args. (see libc/reent/impure.c for an example of
>> > is done for the reent struct).
>> > In __register_exitproc, declare it as weak and refer to it when
>> > to the flags.
>> > In on_exit and __cxa_exit, use the flags to determine when to
>> > 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
>> > configured with the flags. Other applications will not get the
>> > 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
>> used, then the static instance of _on_exit_args struct is not linked.
>> either on_exit() or __cxa_atexit() are used, then the static instance
>> linked into the executable.
>> The static instance of _on_exit_args struct is used when "small
>> configuration is used. In theory it could be limited to "reent small"
>> dynamic allocation in atexit()", but the approach I took seemed more
>> appropriate. on_exit()'s description in newlib's docs says that there
>> statically allocated slots, so with this fix this is really true for
>> I attach two patches that implement relevant changes - the first one
>> 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
>> identical to what I sent previously, but with changed commit message
>> no problem with _on_exit_args after the first patch is applied).
>> I've verified that all 8 combinations of relevant options (reent
>> dynamic alloc in atexit, global atexit) can be compiled.
More information about the Newlib