Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-rpath $ORIGIN is ignored at link time with GNU ld #1897

Closed
nirbheek opened this issue Jun 4, 2017 · 1 comment
Closed

-rpath $ORIGIN is ignored at link time with GNU ld #1897

nirbheek opened this issue Jun 4, 2017 · 1 comment

Comments

@nirbheek
Copy link
Member

nirbheek commented Jun 4, 2017

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

The best way to fix this while also preserving both $ORIGIN in the DT_RPATH of the output and the changes in #1545 is to also pass -Wl,-rpath-link with the full path to the subdirectories (without $ORIGIN).

I checked and this does work as we want it to. But I am not sure why this wasn't caught on the CI. A lot of tests are failing on my machine (Fedora 25, binutils 2.26.1).

Will submit a PR with a test for this.

@nirbheek
Copy link
Member Author

nirbheek commented Jun 4, 2017

For example:

meson.git/test cases/common/46 library chain $ ninja -C build
ninja: Entering directory `build'
[11/11] Linking target prog.
FAILED: prog 
ccache cc  -o prog 'prog@exe/main.c.o' -Wl,--no-undefined -Wl,--as-needed subdir/liblib1.so '-Wl,-rpath,$ORIGIN/subdir:$ORIGIN/subdir/subdir2:$ORIGIN/subdir/subdir3'  
/usr/bin/ld: warning: liblib2.so, needed by subdir/liblib1.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: liblib3.so, needed by subdir/liblib1.so, not found (try using -rpath or -rpath-link)
subdir/liblib1.so: undefined reference to `lib3fun'
subdir/liblib1.so: undefined reference to `lib2fun'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

This works:

ccache cc -o prog 'prog@exe/main.c.o' -Wl,--no-undefined -Wl,--as-needed subdir/liblib1.so '-Wl,-rpath,$ORIGIN/subdir:$ORIGIN/subdir/subdir2:$ORIGIN/subdir/subdir3' "-Wl,-rpath-link,$PWD/subdir:$PWD/subdir/subdir2:$PWD/subdir/subdir3"

And readelf:

$ readelf -a prog | grep -i rpath
0x000000000000000f (RPATH) Library rpath: [$ORIGIN/subdir:$ORIGIN/subdir/subdir2:$ORIGIN/subdir/subdir3]

I also verified manually by relocating prog to another directory.

glslang pushed a commit to glslang/meson that referenced this issue Jun 25, 2017
Use -rpath-link with the absolute paths to the respective build dirs
to work around a binutils bug that causes $ORIGIN to not be used while
linking.

Includes a unit test that manually checks the RPATH value written out
to ensure that it uses $ORIGIN.

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

Closes mesonbuild#1897
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant