This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: shared lib problem with atexit
Thanks, H.J. and Ulrich for explaining.
Ulrich Drepper wrote:
> Kick the qt people. They most definitely have built the DSO without
> linking with libc.
Actually, "objdump -p" shows that all involved libraries depend on libc.so.6.
So this cannot be the cause. libqt is created via "g++ -shared", and
libX11 via "gcc -shared".
Here is a testcase. On a glibc-2.1.x system, in /root, create the following
source files.
================= low.c =================
void low ()
{
}
================= high.c =================
#include <stdlib.h>
extern void low ();
void high_nop ()
{
}
void high ()
{
atexit (high_nop);
low ();
}
================= main.c =================
extern void high ();
int main ()
{
high ();
return 0;
}
==========================================
Then, on the glibc-2.1.x system:
# cd /root
# gcc -shared -O -Wall low.c -o liblow.so
# gcc -shared -O -Wall -L/root -llow -Wl,-rpath,/root high.c -o libhigh.so
# LD_LIBRARY_PATH=/root gcc -L/root -lhigh main.c -o main
# LD_LIBRARY_PATH=/root ./main && echo ok
ok
# nm liblow.so | grep atexit
U atexit@@GLIBC_2.0
# objdump -p liblow.so | grep NEEDED
NEEDED libc.so.6
# objdump -p libhigh.so | grep NEEDED
NEEDED liblow.so
NEEDED libc.so.6
Copy the files to a glibc-2.2.3 system under /root.
# ./main
./main: error while loading shared libraries: cannot open shared object file: cannot load shared object file: No such file or directory
Note the error message is wrong. It should read
./main: error while loading shared libraries: libhigh.so: No such file or directory
# LD_LIBRARY_PATH=/root ./main && echo ok
ok
# gcc -shared -O -Wall low.c -o liblow.so
# LD_LIBRARY_PATH=/root ./main && echo ok
ok
# LD_LIBRARY_PATH=/root gcc -L/root -lhigh main.c -o main
/root/liblow.so: undefined reference to `atexit'
collect2: ld returned 1 exit status
# nm liblow.so | grep atexit
U atexit
# objdump -p liblow.so | grep NEEDED
NEEDED libc.so.6
# objdump -p libhigh.so | grep NEEDED
NEEDED liblow.so
NEEDED libc.so.6
It looks like an ld bug to me. If the runtime linker can resolve 'atexit'
from liblow.so to 'atexit@GLIBC_2.0' in libc.so.6, why doesn't ld do the
same when 'main' is linked?
This occurs with both ld-2.9.5.0.24 and ld-2.10.0.18.
Note: This is not a _compatibility_ bug; you can reproduce the error by
doing the following on the glibc-2.2.3 system, without resorting to a
glibc-2.1.x system:
# cd /root
# gcc -shared -O -Wall low.c -o liblow.so
# gcc -shared -O -Wall -L/root -llow -Wl,-rpath,/root high.c -o libhigh.so
# LD_LIBRARY_PATH=/root gcc -L/root -lhigh main.c -o main
/root/liblow.so: undefined reference to `atexit'
collect2: ld returned 1 exit status
Bruno