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

patchShebangs doesn't select correct /bin/sh for cross builds #21138

Closed
elitak opened this issue Dec 14, 2016 · 5 comments
Closed

patchShebangs doesn't select correct /bin/sh for cross builds #21138

elitak opened this issue Dec 14, 2016 · 5 comments
Labels
6.topic: cross-compilation Building packages on a different platform than they will be used on
Milestone

Comments

@elitak
Copy link
Contributor

elitak commented Dec 14, 2016

Issue description

pkgs/build-support/setup-hooks/patch-shebangs.sh uses command -v to determine the substitute for the shebang path. This selects the wrong path during cross-builds and results in x86_64 binaries getting pulled in as dependencies to cross-built binaries that can't possibly use them at runtime.

I don't know if we can reliably pick the correct /bin/sh without it being in the PATH envvar. I presume patchShebangs works fine for binaries that don't overlap with stdenv's and are included in buildInputs.

Steps to reproduce

If you cross-build some packages to ARM platforms, patchShebangs runs in the fixup phase and run head -n1 /nix/store/*-glibc-2.24-arm*-bin/bin/sotruss, you'll see it points to the native /bin/sh rather than the cross one. I was considering a PR to just add dontPatchShebangs=true; to the cross build of glibc, but figured it'd be better if the root issue were fixed instead.

Technical details

  • System: "16.03pre75806.77f8f35"
  • Nix version: nix-env (Nix) 1.12pre1234_abcdef
  • Nixpkgs version: 17.03.git.01febe0 (Gorilla)
@joachifm joachifm added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Dec 14, 2016
@bjornfor
Copy link
Contributor

/participate. (I've stumbled across this too.)

@elitak
Copy link
Contributor Author

elitak commented Dec 15, 2016

Is it safe to assume /bin/{ba,a}sh are the only paths that will ever realistically have this problem? If so, how and where would we pull in bash.crossDrv as a buildInput without it clobbering the native /bin/sh used by stdenv to run the builder? Once we're already executing patchShebangs, it's too late to find any .crossDrvs.

This problem overlaps with another, #21191, which is that crossDrvs clobber stdenv's binaries in the PATH.

The best solution I can come up with is to manually include bash in buildInputs of e.g. glibc, add logic in pks/stdenv/generic/setup.sh to not add ${bash.crossDrv}/bin to the PATH when crossbuilding, based on some new derivation attr like excludeBuildInputsFromPath = [ bash ];, then search $crossPkgs/bin during patchShebangs, independently of what's set in the PATH.

Or we could just make setup.sh smarter about importing /bin/ PATHs that contain elements of the stdenv, namely: coreutils bash busybox.

@Ericson2314
Copy link
Member

NixOS/nix#1080 is essential to fix this without greatly complicating bootstrapping.

@Ericson2314
Copy link
Member

Ericson2314 commented Jul 27, 2018

@matthewbauer don't forget to close. :)

Ericson2314 pushed a commit to obsidiansystems/nixpkgs that referenced this issue Sep 11, 2018
This hopefully makes patchShebangs respect cross compilation. It
introduces the concept of the HOST_PATH. Nothing is ever executed on
it but instead used as a way to get the proper path using ‘command
-v’. Needs more testing.

/cc @Ericson2314 @dtzWill

Fixes NixOS#33956
Fixes NixOS#21138

(Modified backport of f069423. See
previous commit to understand the differences between this and the
original.)
@FRidh FRidh closed this as completed in f069423 Oct 2, 2018
@matthewbauer matthewbauer reopened this Oct 2, 2018
jbgi pushed a commit to input-output-hk/nixpkgs that referenced this issue Jan 15, 2019
This hopefully makes patchShebangs respect cross compilation. It
introduces the concept of the HOST_PATH. Nothing is ever executed on
it but instead used as a way to get the proper path using ‘command
-v’. Needs more testing.

/cc @Ericson2314 @dtzWill

Fixes NixOS#33956
Fixes NixOS#21138
angerman pushed a commit to input-output-hk/nixpkgs that referenced this issue Jan 23, 2019
This hopefully makes patchShebangs respect cross compilation. It
introduces the concept of the HOST_PATH. Nothing is ever executed on
it but instead used as a way to get the proper path using ‘command
-v’. Needs more testing.

/cc @Ericson2314 @dtzWill

Fixes NixOS#33956
Fixes NixOS#21138
@matthewbauer matthewbauer reopened this Jan 27, 2019
@matthewbauer matthewbauer added this to the 19.09 milestone Jan 27, 2019
@matthewbauer
Copy link
Member

Addressed in #43833

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: cross-compilation Building packages on a different platform than they will be used on
Projects
None yet
Development

No branches or pull requests

5 participants