RFC: [PATCH] Make -static builds work again without crashing

Denys Vlasenko vda.linux at googlemail.com
Mon Apr 14 17:47:05 UTC 2008


On Monday 14 April 2008 19:11, Maarten Lankhorst wrote:
>  >  > After some experimenting I came to the conclusion that the minimum app
>  >  > that won't crash with gcc -static is printf("%.0d", 0); which is
>  >  > essentially a noop printf. So my patch calls that before calling main.
>  >  >
>  >  > Looking for feedback on the patch.
>  >
>  >
>  > ?!
>  >
>  >  Ths will force stdio to be linked it into every application.
>  >
>  >  How about fixing the problem instead of papering over it?
>  >
>  >  I think the possible reason is that _stdio_init is a weak symbol:
>  >
>  >  extern void weak_function _stdio_init(void) attribute_hidden;
>  >
>  >  and here we check that it was linked in, only if it was, we run it:
>  >
>  >     /*
>  >      * Initialize stdio here.  In the static library case, this will
>  >      * be bypassed if not needed because of the weak alias above.
>  >      * Thus we get a nice size savings because the stdio functions
>  >      * won't be pulled into the final static binary unless used.
>  >      */
>  >     if (likely(_stdio_init != NULL))
>  >         _stdio_init();
>  >
>  >  But current gcc assumes (and it's allowed by C standard) that function
>  >  address is never NULL. So it optimizes away this if(), and calls
>  >  _stdio_init() unconditionally. If it indeed is NULL, we crash.
> 
> I don't think this is the issue here, if I remove the call to
>  _stdio_init call in __uClibc_init it will still crash.

Just adding bogus printf is still not a solution.

Where it crashes?
--
vda



More information about the uClibc mailing list