[patch] Move __libc_fini_array into a separate file.

Jeff Johnston jjohnstn@redhat.com
Tue Jun 8 20:06:00 GMT 2010


I've made the register_fini function optional based on the 
_WANT_REGISTER_FINI flag.  This flag can be set at configuration time 
via the newly added --enable-newlib-register-fini option.  It can also 
be set manually if desired.

This should fix the problem and allow the new functionality where desired.

If there are any problems, please let me know.

2010-06-08  Jeff Johnston  <jjohnstn@redhat.com>

         * configure.in: Add test for enable-newlib-register-fini
         to set the _WANT_REGISTER_FINI flag.
         * configure: Regenerated.
         * Makefile.in: Ditto.
         * newlib.hin: Add _WANT_REGISTER_FINI flag.
         * libc/stdlib/__call_atexit.c: Add test for
         _WANT_REGISTER_FINI to enable the register_fini function.

-- Jeff J.

On 06/08/2010 11:18 AM, Corinna Vinschen wrote:
> On Jun  4 11:31, Jeff Johnston wrote:
>> On 06/03/2010 06:57 PM, Mark Mitchell wrote:
>>> Jeff Johnston wrote:
>>>> What calls the new static routine register_fini??  I don't see anything
>>>> using it in this patch.
>>>
>>>>> +static void
>>>>> +register_fini(void) __attribute__((constructor (0)));
>>>
>>> It's a constructor function.
>>>
>>> Thanks,
>>>
>>
>> Ah.  Patch applied.
>
> This patch breaks building Cygwin.  When building from scratch, I'm
> getting this error message now:
>
>    Creating library file: cygdll.a
>    /ext/build/cygwin/src/i686-pc-cygwin/newlib/libc/libc.a(lib_a-__call_atexit.o):
>    In function `register_fini':
>    /home/corinna/src/cygwin/src/newlib/libc/stdlib/__call_atexit.c:49: undefined re
>    ference to `__fini'
>    collect2: ld returned 1 exit status
>
> The problem is this.  In the former code, newlib only referenced _fini
> if HAVE_INITFINI_ARRAY was defined.  If it wasn't defined, none of the
> code in libc/misc/init.c was complied in.
>
> Now, with the new code, _fini() is *always* referenced, even on systems
> which don't define HAVE_INITFINI_ARRAY:
>
>    libc/stdlib/__call_atexit.c:
>
>      static void
>      register_fini(void)
>      {
>        if (&__libc_fini) {
>      #ifdef HAVE_INITFINI_ARRAY
> 	extern void __libc_fini_array (void);
> 	atexit (__libc_fini_array);
>      #else
> 	extern void _fini (void);
> 	atexit (_fini);
>      #endif
>        }
>      }
>
> AFAICS, the #else part of the conditional code just has to go away.
>
> However, I'm not an expert in this stuff, so what do other's think
> is the right solution?
>
>
> Corinna



More information about the Newlib mailing list