Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-08-29
6
Medium Priority
?
3,353 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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 demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

885 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