LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-29-2018, 08:19 PM   #1
eldiener
Member
 
Registered: Nov 2006
Distribution: Mepis, CentOS, OpenSuse
Posts: 106

Rep: Reputation: 17
LD_LIBRARY_PATH overriding -rpath for executable


In a Linux executable I am building with gcc I have linker options setting the rpath with:

'-Wl,-rpath=/some/path'

Yet if LD_LIBRARY_PATH is set to some path which contains the same version number of a shared library which my Linux executable needs at run-time the loader uses that instance of the shared library rather than the one in the directory I am setting with the -rpath linker option above. Why is that ? Does LD_LIBRARY_PATH really override the -rpath path I am setting in the executable itself ? That seems as if it must be a wrong design. How then can I ensure that the executable uses the shared library path which I set in the executable over anything that can be set by an environment variable.

BTW I can of course test that the above is actually happening with the ldd command.

Last edited by eldiener; 09-29-2018 at 08:20 PM.
 
Old 09-30-2018, 01:28 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
rpath has lower precedence: https://en.wikipedia.org/wiki/Rpath.
or see man ld.so
 
Old 10-01-2018, 09:57 AM   #3
eldiener
Member
 
Registered: Nov 2006
Distribution: Mepis, CentOS, OpenSuse
Posts: 106

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by pan64 View Post
rpath has lower precedence: https://en.wikipedia.org/wiki/Rpath.
or see man ld.so
In the Wikipedia link you supplied it says that the rpath is searched first. I do not understand therefore how or why it would have lower precedence.
 
Old 10-01-2018, 02:08 PM   #4
average_user
Member
 
Registered: Dec 2010
Location: Warsaw, Poland
Distribution: Slackware
Posts: 560

Rep: Reputation: 220Reputation: 220Reputation: 220
What version of ld do you use? It's possible that you set DT_RUNPATH instead of DT_RPATH. See https://software.intel.com/sites/def.../dsohowto.pdf:
Quote:
For each object, DSO as well as executable, the author can define a
“run path”. The dynamic linker will use the value of the path string
when searching for dependencies of the object the run path is defined
in. Run paths comes is two variants, of which one is deprecated. The
runpaths are accessible through entries in the dynamic section as
field with the tags DT RPATH and DT RUNPATH . The dif- ference between
the two value is when during the search for dependencies they are
used. The DT RPATH value is used first, before any other path,
specifically before the path defined in the LD LIBRARY PATH
environment vari- able. This is problematic since it does not allow
the user to overwrite the value. Therefore DT RPATH is depre-
cated. The introduction of the new variant, DT RUNPATH , corrects this
oversight by requiring the value is used after the path in LD LIBRARY
PATH .
Show output of:
Code:
readelf  -a binary  | grep -i RPATH
 
Old 10-02-2018, 09:34 AM   #5
eldiener
Member
 
Registered: Nov 2006
Distribution: Mepis, CentOS, OpenSuse
Posts: 106

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by average_user View Post
What version of ld do you use? It's possible that you set DT_RUNPATH instead of DT_RPATH. See https://software.intel.com/sites/def.../dsohowto.pdf:

Show output of:
Code:
readelf  -a binary  | grep -i RPATH
Thanks !

I can see from the 'readelf' command that it is setting the RUNPATH rather than the RPATH to what I specify as the '-rpath' option to the linker, and that is why the LD_LIBRARY_PATH is being searched first.

But why would the linker set the RUNPATH rather than the RPATH when I specify '-rpath' in my linker option ? I clearly want the RPATH set since I do not want the end-user to have the ability to override the order of the search path for shared libraries for the executable.
 
Old 10-03-2018, 04:59 AM   #6
average_user
Member
 
Registered: Dec 2010
Location: Warsaw, Poland
Distribution: Slackware
Posts: 560

Rep: Reputation: 220Reputation: 220Reputation: 220
Show output of
Code:
ld --version
ld is a part of binutils and I read somewhere that at some point they changed the meaning of -rpath option.
 
  


Reply

Tags
ldd



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
try using -rpath or -rpath-link knobby67 Programming 5 11-12-2015 02:04 PM
[SOLVED] Another compilation error (plasma-runtime). -rpath -rpath-link davepi Gentoo 1 08-21-2012 09:04 AM
Java Rpath ? maas187 Linux - Software 2 09-27-2009 05:20 AM
rPath remaster phantom_cyph Linux - General 3 05-19-2007 08:54 AM
overriding SIGINT xface66 Programming 3 04-02-2007 01:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration