segfault with static programs that don't use stdio functions

Denys Vlasenko vda.linux at googlemail.com
Fri Dec 12 13:54:03 UTC 2008


On Thu, Dec 11, 2008 at 1:57 AM, Denys Vlasenko
<vda.linux at googlemail.com> wrote:
> 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.

I saw it sometime ago, but now can't reproduce it.
My assembly shows (make libc/misc/internals/__uClibc_main.s):

        movl    $_stdio_init, %eax
        testl   %eax, %eax
        je      .L12
        jmp     _stdio_init
.L12:
        ret

So, it can be gcc issue (maybe it was fixed to understand that weak
symbols _can_ be NULL despite what C standard says), or it is
affected by uclibc .config

Can you run "make libc/misc/internals/__uClibc_main.i"
and send resulting file to me, along with "gcc -v" output?
Mine are:

# i486-linux-uclibc-gcc -v
Using built-in specs.
Target: i486-linux-uclibc
Configured with: ../gcc-4.3.1/configure
--prefix=/usr/app/gcc-4.3.1-i486-linux-uclibc
--exec-prefix=/usr/app/gcc-4.3.1-i486-linux-uclibc
--bindir=/usr/app/gcc-4.3.1-i486-linux-uclibc/bin
--sbindir=/usr/app/gcc-4.3.1-i486-linux-uclibc/sbin
--libexecdir=/usr/app/gcc-4.3.1-i486-linux-uclibc/libexec
--datadir=/usr/app/gcc-4.3.1-i486-linux-uclibc/share--sysconfdir=/etc
--sharedstatedir=/usr/app/gcc-4.3.1-i486-linux-uclibc/var/com
--localstatedir=/usr/app/gcc-4.3.1-i486-linux-uclibc/var
--libdir=/usr/app/gcc-4.3.1-i486-linux-uclibc/lib
--includedir=/usr/app/gcc-4.3.1-i486-linux-uclibc/include
--infodir=/usr/app/gcc-4.3.1-i486-linux-uclibc/info
--mandir=/usr/app/gcc-4.3.1-i486-linux-uclibc/man --disable-nls
--with-local-prefix=/usr/local
--with-slibdir=/usr/app/gcc-4.3.1-i486-linux-uclibc/lib
--target=i486-linux-uclibc --with-gnu-ld
--with-ld=/usr/bin/i486-linux-uclibc-ld --with-gnu-as
--with-as=/usr/bin/i486-linux-uclibc-as
--with-sysroot=/usr/cross/i486-linux-uclibc --enable-languages=c,c++
--disable-shared --disable-threads --disable-tls --disable-libgomp
Thread model: single
gcc version 4.3.1 (GCC)

See attached __uClibc_main.i.c, it is the result of
"make libc/misc/internals/__uClibc_main.i" renamed to have .c
extension, and when I compile it to asm:

# i486-linux-uclibc-gcc -Os -fomit-frame-pointer -S __uClibc_main.i.c
<built-in>:1:1: warning: "__STDC__" redefined
<built-in>: warning: this is the location of the previous definition
<built-in>:3:1: warning: "__STDC_HOSTED__" redefined
<built-in>: warning: this is the location of the previous definition

I see in __uClibc_main.i.s:

__GI___uClibc_init:
        cmpb    $0, been_there_done_that.3164
        jne     .L12
        movb    $1, been_there_done_that.3164
        movl    $4096, __pagesize
        movl    $_stdio_init, %eax
        testl   %eax, %eax
        je      .L12
        jmp     _stdio_init
.L12:
        ret

Please do the same steps, and post results.
--
vda
-------------- next part --------------
A non-text attachment was scrubbed...
Name: __uClibc_main.i.c.bz2
Type: application/x-bzip2
Size: 36667 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/uclibc/attachments/20081212/7fbf87a4/attachment-0002.bin 


More information about the uClibc mailing list