This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Patch: Re: bug in ld -rpath ??
- To: kettenis at wins dot uva dot nl, hjl at lucon dot org, brownb at jany dot gs dot com
- Subject: Re: Patch: Re: bug in ld -rpath ??
- From: Nick Clifton <nickc at redhat dot com>
- Date: Mon, 21 Aug 2000 15:40:55 -0700
- CC: binutils at sourceware dot cygnus dot com
Hi Guys,
: From: Bob Brown
:
: Does GNU ld have a broken "-rpath" switch, or is GNU ld behaving as
: you intend?
I believe that it is broken, although not in the way that you may have
originally thought (see below).
: If the bug only appears in the 2.10 binutils release, is it safe to
: use an earlier linker with gcc version 2.95.2?
Nope - earlier versions were broken in different ways.
: vole <121> gcc -v -L/tmp/a -Wl,-rpath /tmp/a main.o -la
: Reading specs from
: /sw/external/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs
: gcc version 2.95.2 19991024 (release)
:
: /sw/external/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/collect2
: -m elf_i386
: -dynamic-linker /lib/ld-linux.so.2
: /usr/lib/crt1.o
: /usr/lib/crti.o
: /sw/external/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/crtbegin.o
: -L/tmp/a
: -L/sw/external/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2
: -L/sw/external/gcc-2.95.2/lib
: -rpath /tmp/a
: main.o
: -la
: -lgcc
: -lc
: -lgcc
: /sw/external/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/crtend.o
: /usr/lib/crtn.o
: /sw/external/binutils-2.10/bin/ld: warning: libused_by_a.so, needed
: by /tmp/a/liba.so, not found (try using --rpath)
: /tmp/a/liba.so: undefined reference to `used_by_a'
This is (arguably) correct behavior for the linker. The
documentation says (for -rpath-link, although I believe that it
applies to -rpath as well) that:
This option should be used with caution as it overrides the search
path that may have been hard compiled into a shared library. In such
a case it is possible to use unintentionally a different search path
than the runtime linker would do.
Hence the linker does not look in /tmp/u since the presence of the
-rpath switch overrides the use of the paths built into the shared
library. Note if you change your command line to:
gcc -v -L/tmp/a -Wl,-rpath /tmp/u main.o -la
^
Then the link will work. |
Of course following this logic, if the -rpath switch is omitted
entirely then the path built into the liba.so object ought to be used,
but this does not appear to be the case. IMHO this is the real bug.
: From H.J.Lu
:
: I see it as a bug. Here is a patch. Any comments?
I like the patch, although I think that it needs a few tweaks. See below.
: From: Mark Kettenis <kettenis@wins.uva.nl>
:
: From: "H . J . Lu" <hjl@lucon.org>
:
: I see it as a bug. Here is a patch. Any comments?
:
: This changes the documented behaviour. The search order is explicitly
: specified under the description of the -rpath-link option. Your
: patches changes the documented behaviour. If there is a consesus that
: this is the right thing there should be a change to the documentation
: and an entry in the NEWS file.
I agree that the patch changes the linker's behavior, although I do
not think that this is a bad thing. Since the new behavior is to
check an additional set of directories for a shared library, and since
the check is performed after all of the other user-configurable
searches, I think that the change is helpful rather than hurtful.
H.J. Please could you amend your patch to do the following things:
* Only search through the DT_RPATH and DT_RUNPATH entries if the
-rpath and -rpath-link command line switches have not been
specified. This should make the linker behave as it did before in
the presence of these switches.
* Update the documentation in ld.texinfo to:
1. Make it clear that the -rpath and -rpath-link switches
completely stop the linker from using the DT_RPATH and
DT_RUNPATH entries, (the wording at the moment is open to
interpretation).
2. At an item (in the correct place!) to the list of places
where the linker will search for shared libraries saying
that, for ELF systems, if the -rpath and -rpath-link switches
have not been used, then it will look in the directories
specified by the DT_RPATH or DT_RUNPATH entries in the
relevant object file.
* Add an entry to the NEWS file noting this new behavior.
* Add code to the ..._after_open() function to display the searches
(both successful and failed) for needed libraries when the
-verbose switch is used. (Searches for libraries specified on
the command line are shown with this option, and I believe that
it would be helpful to have the needed library searches shown as
well).
Thanks very much.
Cheers
Nick