Solved

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

Posted on 2004-08-29
6
2,908 Views
Last Modified: 2008-01-09
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)?
0
Comment
Question by:videocoder
  • 3
  • 2
6 Comments
 
LVL 38

Expert Comment

by:yuzh
ID: 11928748
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)
0
 

Author Comment

by:videocoder
ID: 11928841
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.
0
 
LVL 38

Expert Comment

by:yuzh
ID: 11928994
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.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:videocoder
ID: 11929056
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'.
0
 
LVL 5

Accepted Solution

by:
mtmike earned 500 total points
ID: 11932758
DT_RPATH and DT_RUNPATH are entries in the dynamic table. You can dump the dynamic table using "objdump -p /path/to/binary".

The manual page of dlopen() seems to suggest that RUNPATH is searched, but this is not the case. See http://sources.redhat.com/ml/libc-alpha/2004-06/msg00120.html

Using '-Wl,-rpath,LOCATION' should set RPATH and not RUNPATH. If the SUSE 9.1 linker does set RUNPATH, try passing '-Wl,-disable-new-dtags' to gcc.
0
 

Author Comment

by:videocoder
ID: 11939009
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).
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question