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]

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

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
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.

Attachment: Makefile
Description: Binary data

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