Skip to content

Commit

Permalink
Merge pull request NixOS#257158 from dpc/wrap-that-mold
Browse files Browse the repository at this point in the history
mold: wrap so it can find system libraries
  • Loading branch information
Artturin authored Oct 13, 2023
2 parents 9cbf22c + 77bf139 commit 6f9a9af
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
49 changes: 47 additions & 2 deletions pkgs/development/tools/mold/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
, testers
, mold
, nix-update-script
, runCommandCC
, mold-wrapped
, hello
, buildPackages
, useMoldLinker
}:

stdenv.mkDerivation rec {
Expand Down Expand Up @@ -44,11 +49,51 @@ stdenv.mkDerivation rec {

passthru = {
updateScript = nix-update-script { };
tests.version = testers.testVersion { package = mold; };
tests =
let
helloTest = name: helloMold:
let
command = "$READELF -p .comment ${lib.getExe helloMold}";
emulator = stdenv.hostPlatform.emulator buildPackages;
in
runCommandCC "mold-${name}-test" { passthru = { inherit helloMold; }; }
''
echo "Testing running the 'hello' binary which should be linked with 'mold'" >&2
${emulator} ${lib.getExe helloMold}
echo "Checking for mold in the '.comment' section" >&2
if output=$(${command} 2>&1); then
if grep -Fw -- "mold" - <<< "$output"; then
touch $out
else
echo "No mention of 'mold' detected in the '.comment' section" >&2
echo "The command was:" >&2
echo "${command}" >&2
echo "The output was:" >&2
echo "$output" >&2
exit 1
fi
else
echo -n "${command}" >&2
echo " returned a non-zero exit code." >&2
echo "$output" >&2
exit 1
fi
''
;
in
{
version = testers.testVersion { package = mold; };
wrapped = helloTest "wrapped" (hello.overrideAttrs (previousAttrs: {
nativeBuildInputs = (previousAttrs.nativeBuildInputs or [ ]) ++ [ mold-wrapped ];
NIX_CFLAGS_LINK = toString (previousAttrs.NIX_CFLAGS_LINK or "") + " -fuse-ld=mold";
}));
adapter = helloTest "adapter" (hello.override (old: { stdenv = useMoldLinker old.stdenv; }));
};
};

meta = with lib; {
description = "A faster drop-in replacement for existing Unix linkers";
description = "A faster drop-in replacement for existing Unix linkers (unwrapped)";
longDescription = ''
mold is a faster drop-in replacement for existing Unix linkers. It is
several times faster than the LLVM lld linker. mold is designed to
Expand Down
4 changes: 2 additions & 2 deletions pkgs/stdenv/adapters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ rec {
useMoldLinker = stdenv: let
bintools = stdenv.cc.bintools.override {
extraBuildCommands = ''
wrap ld.mold ${../build-support/bintools-wrapper/ld-wrapper.sh} ${pkgs.mold}/bin/ld.mold
wrap ld ${../build-support/bintools-wrapper/ld-wrapper.sh} ${pkgs.mold}/bin/ld.mold
wrap ${stdenv.cc.bintools.targetPrefix}ld.mold ${../build-support/bintools-wrapper/ld-wrapper.sh} ${pkgs.mold}/bin/ld.mold
wrap ${stdenv.cc.bintools.targetPrefix}ld ${../build-support/bintools-wrapper/ld-wrapper.sh} ${pkgs.mold}/bin/ld.mold
'';
};
in stdenv.override (old: {
Expand Down
8 changes: 8 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19649,6 +19649,14 @@ with pkgs;

mold = callPackage ../development/tools/mold { };

mold-wrapped = wrapBintoolsWith {
bintools = mold;
extraBuildCommands = ''
wrap ${targetPackages.stdenv.cc.bintools.targetPrefix}ld.mold ${../build-support/bintools-wrapper/ld-wrapper.sh} ${mold}/bin/ld.mold
wrap ${targetPackages.stdenv.cc.bintools.targetPrefix}mold ${../build-support/bintools-wrapper/ld-wrapper.sh} ${mold}/bin/mold
'';
};

mommy = callPackage ../tools/misc/mommy { };

moon = callPackage ../development/tools/build-managers/moon/default.nix { };
Expand Down

0 comments on commit 6f9a9af

Please sign in to comment.