RFC: [PATCH] Make -static builds work again without crashing
Denys Vlasenko
vda.linux at googlemail.com
Mon Apr 14 11:55:11 UTC 2008
On Monday 14 April 2008 05:06, Maarten Lankhorst wrote:
> Hi all,
>
> 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.
--
vda
More information about the uClibc
mailing list