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

drop LD_LIBRARY_PATH for opengl programs #11434

Closed
lucabrunox opened this issue Dec 3, 2015 · 10 comments · Fixed by #61981
Closed

drop LD_LIBRARY_PATH for opengl programs #11434

lucabrunox opened this issue Dec 3, 2015 · 10 comments · Fixed by #61981

Comments

@lucabrunox
Copy link
Contributor

Proposal:

  • Make a mesa setup-hook: find opengl programs in $out, fix rpath to point to /run/opengl-driver (or /run/opengl-driver-32).
  • Drop LD_LIBRARY_PATH.
@vcunat
Copy link
Member

vcunat commented Dec 3, 2015

I'm not certain about all the consequences. It isn't just libGL* – there can also be other required things on that path, e.g. libvdpau_* and libcuda.so*. But I guess the packages that stop finding libs should be fixable easily by adding the reference explicitly somehow.

What might also be a problem: during chrooted builds we have no /run/opengl-driver*, so if mesa is removed from rpath, I think many executables wouldn't even start due to that dependency, e.g. through libcairo. That would be worked around if we only added /run/opengl-driver* at the beginning of rpath without removing the mesa reference.

@ttuegel
Copy link
Member

ttuegel commented Dec 4, 2015

Will this affect people using Nixpkgs outside NixOS?

@lucabrunox
Copy link
Contributor Author

@ttuegel it should be the same, need for creating /run/opengl-driver manually, or setting another proper LD_LIBRARY_PATH.

The behavior should be the same as of now, except we don't need LD_LIBRARY_PATH which would apply to every binary.

@vcunat
Copy link
Member

vcunat commented Jan 6, 2016

Closely related: there might be a change how libGL implementations are switched. https://github.com/NVIDIA/libglvnd So far only nvidia is known to use that interface, but it's well possible the other major players will jump in soon.

@Profpatsch
Copy link
Member

(triage) any action items?

@lucabrunox
Copy link
Contributor Author

No, just brainstorming here.

@Profpatsch
Copy link
Member

(triage) I assume this hasn’t been implemented yet?

@flokli
Copy link
Contributor

flokli commented May 20, 2019

There's #60985, which will set RUNPATH in various dispatch libraries to look in /run/opengl-driver(-32), and I suggested dropping the global LD_LIRARY_PATH there, too.

@ambrop72
Copy link
Contributor

ambrop72 commented May 22, 2019

Once I remove LD_LIBRARY_PATH from opengl.nix, when I log in via LightDM (as supposed to SDDM or a console login), I still get this in LD_LIBRARY_PATH: /run/opengl-driver/lib:/nix/store/s98r8d73ajrmsgcmscbr2q2xicm2xx56-nvidia-x11-430.14-4.19.44. Note how there's no 32-bit link and there is also the absolute path to the driver directory (which in my case does nothing because libraries are under lib). I'm pretty sure it's coming from xserver.nix. SDDM must be unsetting it while LightDM is letting it through to the user session.

We should remove this so it doesn't affect the session, and fix things as necessary by adding RUNPATH to programs that need it (X server, individual display managers, wayland stuff?). I will try with NVidia but cannot try other drivers.

@ambrop72
Copy link
Contributor

ambrop72 commented May 22, 2019

I see two drivers that still rely on LD_LIBRARY_PATH to override default system libraries, amdgpu-pro and ati_drivers_x11. Not only do they directly provide libraries like libGL, libEGL, libGLESv2 and libOpenCL instead of using dispatch libraries (libglvnd, opencl-icd), they override other system libraries:

  • ati_drivers_x11 has symlinks to NixOS builds of a whole bunch of Xorg libraries (e.g. libSM, libX11, libXext). There is a comment in the package saying it makes some programs work, without explaining why.
  • amdgpu_pro has replacements of libdrm, libgbm, libkms and some LLVM libraries (libLTO, libLLVM-5.0).

Because NixOS has patched glibc to give LD_LIBRARY_PATH priority over RUNPATH, any program that links to one of these libraries will load the one from the AMD drivers. This can result in horrible breakage (what happens to programs that link to LLVM when they get the AMD thing?).

This is so ugly and prone to break things that I think we should consider dropping both drivers. If not then we should at least go forward with dropping LD_LIBRARY_PATH only for drivers that don't need it (mesa, nvidia).

ambrop72 added a commit to ambrop72/nixpkgs that referenced this issue May 26, 2019
… it.

A new internal option `hardware.opengl.setLdLibraryPath` is added which controls if `LD_LIBRARY_PATH` should be set to `/run/opengl-driver(-32)/lib`. It is false by default and is meant to be set to true by any driver which requires it. If this option is false, then `opengl.nix` and `xserver.nix` will not set `LD_LIBRARY_PATH`.

Currently Mesa and NVidia drivers don't set `setLdLibraryPath` because they work with libglvnd and do not override libraries, while `amdgpu-pro`, `ati` and `parallels-guest` set it to true (the former two really need it, the last one doesn't build so is presumed to).

Additionally, the `libPath` attribute within entries of `services.xserver.drivers` is removed. This made `xserver.nix` add the driver path directly to the `LD_LIBRARY_PATH` for the display manager (including X server). Not only is it redundant when the driver is added to `hardware.opengl.package` (assuming that `hardware.opengl.enable` is true), in fact all current drivers except `ati` set it incorrectly to the package path instead of package/lib.

This removal of `LD_LIBRARY_PATH` could break certain packages using CUDA, but only those that themselves load `libcuda` or other NVidia driver libraries using `dlopen` (not if they just use `cudatoolkit`). A few have already been fixed but it is practically impossible to test all because most packages using CUDA are libraries/frameworks without a simple way to test.

Fixes NixOS#11434 if only Mesa or NVidia graphics drivers are used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants