This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Should ld consider -rpath '$ORIGIN' when finding dependencies?

On Thu, May 2, 2013 at 12:29 PM, Jonathan Wakely <> wrote:
> Consider this case (reproducable with the attached Makefile)
> echo 'int bar();   int main() { return bar(); }' > main.c
> echo 'int foo();   int bar() { return foo(); }' > bar.c
> echo 'int i;   int foo() { return i; }' > foo.c
> cc -shared -Wl,-h, -fPIC foo.c -L. '-Wl,-rpath,$ORIGIN'  -o
> cc -shared -Wl,-h, -fPIC bar.c -L. '-Wl,-rpath,$ORIGIN' -lfoo
> -o
> cc main.c -L. '-Wl,-rpath,$ORIGIN' -lbar -o main
> /usr/bin/ld: warning:, needed by ./, not found (try
> using -rpath or -rpath-link)
> ./ undefined reference to `foo'
> collect2: error: ld returned 1 exit status
> make: *** [main] Error 1
> depends on, so when linking main to the
> linker checks for, but fails.
> If I replace '-Wl,-rpath,$ORIGIN' with -Wl,-rpath,$PWD it works (using
> the attached Makefile that can be done with "make RPATH=$PWD") but
> that puts the wrong RPATH in the executable.
> If I add -Wl,-rpath-link,. it works.
> If I use Gold it works.
> So is this a ld bug, or just a difference between bfd and gold?
> I expected this to work given that ./ contains
> DT_RPATH=$ORIGIN and ./main is being given DT_RPATH=$ORIGIN too, both
> of which would allow finding ./ at runtime, so I expect it to
> link successfully.

Since the build directory layout is independent of the run-time directory
layout, checking $ORIGIN may not always work at build time.

BTW, gold doesn't check undefined symbols in


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]