bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/20535] New: DSO1 needed by DSO2 linked into executable not found


From: sbergman at redhat dot com
Subject: [Bug ld/20535] New: DSO1 needed by DSO2 linked into executable not found without -rpath-link, even though DT_RPATH and -rpath would find it
Date: Tue, 30 Aug 2016 09:53:38 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=20535

            Bug ID: 20535
           Summary: DSO1 needed by DSO2 linked into executable not found
                    without -rpath-link, even though DT_RPATH and -rpath
                    would find it
           Product: binutils
           Version: 2.26
            Status: NEW
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: sbergman at redhat dot com
  Target Milestone: ---

At least with binutils-2.26.1-1.fc24.x86_64,

> $ cat dso1.c
> void fun1(void) {}
>
> $ cat dso2.c
> void fun1(void);
> void fun2(void) { fun1(); }
>
> $ cat main.c
> void fun2(void);
> int main(void) {
>  fun2();
>  return 0;
> }
>
> $ mkdir dsos
> $ gcc -shared -fPIC -o dsos/libdso1.so dso1.c
> $ gcc -shared -fPIC -o dsos/libdso2.so -Wl,-rpath='$ORIGIN' dso2.c -Ldsos 
> -ldso1
> $ gcc -Wl,-rpath='$ORIGIN/dsos' main.c -Ldsos -ldso2
> /usr/bin/ld: warning: libdso1.so, needed by dsos/libdso2.so, not found (try 
> using -rpath or -rpath-link)
> dsos/libdso2.so: undefined reference to `fun1'
> collect2: error: ld returned 1 exit status

fails to find libdso2.so needed by libdso1.so, even though (a) libdso1.so has a
DT_NEEDED $ORIGIN (so it should be found via point 6 below), and (b) the ld
command line for building a.out contains -rpath='$ORIGIN/dsos' (so it should
already be found via point 2 below).

The ld man page claims (under -rpath-link) that:

  "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 between
-rpath and -rpath-link is that directories specified by -rpath options are
included in the executable and used at runtime, whereas the -rpath-link option
is only effective at link time. Searching -rpath in this way is only supported
by native linkers and cross linkers which have been configured with the
--with-sysroot option.

  [...]

  "6.  For a native ELF linker, the directories in 'DT_RUNPATH' or 'DT_RPATH'
of a shared library are searched for shared libraries needed by it. The
'DT_RPATH' entries are ignored if 'DT_RUNPATH' entries exist."

  [...]

Adding -Wl,-rpath-link=dsos when building a.out would help, but its not clear
to me why that should be necessary.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]