wrapBintoolsWith: support LINK.EXE-style args in purity checks

LLD supports Windows-style linker arguments, but these previously
triggered purity check false positives, because it saw that they
started with a '/' and assumed they were paths.

This tweaks the path detection to allow through certain values that
could be paths, but are much more likely to be LINK.EXE-style flags.
The risk of false negatives here is low — the only things we'd now
fail to catch would be attempts to link with libraries in the root
directory, which doesn't happen in practice.

We also teach the wrapper how to apply its purity checks to library
paths specified with the /LIBPATH: option.

Tested that paths we expect to be rejected (like /lib/libfoo.so) still
are.

+12 -5
+6 -4
pkgs/build-support/bintools-wrapper/ld-wrapper.sh
··· 55 55 # produces '-syslibroot //' linker flag. It's a no-op, 56 56 # which does not introduce impurities. 57 57 n+=1; skip "$p2" 58 - elif [ "${p:0:1}" = / ] && badPath "$p"; then 59 - # We cannot skip this; barf. 60 - echo "impure path \`$p' used in link" >&2 61 - exit 1 58 + elif [ "${p:0:10}" = /LIBPATH:/ ] && badPath "${p:9}"; then 59 + reject "${p:9}" 60 + # We need to not match LINK.EXE-style flags like 61 + # /NOLOGO or /LIBPATH:/nix/store/foo 62 + elif [[ $p =~ ^/[^:]*/ ]] && badPath "$p"; then 63 + reject "$p" 62 64 elif [ "${p:0:9}" = --sysroot ]; then 63 65 # Our ld is not built with sysroot support (Can we fix that?) 64 66 :
+6 -1
pkgs/build-support/wrapper-common/utils.bash
··· 84 84 done 85 85 } 86 86 87 - skip () { 87 + skip() { 88 88 if (( "${NIX_DEBUG:-0}" >= 1 )); then 89 89 echo "skipping impure path $1" >&2 90 90 fi 91 + } 92 + 93 + reject() { 94 + echo "impure path \`$1' used in link" >&2 95 + exit 1 91 96 } 92 97 93 98