This is the mail archive of the binutils@sourceware.org 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]

Is '$ORIGIN' supposed to work within DT_NEEDED sections?


Subj.

I mean something like this:

    objdump -p file | fgrep NEEDED
      NEEDED               $ORIGIN/f.so
      NEEDED               libc.so.6

or like this:

    objdump -p file | fgrep NEEDED
      NEEDED               $ORIGIN/subdir/f.so
      NEEDED               libc.so.6

?

De-facto current state is (at least, in Ubuntu 16.04):
  - it works when *.so files don't use versions;
- it causes assertion failure in ld (line 224) when *.so files use versions.

It can be tested with simple script (warning: uses current dir):
#!/bin/bash -e

echo 'void f() {}' >f.c
gcc -c -fpic -o f.o f.c
ld -shared -o f.so f.o

echo 'void f(); int main() {f(); return 0;}' >main.c

echo && echo 'Now test $ORIGIN/f.so within DT_NEEDED:'
ln -s . '$ORIGIN' && gcc -o main1 main.c '$ORIGIN/f.so' && rm '$ORIGIN'
objdump -p main1 | fgrep NEEDED
./main1 && echo '  It works' || echo '  It does not work'

echo && echo 'Now test $ORIGIN/subdir/f.so within DT_NEEDED: '
mkdir '$ORIGIN' && ln -s .. '$ORIGIN/subdir' &&
    gcc -o main2 main.c '$ORIGIN/subdir/f.so' &&
    rm -r '$ORIGIN'
objdump -p main2 | fgrep NEEDED
mkdir subdir && mv f.so subdir &&
    (./main2 && echo '  It works' || echo '  It does not work') &&
    mv subdir/f.so . && rmdir subdir

echo && echo 'Now test $ORIGIN/f.so within DT_NEEDED with versions:'
ld -shared --version-script=<(echo 'V {f;};') -o fv.so f.o
ln -s . '$ORIGIN' && gcc -o main3 main.c '$ORIGIN/fv.so' && rm '$ORIGIN'
objdump -p main3 | fgrep NEEDED
./main3 && echo '  It works' || echo '  It does not work'
##END-OF-SCRIPT


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