Skip to content

Commit

Permalink
bintools: Add response file support to ld-wrapper
Browse files Browse the repository at this point in the history
The motivation behind this is to alleviate the problem
described in NixOS#41340.
I'm not sure if this completely fixes the problem, but it
eliminates one more area where we can exceed command line
length limits.

This is essentially the same change as in NixOS#112449,
except for `ld-wrapper.sh` instead of `cc-wrapper.sh`.

However, that change alone was not enough; on macOS the
`ld` provided by `darwin.cctools` fails if you use process
substitution to generate the response file, so I put up a
PR to fix that:

tpoechtrager/cctools-port#131

… and I included a patch referencing that fix so that the
new `ld-wrapper` still works on macOS.
  • Loading branch information
Gabriella439 committed Feb 1, 2023
1 parent cdd68cd commit 1fb5cd6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pkgs/build-support/bintools-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
, nativeTools, noLibc ? false, nativeLibc, nativePrefix ? ""
, propagateDoc ? bintools != null && bintools ? man
, extraPackages ? [], extraBuildCommands ? ""
, isGNU ? bintools.isGNU or false, isLLVM ? bintools.isLLVM or false
, isGNU ? bintools.isGNU or false
, isLLVM ? bintools.isLLVM or false
, isCCTools ? bintools.isCCTools or false
, buildPackages ? {}
, targetPackages ? {}
, useMacosReexportHack ? false
Expand Down Expand Up @@ -140,6 +142,7 @@ stdenv.mkDerivation {
local dst="$1"
local wrapper="$2"
export prog="$3"
export use_response_file_by_default=${if isCCTools then "1" else "0"}
substituteAll "$wrapper" "$out/bin/$dst"
chmod +x "$out/bin/$dst"
}
Expand Down
16 changes: 12 additions & 4 deletions pkgs/build-support/bintools-wrapper/ld-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,18 @@ fi

PATH="$path_backup"
# Old bash workaround, see above.
@prog@ \
${extraBefore+"${extraBefore[@]}"} \
${params+"${params[@]}"} \
${extraAfter+"${extraAfter[@]}"}

if (( "${NIX_LD_USE_RESPONSE_FILE:-@use_response_file_by_default@}" >= 1 )); then
@prog@ @<(printf "%q\n" \
${extraBefore+"${extraBefore[@]}"} \
${params+"${params[@]}"} \
${extraAfter+"${extraAfter[@]}"})
else
@prog@ \
${extraBefore+"${extraBefore[@]}"} \
${params+"${params[@]}"} \
${extraAfter+"${extraAfter[@]}"}
fi

if [ -e "@out@/nix-support/post-link-hook" ]; then
source @out@/nix-support/post-link-hook
Expand Down
1 change: 1 addition & 0 deletions pkgs/os-specific/darwin/binutils/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ stdenv.mkDerivation {

passthru = {
inherit targetPrefix;
isCCTools = true;
};

meta = {
Expand Down
5 changes: 5 additions & 0 deletions pkgs/os-specific/darwin/cctools/port.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
, libuuid
, libobjc ? null, maloader ? null
, enableTapiSupport ? true, libtapi
, fetchpatch
}:

let
Expand Down Expand Up @@ -42,6 +43,10 @@ stdenv.mkDerivation {
patches = [
./ld-ignore-rpath-link.patch
./ld-rpath-nonfinal.patch
(fetchpatch {
url = "https://github.com/tpoechtrager/cctools-port/commit/4a734070cd2838e49658464003de5b92271d8b9e.patch";
sha256 = "0c3xh3v3jxcgwv55q00c2rfjs4h91lk43s21w5r33z600h4n6zjr";
})
]
++ lib.optional stdenv.isDarwin ./darwin-no-memstream.patch;

Expand Down

0 comments on commit 1fb5cd6

Please sign in to comment.