Link to home
Start Free TrialLog in
Avatar of videocoder
videocoder

asked on

How To Set DT_RUNPATH or How To Augment dlopen() Search Path, At Link-time?

I'm linking an executable, on Linux (SuSE version 9.1, kernel version 2.6.6, ld version 2.15.90.0.1.1, gcc version 3.2.3 (old)), and I want to augment the shared library path used by dlopen().  In the manpage on that system, it says that, in addition to all the standard places to look, dlopen() will use DT_RUNPATH or fall back on DT_RPATH.

During the link (I use gcc as a front-end to ld), I specify '-Wl,-rpath,LOCATION' (equivalent to calling ld w/ '-rpath LOCATION'), among other options, yet dlopen() fails to find the library in LOCATION.  On an older system (SuSE version 9.0, kernel version 2.4.21, ld version 2.14.90.0.5, gcc version 3.2.3 (same)), dlopen() succeeds.  On either system, if I put LOCATION in LD_LIBRARY_PATH, dlopen() succeeds, yet that's an unreasonable requirement for this application.

I'm aware of the tool chrpath (http://freshmeat.net/projects/chrpath/?topic_id=46), but I want to know if there's a more straight-forward way to set DT_RUNPATH.  Such as via the command-line for ld.

BTW, isn't it a bit strange that someone had to write a dedicated tool for doing that?  Is it really true that binutils contains nothing for dumping or modifying DT_RPATH or DT_RUNPATH (or similar labels)?
Avatar of yuzh
yuzh

In command line:

for sh/ksh/bash
you do:

DT_RUNPATH=/path-to/lib
export DT_RUNPATH

or simply use LD_LIBRARY_PATH
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/path-to-lib
export  LD_LIBRARY_PATH

For csh/tcsh
setenv LD_LIBRARY_PATH           $LD_LIBRARY_PATH:/path-to-lib

you can you them in your .profile (sh/ksh/bash) or .cshrc file (csh/tcsh)
Avatar of videocoder

ASKER

Huh?  Are you sure about that?

DT_RUNPATH is not documented as an environment variable related to ld, in it the ld manpage.  Furthermore, this seems to make no difference in the behavior I'm seeing, and running 'strings' on my program shows that the path I put in the DT_RUNPATH environment variable didn't even make it into the executable.


Finally, as I think the subject and question clearly state, I am looking for an ALTERNATIVE to using LD_LIBRARY_PATH (which must be specified at runtime, rather than link-time).


I appreciate your attempt to help, but it seems like you didn't try to read or understand the question very thoroughly.
I have never used "DT_RUNPATH", I thought you want to define such a var for your app,
a lot of app defined their only ENV vars. I have use something like LD_RUN_PATH.
Sorry, I assumed people wouldn't try to answer the question without actually knowing about DT_RPATH and DT_RUNPATH.  They're described in the dlopen() manpage as 'tags' in an ELF file.

I don't know much about ELF files, and I don't know what a 'tag' is, but I assume it's different from a 'section' or a 'symbol'.
ASKER CERTIFIED SOLUTION
Avatar of mtmike
mtmike

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BTW, for the sake of anyone else reading this solution, I just wanted to note that '-rpath' appears to set both DT_RPATH and DT_RUNPATH (on the SuSE 9.1, kernel 2.6 system in question).