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

[c/c++] minimal cc/ld wrapper instead of LD_LIBRARY_PATH #104

Open
Mic92 opened this issue Mar 11, 2021 · 1 comment
Open

[c/c++] minimal cc/ld wrapper instead of LD_LIBRARY_PATH #104

Mic92 opened this issue Mar 11, 2021 · 1 comment

Comments

@Mic92
Copy link
Member

Mic92 commented Mar 11, 2021

LD_LIBRARY_PATH breaks users' executable in the following ways:

  • Executables not part of devshell might pick up libraries from LD_LIBRARY_PATH, this can lead to incompatible libraries being loaded and crash executables. This is very likely to happen on NixOS with different release channels or on Non-NixOS distributions
  • Executables compiled in devshell won't run if the environment is unset or users tries to start them outside of devshell

Instead a minimal cc/ld wrapper could set an rpath and interpreter:

#!/usr/bin/env bash
exec /nix/store/xxxxx-gcc-unwrapped/bin/gcc -Wl,-rpath=$DEVSHELL_ROOT/lib" -Wl,-dynamic-linker=$NIX_DYNAMIC_LINKER "$@"
#!/usr/bin/env bash
exec /nix/store/xxxxx-binutils-unwrapped/bin/ld -rpath "$DEVSHELL_ROOT/lib" -dynamic-linker "$NIX_DYNAMIC_LINKER" "$@"

Dynamic linker can be obtained from the wrapped version at build time: $(cat $NIX_CC/nix-support/dynamic-linker)

@Mic92
Copy link
Member Author

Mic92 commented Mar 11, 2021

Also related to #102

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

No branches or pull requests

1 participant