uclibc: weak symbols -> SEGV

Rich Felker dalias at aerifal.cx
Sat Dec 30 03:18:15 UTC 2006


On Sat, Dec 30, 2006 at 02:20:05AM +0100, Denis Vlasenko wrote:
> > > A little bug hunting session shows that it dies exactly
> > > here in __uClibc_init:
> > > 
> > >     if (likely(_locale_init!=NULL))
> > >         _locale_init();
> > 
> > More data points: SEGV happens when it tries to do the actual call.
> > In other words - this code:
> > 
> >     if (likely(_locale_init!=NULL))
> > {_exit(95);
> >         _locale_init();
> > }
> > 
> > exits without SEGV. With _exit() removed it SEGVs despite another
> > _exit() sitting right there at the very start of _locale_init()
> 
>     if (likely(_locale_init!=NULL))
> {
> void *p = _locale_init;
> write(1, &p, 4);
> _exit(95);
>         _locale_init();
> }
> 
> Compiling with -S reveals that if() is optimized to if(1) -
> gcc thinks that _locale_init is never NULL. But it is -
> write() outputs four zero bytes if I compile and run this...

gcc is correct on this. In the C language, the address of a variable
or function can never compare equal to the null pointer. These weak
symbol hacks are disgusting abuses of ELF symantics which _happened_
to work with old versions of gcc, nothing more...

Rich



More information about the busybox mailing list