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

autoPatchelfHook: improve arch/ABI compatibility, fix packages that use stdenvNoCC #137886

Merged
merged 2 commits into from
Sep 22, 2021

Conversation

impl
Copy link
Member

@impl impl commented Sep 14, 2021

Motivation for this change

Fully enabling crossSystem support for autoPatchelfHook came with some perhaps unintended consequences of being a bit more aggressive about patching ELF files from architectures/ABIs that differ from the target (previously, those files would be ignored because ldd usually couldn't handle them).

This change adds architecture and rough OS ABI detection to the script so that it doesn't try to blindly replace the interpreter of files that can't possibly use that interpreter, and also makes sure it doesn't accidentally use libraries of other architectures/ABIs.

I also took the liberty of eliminating the last shellcheck error from the file (which, granted, I also introduced). :-)

Some examples of packages that will be able to build correctly under this change:

  • cqrlog
  • dmd
  • fishnet

For package maintainers, this also removes the implicit dependency on stdenv (#137982).

cc @symphorien

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all packages 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/)
  • 21.11 Release Notes (or backporting 21.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@symphorien
Copy link
Member

/rebase staging

@impl impl force-pushed the autopatchelfhook-arch-abi-compat branch from b3f40c1 to 3729409 Compare September 17, 2021 20:43
@impl impl changed the title autoPatchelfHook: improve arch/ABI compatibility autoPatchelfHook: improve arch/ABI compatibility, fix packages that use stdenvNoCC Sep 17, 2021
@impl
Copy link
Member Author

impl commented Sep 18, 2021

@symphorien Sorry, I missed your earlier comment when I added that most recent commit! Did you want me to target this PR against the staging branch instead?

@symphorien
Copy link
Member

Hum there used to have a github action to do it automatically, but maybe it does not exist anymore. Yes in theory PRs with > 500 rebuilds should target staging.

Fully enabling crossSystem support for autoPatchelfHook came with some
perhaps unintended consequences of being a bit more aggressive about
patching ELF files from architectures/ABIs that differ from the target
(previously, those files would be ignored because ldd usually couldn't
handle them).

This change adds architecture and rough OS ABI detection to the script
so that it doesn't try to blindly replace the interpreter of files that
can't possibly use that interpreter, and also makes sure it doesn't
accidentally use libraries of other architectures/ABIs.
autoPatchelfHook actually doesn't depend on stdenv and only needs
bintools (with its wrapper). This change uses $NIX_BINTOOLS instead of
$NIX_CC and makes the dependency on bintools explicit.
@impl impl force-pushed the autopatchelfhook-arch-abi-compat branch from 3729409 to a7f5e83 Compare September 19, 2021 04:58
@github-actions github-actions bot added 6.topic: bsd Running or building packages on BSD 6.topic: kernel The Linux kernel 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS labels Sep 19, 2021
@github-actions github-actions bot removed 8.has: documentation This PR adds or changes documentation 6.topic: kernel The Linux kernel 6.topic: stdenv Standard environment 8.has: changelog 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: python 6.topic: systemd 6.topic: bsd Running or building packages on BSD labels Sep 19, 2021
@impl
Copy link
Member Author

impl commented Sep 19, 2021

👍 Makes sense, I changed the base branch to staging. It looks like I should have done that before I force-pushed my rebased branch, so my apologies the rest of you that just got flagged as reviewers on this! 😭

@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 19, 2021
@r-burns
Copy link
Contributor

r-burns commented Sep 19, 2021

No worries, it's a pretty common footgun. FYI you can rebase onto git merge-base master staging and force push before changing the base branch, to avoid the reviewer explosion.

@impl impl mentioned this pull request Sep 19, 2021
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 19, 2021
@symphorien symphorien merged commit 8ce8c97 into NixOS:staging Sep 22, 2021
Comment on lines +146 to +147
autoPatchelfHook = makeSetupHook
{ name = "auto-patchelf-hook"; deps = [ bintools ]; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
autoPatchelfHook = makeSetupHook
{ name = "auto-patchelf-hook"; deps = [ bintools ]; }
autoPatchelfHook = makeSetupHook { name = "auto-patchelf-hook"; deps = [ bintools ]; }

if [ -f "$dep" ]; then
continue
fi
elif [ -f "$libcLib/$dep" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we mixing [ and [[?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to always use [[ myself when I'm guaranteed to have a bash shell, but I was trying to match the existing style of the file which seemed to only use [[ when it was required and [ otherwise. Maybe I was reading too much into it though. :-)

Since this was already merged, would you like me to open another PR for some of these stylistic fixes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NixOS's stdenv is guaranteed to use bash. I wouldn't worry personally about portability at all. You can keep it like it is for now but in the future I think it would be better to either fully use [ or [[ and not mix and match them.

Copy link
Member Author

@impl impl Sep 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, thanks for the clarification.

I do want to introduce one more change to this script, which is to bring back #66620 (or #51588) so that packages that need stdenv_32bit will work on 64-bit. So when I get around to that I'll include these suggestions as well. Thanks again!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I am fine with always using [[. This is also how I handle new code that I add to stdenv. We don't have a written style guide yet on this.

@lionello lionello mentioned this pull request Sep 25, 2021
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants