link and run against another libc

Mathieu Lacage Mathieu.Lacage@sophia.inria.fr
Fri Jan 14 15:38:00 GMT 2005


hi,

I am trying to link and run my threaded program against a libc I built
somewhere on my system but which I did not install (it has been built
with, theoretically, the _exact_ same options used by the libc on my FC3
system since I did copy the build command from the spec file of the FC3
source rpm. I also used the patched source from the FC3 glibc rpm).

I build my program with the following command:
cc  -nostdlib -L/lib -ldl -Wl,-rpath 
-Wl,/usr/src/redhat/BUILD/glibc-20041021T0701/objdir/bins 
-L/usr/src/redhat/BUILD/glibc-20041021T0701/objdir/bins -lc 
-lpthread  -lthread_db 
/usr/src/redhat/BUILD/glibc-20041021T0701/objdir/bins/csu/crt1.o 
/usr/src/redhat/BUILD/glibc-20041021T0701/objdir/bins/csu/elf-init.o 
/usr/src/redhat/BUILD/glibc-20041021T0701/objdir/bins/csu/crti.o 
-o thread-db-test thread-db-test.o

The resulting binary shows this:
[mlacage@chronos profiler]$ ldd thread-db-test
        libdl.so.2 => /usr/src/redhat/BUILD/glibc-20041021T0701/objdir/bins/libdl.so.2 (0x00519000)
        libc.so.6 => /usr/src/redhat/BUILD/glibc-20041021T0701/objdir/bins/libc.so.6 (0x00eca000)
        libpthread.so.0 => /usr/src/redhat/BUILD/glibc-20041021T0701/objdir/bins/libpthread.so.0 (0x00111000)
        libthread_db.so.1 => /usr/src/redhat/BUILD/glibc-20041021T0701/objdir/bins/libthread_db.so.1 (0x00737000)
        /lib/ld-linux.so.2 (0x00394000)

If I try to run the binary, I get a segfault which appears (as claimed
by gdb) to be located in 

#0  0x08048115 in ?? ()
#1  0x00fe35fc in __pthread_initialize_minimal_internal () at init.c:322
#2  0x00fe32c8 in call_initialize_minimal () from /usr/src/redhat/BUILD/glibc-20041021T0701/objdir/bins/libpthread.so.0
#3  0x00fe2e84 in _init () from /usr/src/redhat/BUILD/glibc-20041021T0701/objdir/bins/libpthread.so.0
#4  0x00aafe8c in _dl_init (main_map=0xab94e0, argc=1, argv=0xfefdad74, env=0xfefdad7c) at dl-init.c:70
#5  0x00aa57f5 in ?? () at rtld.c:577 from /lib/ld-linux.so.2

I tried to find a way to set the elf interpreter to use for that binary
to use the one I just built (to avoid the dependency on /lib/ld-
linux.so) but I found no way to do this except by writing my own link
file and I don't feel ready to do that yet.

Would someone mind help me to find out what I did wrong ? 

It might help to say that my ultimate goal is to use a set of
(libc/libpthread/libthread_db) libraries with debugging symbols. It
appears that the debuginfo packages provided with my FC3 (namely, glibc-
debuginfo-common-2.3.3-74 and glibc-debuginfo-2.3.3-74) are not used by
the gdb installed despite this:
[mlacage@chronos nptl_db]$ rpm -ql glibc-debuginfo-2.3.3-74|grep pthread
/usr/lib/debug/lib/libpthread-0.10.so.debug
/usr/lib/debug/lib/libpthread.so.0.debug
/usr/lib/debug/lib/tls/i486/libpthread-2.3.3.so.debug
/usr/lib/debug/lib/tls/i486/libpthread.so.0.debug
[mlacage@chronos nptl_db]$ rpm -ql glibc-debuginfo-2.3.3-74|grep thread_db
/usr/lib/debug/lib/libthread_db-1.0.so.debug
/usr/lib/debug/lib/libthread_db.so.1.debug
/usr/lib/debug/lib/tls/i486/libthread_db-1.0.so.debug
/usr/lib/debug/lib/tls/i486/libthread_db.so.1.debug

I get this:
[mlacage@chronos profiler]$ readelf -s thread-db-test|grep thread
     8: 00000000   387 FUNC    GLOBAL DEFAULT  UND pthread_create@GLIBC_2.1 (4)
    22: 00000000   123 FUNC    GLOBAL DEFAULT  UND pthread_self@GLIBC_2.0 (2)
    50: 00000000     0 FILE    LOCAL  DEFAULT  ABS thread-db-test.c
    57: 0804939a    73 FUNC    LOCAL  DEFAULT   12 thread_cb
   102: 00000000   387 FUNC    GLOBAL DEFAULT  UND pthread_create@@GLIBC_2.1
   129: 00000000   123 FUNC    GLOBAL DEFAULT  UND pthread_self@@GLIBC_2.0
[mlacage@chronos profiler]$ gdb ./thread-db-test
GNU gdb Red Hat Linux (6.1post-1.20040607.43rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/i686/libthread_db.so.1".
 
(gdb) b main
Breakpoint 1 at 0x80493ff: file thread-db-test.c, line 334.
(gdb) r
Starting program: /home/mlacage/profiler/thread-db-test
[Thread debugging using libthread_db enabled]
[New Thread -151099712 (LWP 13650)]
[Switching to Thread -151099712 (LWP 13650)]
 
Breakpoint 1, main (argc=1, argv=0xfef4b7b4) at thread-db-test.c:334
334             ta = start_db ();
(gdb) b pthread_create
Function "pthread_create" not defined.
Make breakpoint pending on future shared library load? (y or [n])

Is there something I did really stupid ? I am a bit at a loss I must
say.

regards,
Mathieu
-- 



More information about the Libc-alpha mailing list