Following is a simple example that works when the dl library isn't involved
at link time, but fails when it is.
Here are relevant versions:
Linux pile.franz.com 2.0.34 #1 Fri May 8 16:05:57 EDT 1998 i586 unknown
/lib/libc-2.0.7.so
/lib/libc.so.6
/lib/ld.so.1.9.5
Here's how to reproduce the problem:
1. Make a file called ctest.c, containing:
#include <stdio.h>
#include <stdlib.h>
#include <schedbits.h>
int
foo( void *arg )
{
fprintf( stderr, "in foo, pid = %d\n", getpid() );
call_sub();
sleep( 2 );
}
main()
{
void *stk = malloc( 1024 * 1024 );
clone( foo, stk, CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND, 0 );
fprintf( stderr, "in main, pid = %d\n", getpid() );
sleep( 2 );
}
2. Make a file called csub.c, containing:
#include <dlfcn.h>
int call_sub()
{
#ifdef WILL_BREAK_CLONE
dlopen( "somefile", RTLD_LAZY );
#endif
return 0;
}
3. Make sure that LD_LIBRARY_PATH contains the current directory
4. Compile, link, and run to show that it there is no problem with clone()
when the dl library is not involved:
cc -c csub.c
ld -shared -o libcsub.so csub.o
cc -o ctest ctest.c -L. -lcsub
ctest
(You will see:
in main, pid = xxx
in foo, pid = xxx+1)
5. recompile, relink, and rerun to show that clone() fails when the dl
library is involved:
cc -c -DWILL_BREAK_CLONE csub.c
ld -shared -o libcsub.so csub.o -ldl
ctest
(You will see:
in main, pid = xxx) - the cloned thread will have died before running foo...
I would appreciate any information that would help me get around this...
Thanks,
Steve
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/