Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3562
  • Last Modified:

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)?
0
videocoder
Asked:
videocoder
  • 3
  • 2
1 Solution
 
yuzhCommented:
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
 
videocoderAuthor Commented:
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
 
yuzhCommented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
videocoderAuthor Commented:
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
 
mtmikeCommented:
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
 
videocoderAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now