diff --git a/pkgs/build-support/bintools-wrapper/add-lld-ldflags-before.sh b/pkgs/build-support/bintools-wrapper/add-lld-ldflags-before.sh new file mode 100644 index 00000000000..265339eb185 --- /dev/null +++ b/pkgs/build-support/bintools-wrapper/add-lld-ldflags-before.sh @@ -0,0 +1,6 @@ +# ld.lld has two incompatible command-line drivers: One for the gnu-compatible COFF linker and one for +# the ELF linker. If no emulation is set (with -m), it will default to the ELF linker; +# unfortunately, some configure scripts use `ld --help` to check for certain Windows-specific flags, +# which don't show up in the help for the ELF linker. So we set a default -m here. + +extraBefore+=("-m" "@mtype@") diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 16a9a0c7b22..59de0ef90a3 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -384,6 +384,24 @@ stdenv.mkDerivation { '' ) + ## + ## Set the default machine type so that $prefix-ld.lld uses the COFF driver for --help + ## + ## Needed because autotools parses --help for linker features... + ## + + optionalString (isLld && stdenv.targetPlatform.isWindows) (let + mtype = + /**/ if targetPlatform.isx86_32 then "i386pe" + else if targetPlatform.isx86_64 then "i386pep" + else if targetPlatform.isAarch32 then "thumb2pe" + else if targetPlatform.isAarch64 then "arm64pe" + else throw "unsupported target arch for lld"; + in '' + export mtype=${mtype} + substituteAll ${./add-lld-ldflags-before.sh} add-local-ldflags-before.sh + cat add-local-ldflags-before.sh >> $out/nix-support/add-local-ldflags-before.sh + '') + ## ## Code signing on Apple Silicon ##