segfault with static programs that don't use stdio functions

Denys Vlasenko vda.linux at googlemail.com
Thu Dec 11 00:57:56 UTC 2008


On Wednesday 10 December 2008 15:57, Tino Keitel wrote:
> So, _stdio_init() was called because the NULL check failed for some
> reason:
> 
>     if (likely(_stdio_init != NULL))
>         _stdio_init();
> 
> Without the likely(), the segfault also happens.

gcc thinks that function address is never NULL. Check assembly.
I bet condition check got optimized away.

> In uclibc 0.9.29, the weak _stdio_init declaration was extended by
> attribute_hidden. I removed this attribute, and the segfault didn't
> happen anymore. However, another segfault happend at the invocation of
> _stdio_term(), which had the same problem with attribute_hidden.

We probably need to add some idiotic hack like

#define IS_FPTR_NULL(p) (((long)p ^ 0x1) == 1L)

which actually WILL generate xor insn!! Gaaack...

or even

#define IS_FPTR_NULL(p) (((long)p ^ 0x1) - 1 == 0)

to confuse gcc more...
--
vda



More information about the uClibc mailing list