public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Effect of using the -rpath linkler option
@ 2018-10-03 22:16 Edward Diener
  2018-10-03 23:06 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Edward Diener @ 2018-10-03 22:16 UTC (permalink / raw)
  To: gcc-help

I am using gcc 7.2.0-19 on a Debian OS running on an arm-64 SOM. For an 
executable I am building, call it XXX, using a shared library, which I 
also build, call it YYY, I am specifying a linker option when linking 
the object files to final executable form of:

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

so that XXX finds YYY at both linktime and runtime at /some/path. 
However after the executable is built the 'readelf' utility shows me 
that the RUNPATH is set by my -rpath setting rather than the RPATH. What 
this means is that an end-user can set an LD_LIBRARY_PATH which is 
searched before the -rpath I am setting in my executable for library 
YYY. This is not what I want.

Why does the -rpath set the RUNPATH rather than the RPATH ?

How can I make sure that the executable finds YYY in the -rpath I want 
both at link time and run time, rather than in some possible place in 
the LD_LIBRARY_PATH ?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Effect of using the -rpath linkler option
  2018-10-03 22:16 Effect of using the -rpath linkler option Edward Diener
@ 2018-10-03 23:06 ` Jonathan Wakely
  2018-10-03 23:14   ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2018-10-03 23:06 UTC (permalink / raw)
  To: Edward Diener; +Cc: gcc-help

On Wed, 3 Oct 2018 at 23:16, Edward Diener wrote:
>
> I am using gcc 7.2.0-19 on a Debian OS running on an arm-64 SOM. For an
> executable I am building, call it XXX, using a shared library, which I
> also build, call it YYY, I am specifying a linker option when linking
> the object files to final executable form of:
>
> '-Wl,-rpath=/some/path'

GCC just passes that through to the linker.

> so that XXX finds YYY at both linktime and runtime at /some/path.
> However after the executable is built the 'readelf' utility shows me
> that the RUNPATH is set by my -rpath setting rather than the RPATH. What
> this means is that an end-user can set an LD_LIBRARY_PATH which is
> searched before the -rpath I am setting in my executable for library
> YYY. This is not what I want.
>
> Why does the -rpath set the RUNPATH rather than the RPATH ?

This is a linker question, so nothing to do with GCC. Your linker is
configured to prefer the new RUNPATH tag instead of RPATH.

The ld.so(8) man page says usage of RPATH is deprecated. I believe
that's because there's no way to override RPATH if it's present. If
RUNPATH is used you can still override it if needed via LD_RUN_PATH.
If you don't want LD_RUN_PATH to have effect, don't set it (or unset
it) in your program's environment.

> How can I make sure that the executable finds YYY in the -rpath I want
> both at link time and run time, rather than in some possible place in
> the LD_LIBRARY_PATH ?

If you're using the GNU linker, use the linker option --disable-new-dtags

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Effect of using the -rpath linkler option
  2018-10-03 23:06 ` Jonathan Wakely
@ 2018-10-03 23:14   ` Jonathan Wakely
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2018-10-03 23:14 UTC (permalink / raw)
  To: Edward Diener; +Cc: gcc-help

On Thu, 4 Oct 2018 at 00:06, Jonathan Wakely wrote:
> The ld.so(8) man page says usage of RPATH is deprecated. I believe
> that's because there's no way to override RPATH if it's present. If
> RUNPATH is used you can still override it if needed via LD_RUN_PATH.
> If you don't want LD_RUN_PATH to have effect, don't set it (or unset
> it) in your program's environment.

Sorry, brainfart, I meant LD_LIBRARY_PATH both times here, not LD_RUN_PATH.

N.B. some runtime linkers (musl, maybe some BSD ones) will always
allow LD_LIBRARY_PATH to override both RUNPATH and RPATH tags, so you
can't guarantee the behaviour you want on those systems.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-10-03 23:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-03 22:16 Effect of using the -rpath linkler option Edward Diener
2018-10-03 23:06 ` Jonathan Wakely
2018-10-03 23:14   ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).