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

Dynamic loading of libraries broken on NixOS #15194

Closed
ehmry opened this issue Aug 17, 2020 · 1 comment
Closed

Dynamic loading of libraries broken on NixOS #15194

ehmry opened this issue Aug 17, 2020 · 1 comment

Comments

@ehmry
Copy link
Contributor

ehmry commented Aug 17, 2020

Nim binaries run on NixOS give an error when loading libraries that look similar to this:
could not load: libcrypto.so(.1.1|.1.0.2|.1.0.1|.1.0.0|.0.9.9|.0.9.8|.47|.46|.45|.44|.43|.41|.39|.38|.10|).

This is because NixOS does not have a system-wide directory that libraries can be loaded from by name (libcrypto.so). Normally a binary while have a RUNPATH/rpath set in the ELF header that contains absolute paths to packages in the Nix store where the loader will look for libraries, for example: /nix/store/…-glibc-2.31/lib:/nix/store/…-gcc-9.3.0-lib/lib. During the Nix build process for packages these paths are added by detecting and passing the necessary -rpath flags to the linker.

This problem can be fixed by amending the binary RUNPATH after compilation using the patchelf tool, but I cannot think of any easy way to detect which libraries the binary might load at runtime, nor how to perform the patch automatically outside of building NIx packages.

I propose to adjust the Nim compiler to load libraries on NixOS by absolute path rather than simple names, and to detect the absolute at compile time. This would fix the loading problem and improve performance by avoiding the heuristic library search at runtime. This behavior could be controlled by an additional option for the Nim compiler, and the compiler take its search paths from environmental variables that are present in Nix package builds and development environments.

ehmry added a commit to ehmry/Nim that referenced this issue Aug 17, 2020
If "nixbuild" is defined then choose dynamic runtime libraries by
searching $NIX_LDFLAGS at compile-time.

Fix nim-lang#15194
@ehmry
Copy link
Contributor Author

ehmry commented Aug 22, 2020

This can be fixed downstream.

@ehmry ehmry closed this as completed Aug 22, 2020
ehmry added a commit to ehmry/Nim that referenced this issue Mar 5, 2021
If "nixbuild" is defined then choose dynamic runtime libraries by
searching $NIX_LDFLAGS at compile-time.

Fix nim-lang#15194
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant