Skip to content

Conversation

@Mic92
Copy link
Member

@Mic92 Mic92 commented Dec 14, 2020

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.

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • 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 nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

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.
@Mic92 Mic92 requested a review from Ericson2314 as a code owner December 14, 2020 15:44
NIX_LDFLAGS_@suffixSalt@+=" $(< @out@/nix-support/libc-ldflags)"
fi

if [ -z "$NIX_DYNAMIC_LINKER_@suffixSalt@" ] && [ -e @out@/nix-support/dynamic-linker ]; then
Copy link
Member Author

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.

@Mic92
Copy link
Member Author

Mic92 commented Dec 14, 2020

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

@Mic92 Mic92 requested a review from matthewbauer December 14, 2020 15:46
./core-foundation-check
''}

printf "checking whether compiler builds valid static C binaries... " >&2
Copy link
Member Author

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?

@ofborg ofborg bot added 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. labels Dec 14, 2020
@ofborg ofborg bot requested a review from Ericson2314 December 14, 2020 17:10
@ofborg ofborg bot added 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Dec 14, 2020
# Our ld is not built with sysroot support (Can we fix that?)
:
else
if [[ "$p" = -static || "$p" = -static-pie ]]; then
Copy link
Member

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)

Copy link
Member Author

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.

@Ericson2314 Ericson2314 merged commit 7a06f5d into NixOS:staging Dec 14, 2020
@Mic92 Mic92 deleted the fix-static-pie branch December 14, 2020 19:49
fi

if [ -e "@out@/nix-support/dynamic-linker-m32" ] && (( "$link32" )); then
if [[ "$link32" = "0" && "$setDynamicLinker" = 1 && -e "@out@/nix-support/dynamic-linker-m32" ]]; then
Copy link
Contributor

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.

@thefloweringash
Copy link
Member

This is now passing -dynamic-linker on darwin where it's not supported. See comment / thread: #107086 (comment)

@vcunat
Copy link
Member

vcunat commented Dec 21, 2020

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.

@Mic92
Copy link
Member Author

Mic92 commented Dec 25, 2020

reopened: #107596

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants