[uClibc]setjmp() and dynamic loading segfault

michaels at jungo.com michaels at jungo.com
Sun Mar 4 13:38:37 UTC 2001


hello,

Lately I was seeing some segfaults for dynamically linked code that uses
setjmp() and longjmp() codes. Statically linked code doesn't exibit this
weirdness. Attached is the source code. Following is the example
session: 
-------
 Static vs uClibc:
 
../../extra/gcc-uClibc/gcc-uClibc-i386  -Os  -g -c setjmp.c -o setjmp.o
../../extra/gcc-uClibc/gcc-uClibc-i386 -Wl,-warn-common  --static
setjmp.o -o setjmp
/bin/true -Since_we_are_debugging -x -R .note -R .comment setjmp
./setjmp
in foo()
in bar
after longjmp, returned 1
make: [setjmp] Error 1 (ignored)
-------                                                                                
Dynamic vs uClibc:
../../extra/gcc-uClibc/gcc-uClibc-i386  -Os  -g -c setjmp.c -o setjmp.o
../../extra/gcc-uClibc/gcc-uClibc-i386 -Wl,-warn-common  setjmp.o -o
setjmp
/bin/true -Since_we_are_debugging -x -R .note -R .comment setjmp
./setjmp
make[1]: *** [setjmp] Segmentation fault

-------

Dynamic vs GNU libc:

gcc  -Os  -g -c setjmp.c -o setjmp_glibc.o
gcc -Wl,-warn-common  setjmp_glibc.o -o setjmp_glibc
/bin/true -Since_we_are_debugging -x -R .note -R .comment setjmp_glibc
./setjmp_glibc
in foo()
in bar
after longjmp, returned 1
make[1]: [setjmp_glibc] Error 1
(ignored)                                                                               
-- 
[michaels at kobie signal]$ ldd setjmp
        libuClibc.so.1 => /lib/libuClibc.so.1 (0x40017000)
        ld-linux.so.1 => /lib/ld-linux.so.1
(0x4006d000)                        
[michaels at kobie signal]$ ldd setjmp_glibc
        libc.so.6 => /lib/libc.so.6 (0x40023000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2
(0x40000000)                   


Sincerely yours,
Michael Shmulevich
______________________________________
Software Developer
Jungo - R&D 
email: michaels at jungo.com
web: http://www.jungo.com
Phone: 1-877-514-0537(USA)  +972-9-8859365(Worldwide) ext. 233
Fax:   1-877-514-0538(USA)  +972-9-8859366(Worldwide)
-------------- next part --------------
#include <stdio.h>
#include <setjmp.h>
static jmp_buf jmp_env;

int foo();
int bar();

int main(int argc, char* argv[])
{
    int res;
    
    res = setjmp(jmp_env);
    if(res)
    {
	printf("after longjmp, returned %d\n", res);
	return res;
    }
    
    return foo();
}

int foo()
{
    printf("in foo()\n");
    return bar();
}

int bar()
{
    printf("in bar\n");
    longjmp(jmp_env, 1);

    return 0;
}


More information about the uClibc mailing list