Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 75914 - dlopen doesn't search RUNPATH
Summary: dlopen doesn't search RUNPATH
Status: RESOLVED DUPLICATE of bug 73003
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-28 07:07 UTC by Jacek Sieka
Modified: 2005-07-17 13:06 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Testcase (test.tar.bz2,515 bytes, application/octet-stream)
2004-12-28 07:08 UTC, Jacek Sieka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jacek Sieka 2004-12-28 07:07:41 UTC
man dlopen states (amongst other things):

* (ELF only) If the executable file for the calling program contains a DT_RUNPATH tag, then the directories listed in that tag are searched.

Running the attached c program that calls dlopen gives the error:
test1: test2.so: cannot open shared object file: No such file or directory

Running the same application with "LD_LIBRARY_PATH=. ./test11" runs just fine.

objdump -x test11 | grep RUNPATH gives:
  RUNPATH     /home/arnetheduck/tmp/

which seems correct, while "LD_DEBUG=libs ./test11":

      8790:     find library=libdl.so.2; searching
      8790:      search path=/home/arnetheduck/tmp/tls/x86_64:/home/arnetheduck/tmp/tls:/home/arnetheduck/tmp/x86_64:/home/arnetheduck/tmp              (RUNPATH from file ./test11)
      8790:       trying file=/home/arnetheduck/tmp/tls/x86_64/libdl.so.2
      8790:       trying file=/home/arnetheduck/tmp/tls/libdl.so.2
      8790:       trying file=/home/arnetheduck/tmp/x86_64/libdl.so.2
      8790:       trying file=/home/arnetheduck/tmp/libdl.so.2
      8790:      search cache=/etc/ld.so.cache
      8790:       trying file=/lib/libdl.so.2
      8790:
      8790:     find library=libc.so.6; searching
      8790:      search path=/home/arnetheduck/tmp              (RUNPATH from file ./test11)
      8790:       trying file=/home/arnetheduck/tmp/libc.so.6
      8790:      search cache=/etc/ld.so.cache
      8790:       trying file=/lib/libc.so.6
      8790:
      8790:
      8790:     calling init: /lib/libc.so.6
      8790:
      8790:
      8790:     calling init: /lib/libdl.so.2
      8790:
      8790:
      8790:     initialize program: ./test11
      8790:
      8790:
      8790:     transferring control: ./test11
      8790:
      8790:     find library=test2.so; searching
      8790:      search cache=/etc/ld.so.cache
      8790:      search path=/lib/tls/x86_64:/lib/tls:/lib/x86_64:/lib:/usr/lib/tls/x86_64:/usr/lib/tls:/usr/lib/x86_64:/usr/lib                (system search path)
      8790:       trying file=/lib/tls/x86_64/test2.so
      8790:       trying file=/lib/tls/test2.so
      8790:       trying file=/lib/x86_64/test2.so
      8790:       trying file=/lib/test2.so
      8790:       trying file=/usr/lib/tls/x86_64/test2.so
      8790:       trying file=/usr/lib/tls/test2.so
      8790:       trying file=/usr/lib/x86_64/test2.so
      8790:       trying file=/usr/lib/test2.so
      8790:
test1: test2.so: cannot open shared object file: No such file or directory
      8790:
      8790:     calling fini: /lib/libdl.so.2
      8790:
      8790:
      8790:     calling fini: /lib/libc.so.6
      8790:

means that it looks for the shared libraries in the RUNPATH, but not the dlopen'ed ones.

here's emerge info:
Portage 2.0.51-r3 (default-linux/amd64/2004.3, gcc-3.4.3, glibc-2.3.4.20040808-r1, 2.6.9-gentoo-r9 x86_64)
=================================================================
System uname: 2.6.9-gentoo-r9 x86_64 AMD Athlon(tm) 64 Processor 3500+
Gentoo Base System version 1.4.16
ccache version 2.3 [enabled]
Autoconf: sys-devel/autoconf-2.59-r5
Automake: sys-devel/automake-1.8.5-r1
Binutils: sys-devel/binutils-2.15.90.0.1.1-r3
Headers:  sys-kernel/linux26-headers-2.6.8.1-r1
Libtools: sys-devel/libtool-1.5.2-r7
ACCEPT_KEYWORDS="amd64"
AUTOCLEAN="yes"
CFLAGS="-O3 -march=athlon64 -pipe -mfpmath=sse"
CHOST="x86_64-pc-linux-gnu"
COMPILER=""
CONFIG_PROTECT="/etc /usr/X11R6/lib/X11/xkb /usr/kde/2/share/config /usr/kde/3/share/config /usr/lib/mozilla/defaults/pref /usr/share/config /var/qmail/control"
CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d"
CXXFLAGS="-O3 -march=athlon64 -pipe -mfpmath=sse"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoaddcvs autoconfig ccache distlocks sandbox"
GENTOO_MIRRORS="http://mirror.pudas.net/gentoo"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY=""
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="amd64 X acpi alsa berkdb bitmap-fonts crypt fam gcj gdbm gif gnome gtk gtk2 imlib ipv6 ithreads java javascript jp2 jpeg junit lzw lzw-tiff mozcalendar mozdevelop mozilla moznoirc mozplaintext mozsvg multilib ncurses nls nobcel nobeanutils nocommonsnet norhino noxalan nptl opengl oss pam pcre pic png python readline samba ssl tcpd tiff truetype unicode usb userlocales xml2 xpm xrandr xv zlib"

and:
bash-2.05b$ emerge -pv glibc

These are the packages that I would merge, in order:

Calculating dependencies ...done!
[ebuild   R   ] sys-libs/glibc-2.3.4.20040808-r1  -build -debug -erandom -hardened +multilib +nls +nptl +pic +userlocales 0 kB 


source code:
bash-2.05b$ cat test1.c
#include <stdio.h>
#include <dlfcn.h>

int main(int a, char** b) {
        void* h = dlopen("test2.so", RTLD_NOW);
        if(h == NULL) {
                printf("test1: %s\n", dlerror());
        }
        return 0;
}
bash-2.05b$ cat test2.c
#include <stdio.h>


void fcn() {
        printf("test2\n");
}
bash-2.05b$ cat Makefile
all: test11 test12
        ./test11
        ./test12
        LD_LIBRARY_PATH=. ./test11
        LD_LIBRARY_PATH=. ./test12

test11: test1.c test2.so
        gcc -o test11 test1.c -ldl -Wl,-rpath -Wl,/home/arnetheduck/tmp/
test12: test1.c test2.so
        gcc -o test12 test1.c -ldl

test2.so: test2.c
        gcc -o test2.so -fPIC -shared test2.c
Comment 1 Jacek Sieka 2004-12-28 07:08:50 UTC
Created attachment 47027 [details]
Testcase

(obviously you have to change the paths...)
Comment 2 SpanKY gentoo-dev 2004-12-28 21:09:06 UTC
sounds like bug 73003
Comment 3 Jacek Sieka 2005-01-06 04:43:38 UTC
indeed, I must have missed it when searching. That test case doesn't work on my amd64 setup either, although I've got the same binutils.

*** This bug has been marked as a duplicate of 73003 ***