Skip to content

Conversation

@pcc
Copy link
Contributor

@pcc pcc commented Apr 22, 2025

After #400734 we can make useMoldLinker work when cross compiling. We need the following:

  • Need to use pkgs.buildPackages.mold so that we use mold binaries for the build machine instead of the host.
  • Need to create unprefixed ld.mold wrapper because gcc will not look for a triple-prefixed ld.mold when passing -fuse-ld=mold.

Tested on an aarch64 machine with this change + #400734:

$ nix-build -K --expr 'with import "${./.}" { crossSystem = { config = "x86_64-unknown-linux-gnu"; }; }; hello.override { stdenv = useMoldLinker stdenv; }' && strings result/bin/hello | grep mold
/nix/store/w1yg0am7iyqsgi253h84lsp92178sgfi-hello-x86_64-unknown-linux-gnu-2.12.1 mold 2.37.1 (compatible with GNU ld)

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.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.

Add a 👍 reaction to pull requests you find important.

After NixOS#400734 we can make useMoldLinker work when cross compiling.
We need the following:
- Need to use pkgs.buildPackages.mold so that we use mold binaries
  for the build machine instead of the host.
- Need to create unprefixed ld.mold wrapper because gcc will not look
  for a triple-prefixed ld.mold when passing -fuse-ld=mold.

Tested on an aarch64 machine with this change + NixOS#400734:

$ nix-build -K --expr 'with import "${./.}" { crossSystem = { config = "x86_64-unknown-linux-gnu"; }; }; hello.override { stdenv = useMoldLinker stdenv; }' && strings result/bin/hello | grep mold
/nix/store/w1yg0am7iyqsgi253h84lsp92178sgfi-hello-x86_64-unknown-linux-gnu-2.12.1
mold 2.37.1 (compatible with GNU ld)
@github-actions github-actions bot added the 6.topic: stdenv Standard environment label Apr 22, 2025
@ofborg ofborg bot added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Apr 22, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Apr 22, 2025
Copy link
Contributor

@uninsane uninsane left a comment

Choose a reason for hiding this comment

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

this does require the linked PR to properly fix cross compilation, but it should be safe to merge these in any order.

given the previous failure mode would appear to be that mold was just silently not being used for cross compilation, it would be nice to have some regression test for that if it's not too difficult to write.

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one person. label Apr 24, 2025
@siraben
Copy link
Member

siraben commented May 12, 2025

Cherrypicked this onto #400734, got this when running on x86_64-linux.

❯ nix-build -K --expr 'with import "${./.}" { crossSystem = { config = "aarch64-unknown-linux-gnu"; }; }; hello.override { stdenv = useMoldLinker stdenv; }' && strings result/bin/hello | grep mold
/nix/store/vdcwp8jwl9561v5b5hjq537vnsshcdya-hello-aarch64-unknown-linux-gnu-2.12.1
mold 2.37.1 (compatible with GNU ld)

@siraben siraben merged commit 6a4e8e9 into NixOS:master May 12, 2025
25 checks passed
@github-project-automation github-project-automation bot moved this to Done in Stdenv May 12, 2025
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 6.topic: stdenv Standard environment 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants