-
-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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
bintools-wrapper: skip dynamic linker for static binaries #106908
Conversation
Currently we set dynamic-linker unconditionally. This breaks however some static binaries i.e. rust binaries linked against musl. There is no reason we should set an elf interpreter for static binaries hence this is skipped if `-static` or `-static-pie` is either passed to our cc or ld wrapper.
@@ -25,6 +26,10 @@ if [ -e @out@/nix-support/libc-ldflags ]; then | |||
NIX_LDFLAGS_@suffixSalt@+=" $(< @out@/nix-support/libc-ldflags)" | |||
fi | |||
|
|||
if [ -z "$NIX_DYNAMIC_LINKER_@suffixSalt@" ] && [ -e @out@/nix-support/dynamic-linker ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also allows users to specify their own link loader.
Tested with glibc and musl: $ nix-build -A pkgsMusl.tests.cc-wrapper -A pkgsMusl.tests.cc-wrapper-clang -A tests.cc-wrapper -A tests.cc-wrapper-clang |
@@ -28,6 +30,16 @@ in stdenv.mkDerivation { | |||
./core-foundation-check | |||
''} | |||
|
|||
printf "checking whether compiler builds valid static C binaries... " >&2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LnL7 do I need to disable this on darwin?
@@ -47,6 +48,11 @@ if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "${NIX_STORE:-}" | |||
# Our ld is not built with sysroot support (Can we fix that?) | |||
: | |||
else | |||
if [[ "$p" = -static || "$p" = -static-pie ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few other flags from the man page like -Bstatic
, -dn
, and -non_shared
may be relevant (I'm not sure if any of them are used in practice though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Do they have the same semantic.
@@ -134,7 +145,7 @@ then | |||
done | |||
fi | |||
|
|||
if [ -e "@out@/nix-support/dynamic-linker-m32" ] && (( "$link32" )); then | |||
if [[ "$link32" = "0" && "$setDynamicLinker" = 1 && -e "@out@/nix-support/dynamic-linker-m32" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As pointed out in #107253, (( "$link32" ))
is an arithmetic expansion that returns true (status 0) if $link32
is nonzero, not if it’s zero.
This is now passing |
This PR was reverted in 363175c (for now). Unfortunately it isn't possible to reopen the original PR, but you can create a new one. |
reopened: #107596 |
Currently we set dynamic-linker unconditionally. This breaks
however some static binaries i.e. rust binaries linked against musl.
There is no reason we should set an elf interpreter for static binaries
hence this is skipped if
-static
or-static-pie
is either passed toour cc or ld wrapper.
Motivation for this change
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)