RFC: Documenting Linux specific behaviour of --rpath and --rpath-link

Nick Clifton nickc@redhat.com
Wed Apr 7 13:34:58 GMT 2021


Hi Guys,

   I recently had to look over a bug report about the linker not honouring
   the --rpath and --rpath-link options properly.  It was skipping one
   shared library in favour of another further on in the search path.  It
   turns out however that this is actually the correct behaviour - for Linux
   systems only, and only only under specific circumstances.  So I have put
   together the attached patch to update the linker documentation.  To save
   time, and provide context, here is what the new text would look like, if
   the patch were applied:

   '-rpath-link=DIR'
      When using ELF or SunOS, one shared library may require another.
      This happens when an 'ld -shared' link includes a shared library as
      one of the input files.

  [...]

     The linker uses the following search paths to locate required
      shared libraries:

        1. Any directories specified by '-rpath-link' options.
        2. Any directories specified by '-rpath' options.  The difference

   [...]

       10. Any directories specifed by a 'SEARCH_DIR' command in the
           linker script being used.

   [Begin new text]

      Note however on Linux based systems there is an additional caveat:
      If the '--as-needed' option is active _and_ a shared library is
      located which would normally satisfy the search _and_ this library
      does not have DT_NEEDED tag for 'libc.so' _and_ there is a shared
      library later on in the set of search directories which also
      satisfies the search _and_ this second shared library does have a
      DT_NEEDED tag for 'libc.so' _then_ the second library will be
      selected instead of the first.

   [End new text]


I thought about trying to add an explanation of why this behaviour is
mandated, but I felt that I was getting out of my depth at that point.

So - does anyone have any comment or corrections for this new text ?

Cheers
   Nick

-------------- next part --------------
A non-text attachment was scrubbed...
Name: rpath-link.patch
Type: text/x-patch
Size: 918 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20210407/e1498065/attachment.bin>


More information about the Binutils mailing list