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

epoxy: explicitly search libGL path as fallback #38168

Merged
merged 1 commit into from Apr 2, 2018

Conversation

dtzWill
Copy link
Member

@dtzWill dtzWill commented Mar 31, 2018

Don't rely on questionable impact of DT_RPATH on dlopen().

This is a bit of a messy subject, but probably the clearest
reference to motivate not relying on how dlopen() behaves
in the presence of RPATH or RUNPATH is the following:

https://sourceware.org/ml/libc-hacker/2002-11/msg00011.html

FWIW the dlopen() manpage only mentions the the RPATH
and RUNPATH in the "executable file for the calling program";
no mention of the executable files for libraries--
this has been brought to the attention of the relevant
parties and AFAICT nothing has been done.

The best reference for glibc behavior is
apparently to ... "try it and see".
Luckily a generous soul did exactly that
and reported the findings:

https://www.spinics.net/lists/linux-man/msg02291.html

Qt wrote on the subject a bit when they were bit by this,
linking to the above articles (directly or indirectly).

See:
http://blog.qt.io/blog/2011/10/28/rpath-and-runpath/


Since we know the path of libGL at build-time for libepoxy,
there's a simple solution we can use to avoid all of this:
simply teach libepoxy to explicitly look in the libGL path.

This commit patches libepoxy to accomplish this,
looking to "LIBGL_PATH" as a fallback if it cannot find
the libraries otherwise.


This fixes use of libepoxy w/musl on NixOS!

  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

I've tested this with a variety of NixOS tests on my dev branch,
confirming it fixes things w/musl and doesn't regress w/glibc.

FWIW the "slim" NixOS test actually is a good candidate for this,
as well as many qemu tests, by way of glamor--even though it
eventually fails to initialize in the successful case,
if it can't find libEGL.so.1 at all it errors out and test fails.

I've checked the "slim" test works as of this revision.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: epoxy

Partial log (click to expand)

strip is /nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/h89js41hjnpd23ixaf1kqdw9amksqhcy-epoxy-1.5.0/lib
patching script interpreter paths in /nix/store/h89js41hjnpd23ixaf1kqdw9amksqhcy-epoxy-1.5.0
checking for references to /build in /nix/store/h89js41hjnpd23ixaf1kqdw9amksqhcy-epoxy-1.5.0...
shrinking RPATHs of ELF executables and libraries in /nix/store/knz1nzcmvclrn946f1fny4zsxmgbvgqf-epoxy-1.5.0-dev
strip is /nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/knz1nzcmvclrn946f1fny4zsxmgbvgqf-epoxy-1.5.0-dev/lib
patching script interpreter paths in /nix/store/knz1nzcmvclrn946f1fny4zsxmgbvgqf-epoxy-1.5.0-dev
checking for references to /build in /nix/store/knz1nzcmvclrn946f1fny4zsxmgbvgqf-epoxy-1.5.0-dev...
/nix/store/h89js41hjnpd23ixaf1kqdw9amksqhcy-epoxy-1.5.0

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: epoxy

Partial log (click to expand)

strip is /nix/store/j7d4mr0ikv974ig7yzhknpsq288js4bs-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/7j66vmgdxhiqb24cwapk1padg8870zy6-epoxy-1.5.0/lib
patching script interpreter paths in /nix/store/7j66vmgdxhiqb24cwapk1padg8870zy6-epoxy-1.5.0
checking for references to /build in /nix/store/7j66vmgdxhiqb24cwapk1padg8870zy6-epoxy-1.5.0...
shrinking RPATHs of ELF executables and libraries in /nix/store/4vb0p8khwzfamwqzamfbgkh46h6gcsyh-epoxy-1.5.0-dev
strip is /nix/store/j7d4mr0ikv974ig7yzhknpsq288js4bs-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/4vb0p8khwzfamwqzamfbgkh46h6gcsyh-epoxy-1.5.0-dev/lib
patching script interpreter paths in /nix/store/4vb0p8khwzfamwqzamfbgkh46h6gcsyh-epoxy-1.5.0-dev
checking for references to /build in /nix/store/4vb0p8khwzfamwqzamfbgkh46h6gcsyh-epoxy-1.5.0-dev...
/nix/store/7j66vmgdxhiqb24cwapk1padg8870zy6-epoxy-1.5.0

@dtzWill
Copy link
Member Author

dtzWill commented Mar 31, 2018

cc @xeji -- look okay?

@dtzWill
Copy link
Member Author

dtzWill commented Mar 31, 2018

@GrahamcOfBorg test sddm slim

@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Attempted: epoxy

Partial log (click to expand)

cannot build derivation '/nix/store/b0zcv4z95l9rmdx7wpwnj07850g16g3y-apple-framework-ImageIO.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/x3q1bz2h6knr67r12lkhdgldb8d54mf0-apple-framework-ApplicationServices.drv': 7 dependencies couldn't be built
cannot build derivation '/nix/store/wbiwf39c55nwbv89kw91kj40c4bzwy8c-apple-framework-CoreVideo.drv': 8 dependencies couldn't be built
cannot build derivation '/nix/store/q9js7rk2yjryp08ni17h9xgskzljycnw-apple-framework-Foundation.drv': 9 dependencies couldn't be built
cannot build derivation '/nix/store/n35gwc3wrdhxh3whk5cmvggm9rk9vcsx-apple-framework-QuartzCore.drv': 7 dependencies couldn't be built
cannot build derivation '/nix/store/98lnkfrm8gsvj2cr279rijf0ai8l9y05-apple-framework-Carbon.drv': 10 dependencies couldn't be built
cannot build derivation '/nix/store/nq0k2j021018086ji7rmrvgy13l1r8km-apple-lib-Xplugin.drv': 11 dependencies couldn't be built
cannot build derivation '/nix/store/18gm0ykxwj2092k4mwfaazij6xg67m8w-mesa-8.0.5.drv': 27 dependencies couldn't be built
cannot build derivation '/nix/store/k3l5pj3rq9pv3h6fd54zkpa86fgyjdyc-epoxy-1.5.0.drv': 8 dependencies couldn't be built
�[31;1merror:�[0m build of '/nix/store/k3l5pj3rq9pv3h6fd54zkpa86fgyjdyc-epoxy-1.5.0.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-linux (full log)

Attempted: tests.sddm, tests.slim

Partial log (click to expand)

building path(s) ‘/nix/store/rqp5z3kbkqyx2am6ajmvac770h99qjai-etc’
building path(s) ‘/nix/store/c3q3jv07zb2f8d9ypfglc8paglv0kh5k-nixos-system-machine-18.09.git.6318cbb’
building path(s) ‘/nix/store/krfyl16rgd6jvzmpxyapfj0b0wc0iq2c-closure-info’
/nix/store/aj9rz4k3xvg8q9fzqfnb0q123707zp0n-builder: line 1: .attrs.sh: No such file or directory
builder for ‘/nix/store/yvyngwcsd7sg366lja4jzyqaglcz9hqy-closure-info.drv’ failed with exit code 1
cannot build derivation ‘/nix/store/xmw418wa8xi8m1h26v7w032jdfhwvc4h-run-nixos-vm.drv’: 1 dependencies couldn't be built
cannot build derivation ‘/nix/store/aa0l95la1dgfah26zazjwf4g412lqq1b-nixos-vm.drv’: 1 dependencies couldn't be built
cannot build derivation ‘/nix/store/z4rf3n2yv40j20zxsbivq043ac85flv8-nixos-test-driver-slim.drv’: 1 dependencies couldn't be built
cannot build derivation ‘/nix/store/fkx2lg7wfjdr0bdrrrfw9ya2m9x1diag-vm-test-run-slim.drv’: 1 dependencies couldn't be built
error: build of ‘/nix/store/fkx2lg7wfjdr0bdrrrfw9ya2m9x1diag-vm-test-run-slim.drv’ failed

@GrahamcOfBorg
Copy link

Failure on aarch64-linux (full log)

Attempted: tests.sddm, tests.slim

Partial log (click to expand)

cannot build derivation '/nix/store/a31nzk2bx0d2h31lcp5127sbsm4w3jzi-unit-display-manager.service.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/0madwf1x4wmr2y99pm13y8j0vwlygjbs-system-units.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/aknicqhm950lmabap44p0jn50xvhjlg5-etc.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/bsyvhwgr8jf6lkwqjd0jfsylc2zqymgr-nixos-system-machine-18.09.git.881433a.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/ml393zlgghkkr5j8wczbjgfllw6pqkbh-closure-info.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/r123d1975l30h3d56rn50gy7vrcdp978-run-nixos-vm.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/52jigj0j9s6misa34caxxri3l4p862bk-nixos-vm.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/gy4bsdxbyj0asbham22b41138w9cbcqr-nixos-test-driver-slim.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/3hiydbdqqs4ayz7kw521nidpmpc6n8lc-vm-test-run-slim.drv': 1 dependencies couldn't be built
�[31;1merror:�[0m build of '/nix/store/3hiydbdqqs4ayz7kw521nidpmpc6n8lc-vm-test-run-slim.drv' failed

'';
patches = [ ./libgl-path.patch ];

NIX_CFLAGS_COMPILE = stdenv.lib.optional stdenv.isLinux ''-DLIBGL_PATH="${getLib libGL}/lib"'';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limiting to linux might not be necessary with your patch, I had to do that because patchelf fails on darwin.
Let's see if this builds on darwin.

Copy link
Contributor

@xeji xeji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patch looks good, should even work on darwin. Scary stuff though, and glibc provides zero official documentation on dlopen() ...

Don't rely on questionable impact of DT_RPATH on dlopen().

This is a bit of a messy subject, but probably the clearest
reference to motivate *not* relying on how dlopen() behaves
in the presence of RPATH or RUNPATH is the following:

https://sourceware.org/ml/libc-hacker/2002-11/msg00011.html

FWIW the dlopen() manpage only mentions the the RPATH
and RUNPATH in the "executable file for the calling program";
no mention of the executable files for libraries--
this has been brought to the attention of the relevant
parties and AFAICT nothing has been done.

The best reference for glibc behavior is
apparently to ... "try it and see".
Luckily a generous soul did exactly that
and reported the findings:

https://www.spinics.net/lists/linux-man/msg02291.html

Qt wrote on the subject a bit when they were bit by this,
linking to the above articles (directly or indirectly).

See:
http://blog.qt.io/blog/2011/10/28/rpath-and-runpath/

--------

Since we know the path of libGL at build-time for libepoxy,
there's a simple solution we can use to avoid all of this:
simply teach libepoxy to explicitly look in the libGL path.

This commit patches libepoxy to accomplish this,
looking to "LIBGL_PATH" as a fallback if it cannot find
the libraries otherwise.

---------

This fixes use of libepoxy w/musl on NixOS!
@dtzWill
Copy link
Member Author

dtzWill commented Apr 2, 2018

Bumped removing the bit that conditionally set LIBGL_PATH.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: epoxy

Partial log (click to expand)

strip is /nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/h20xayk66zrfxh90yf4v1h3l3pf40k2d-epoxy-1.5.0/lib
patching script interpreter paths in /nix/store/h20xayk66zrfxh90yf4v1h3l3pf40k2d-epoxy-1.5.0
checking for references to /build in /nix/store/h20xayk66zrfxh90yf4v1h3l3pf40k2d-epoxy-1.5.0...
shrinking RPATHs of ELF executables and libraries in /nix/store/4z8mvpdjpjsx6r6rhr5bqxfa4fbyvah2-epoxy-1.5.0-dev
strip is /nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/4z8mvpdjpjsx6r6rhr5bqxfa4fbyvah2-epoxy-1.5.0-dev/lib
patching script interpreter paths in /nix/store/4z8mvpdjpjsx6r6rhr5bqxfa4fbyvah2-epoxy-1.5.0-dev
checking for references to /build in /nix/store/4z8mvpdjpjsx6r6rhr5bqxfa4fbyvah2-epoxy-1.5.0-dev...
/nix/store/h20xayk66zrfxh90yf4v1h3l3pf40k2d-epoxy-1.5.0

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: epoxy

Partial log (click to expand)

strip is /nix/store/j7d4mr0ikv974ig7yzhknpsq288js4bs-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/7c6bbjfz3lpvinykdda2wc3jrfljqzag-epoxy-1.5.0/lib
patching script interpreter paths in /nix/store/7c6bbjfz3lpvinykdda2wc3jrfljqzag-epoxy-1.5.0
checking for references to /build in /nix/store/7c6bbjfz3lpvinykdda2wc3jrfljqzag-epoxy-1.5.0...
shrinking RPATHs of ELF executables and libraries in /nix/store/h2cwizninbg58i0nnmzha7p5dzx6gl5q-epoxy-1.5.0-dev
strip is /nix/store/j7d4mr0ikv974ig7yzhknpsq288js4bs-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/h2cwizninbg58i0nnmzha7p5dzx6gl5q-epoxy-1.5.0-dev/lib
patching script interpreter paths in /nix/store/h2cwizninbg58i0nnmzha7p5dzx6gl5q-epoxy-1.5.0-dev
checking for references to /build in /nix/store/h2cwizninbg58i0nnmzha7p5dzx6gl5q-epoxy-1.5.0-dev...
/nix/store/7c6bbjfz3lpvinykdda2wc3jrfljqzag-epoxy-1.5.0

@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Attempted: epoxy

Partial log (click to expand)

cannot build derivation '/nix/store/b0zcv4z95l9rmdx7wpwnj07850g16g3y-apple-framework-ImageIO.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/x3q1bz2h6knr67r12lkhdgldb8d54mf0-apple-framework-ApplicationServices.drv': 4 dependencies couldn't be built
cannot build derivation '/nix/store/wbiwf39c55nwbv89kw91kj40c4bzwy8c-apple-framework-CoreVideo.drv': 5 dependencies couldn't be built
cannot build derivation '/nix/store/q9js7rk2yjryp08ni17h9xgskzljycnw-apple-framework-Foundation.drv': 4 dependencies couldn't be built
cannot build derivation '/nix/store/n35gwc3wrdhxh3whk5cmvggm9rk9vcsx-apple-framework-QuartzCore.drv': 4 dependencies couldn't be built
cannot build derivation '/nix/store/98lnkfrm8gsvj2cr279rijf0ai8l9y05-apple-framework-Carbon.drv': 7 dependencies couldn't be built
cannot build derivation '/nix/store/nq0k2j021018086ji7rmrvgy13l1r8km-apple-lib-Xplugin.drv': 8 dependencies couldn't be built
cannot build derivation '/nix/store/18gm0ykxwj2092k4mwfaazij6xg67m8w-mesa-8.0.5.drv': 13 dependencies couldn't be built
cannot build derivation '/nix/store/64xadj7h3sxqvblf922sszx46f167kd2-epoxy-1.5.0.drv': 3 dependencies couldn't be built
�[31;1merror:�[0m build of '/nix/store/64xadj7h3sxqvblf922sszx46f167kd2-epoxy-1.5.0.drv' failed

@dtzWill dtzWill merged commit f48197e into NixOS:staging Apr 2, 2018
@dtzWill dtzWill deleted the fix/epoxy-libgl-path branch April 2, 2018 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants