Why cannot insert Dynamic Linker path?

Ian Lance Taylor iant@google.com
Thu Oct 14 03:50:00 GMT 2010


Samson Luk <samsonluk@gmail.com> writes:

> I've alternate sysroot installed in my system and I alway use the
> following gcc command to insert alternate dynamic linker path to new
> compiled binary:
>
> $ gcc -O2 -Wl,-rpath=/usr/lib/cs2010q1/lib:/usr/lib/cs2010q1/usr/lib
> -Wl,--dynamic-linker=/usr/lib/cs2010q1/lib/ld-linux.so.3 main.c -o
> main
>
> $ ldd main
>         libgcc_s.so.1 => /usr/lib/cs2010q1/lib/libgcc_s.so.1 (0x40028000)
>         libc.so.6 => /usr/lib/cs2010q1/lib/libc.so.6 (0x4003b000)
>         /usr/lib/cs2010q1/lib/ld-linux.so.3 (0x40000000)
>
> However, I found '-Wl,--dynamic-linker' seems no effect for create
> dynamic link shared library, it doesn't insert the dynamic linker path
> to the final .so:
>
> $ gcc   -shared -O2
> -Wl,-rpath=/usr/lib/cs2010q1/lib:/usr/lib/cs2010q1/usr/lib
> -Wl,--dynamic-linker=/usr/lib/cs2010q1/lib/ld-linux.so.3
> -L/usr/lib/cs2010q1/lib -L/usr/lib/cs2010q1/usr/lib -L/opt/lib
> -L/opt/lib/gcc/arm-none-linux-gnueabi/4.4.3 -L/usr/local/lib
> -L/usr/local/BerkeleyDB.4.2/lib -fno-stack-protector JP.o cp_00_t.o
> eu_01_t.o ji_02_t.o ji_03_t.o ji_04_t.o ma_05_t.o sh_06_t.o  -o JP.so
>
> $ ldd JP.so
>         libgcc_s.so.1 => /usr/lib/cs2010q1/lib/libgcc_s.so.1 (0x40132000)
>         libc.so.6 => /usr/lib/cs2010q1/lib/libc.so.6 (0x40145000)
>         /lib/ld-linux.so.3 (0x2a000000)
>
> as you can see the JP.so only have the /lib/ld-linux.so.3 instead of
> the /usr/lib/cs2010q1/lib/ld-linux.so.3 as the dynamic linker path.
> Appreciate for your suggestion on how to fix this problem. I am using
> gcc 4.4.3 in arm-linux 2.6.16

The --dynamic-linker option sets the contents of the PT_INTERP segment
in an executable.  There is no PT_INTERP segment in a shared library, so
the option is silently ignored.

It does not make sense to set the dynamic linker for a shared library,
because that shared library has to be loaded by something, and in
particular it has to be loaded by some dynamic linker.  In other words,
by the time the shared library is loaded, the dynamic linker is already
running.  There is no point to storing a dynamic linker in a shared
library, because it will never be used.

Ian



More information about the Gcc-help mailing list