This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

A question about LD_LIBRARY_PATH


Hi all,

I have a question about the environment variable LD_LIBRARY_PATH. I
would like to know whether it takes precedence over the RPATH encoded in
the binary executable. I have a small test case which gives different
results on two Linux platforms; see below for the source code and the
results :

* First machine :

$ uname -a
Linux login0 2.6.32-220.23.1.bl6.Bull.28.8.x86_64 #1 SMP Thu Jul 5
17:34:18 CEST 2012 x86_64 x86_64 x86_64 GNU/Linux
$ cat main.c
int main ()
{
  a ();
}
$ cat a.c
void a ()
{

}

$ cc -c -fPIC a.c
$ ld -shared -o 1/liba.so a.o
$ ld -shared -o 2/liba.so a.o
$ cc -o main.x main.c -Wl,-rpath,$PWD/1 -L$PWD/1 -la
$ ldd main.x
        linux-vdso.so.1 =>  (0x00007fff2e7eb000)
        liba.so => /home_nfs/mrpm/marguina/SAVE/scratch/dyn1/1/liba.so
(0x00007fcdc45be000)
        libc.so.6 => /lib64/libc.so.6 (0x00000032bca00000)
        /lib64/ld-linux-x86-64.so.2 (0x00000032bc200000)
$ LD_LIBRARY_PATH=$PWD/2 ldd ./main.x
        linux-vdso.so.1 =>  (0x00007fff7cc8b000)
        liba.so => /home_nfs/mrpm/marguina/SAVE/scratch/dyn1/1/liba.so
(0x00007f02f465b000)
        libc.so.6 => /lib64/libc.so.6 (0x00000032bca00000)
        /lib64/ld-linux-x86-64.so.2 (0x00000032bc200000)

* On the second machine, all steps but the first and the last give the
same results as before. Last step is different :

$ uname -a
Linux yukisc2 2.6.16.60-0.69.1-smp #1 SMP Fri Sep 17 17:07:54 UTC 2010
x86_64 x86_64 x86_64 GNU/Linux
...
$ LD_LIBRARY_PATH=$PWD/2 ldd ./main.x
        linux-vdso.so.1 =>  (0x00002aaaaaac6000)
        liba.so => /cnrm/gp/mrpm/mrpm609/scratch/dyn/2/liba.so
(0x00002aaaaabc7000)
        libc.so.6 => /lib64/libc.so.6 (0x00002aaaaacea000)
        /lib64/ld-linux-x86-64.so.2 (0x00002aaaaaaab000)

So it seems that LD_LIBRARY_PATH precedence depends on the machine.

What is the correct behaviour ? Is there a way to configure
RPATH/LD_LIBRARY_PATH precedence ?


Regards,

Philippe








Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]