3
0
Fork 0
forked from mirrors/nixpkgs

cc-wrapper: Unify and improve dynamic linker flag logic

Besides deduplicating overlapping logic, clear warning messages were
added for:

 - No glob/path for dynamic linker provided (use default glob)

 - Glob did not expand to anything (don't append flag)

 - glob expanded to multiple things (take first, like before)
This commit is contained in:
John Ericson 2017-06-26 02:01:03 -04:00
parent e826a6a247
commit aca5ba405e

View file

@ -105,22 +105,20 @@ let
done done
''); '');
# The dynamic linker has different names on different platforms. # The dynamic linker has different names on different platforms. This is a
# shell glob that ought to match it.
dynamicLinker = dynamicLinker =
if !nativeLibc then /**/ if libc == null then null
(if targetPlatform.system == "i686-linux" then "ld-linux.so.2" else else if targetPlatform.system == "i686-linux" then "${libc_lib}/lib/ld-linux.so.2"
if targetPlatform.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else else if targetPlatform.system == "x86_64-linux" then "${libc_lib}/lib/ld-linux-x86-64.so.2"
# ARM with a wildcard, which can be "" or "-armhf". # ARM with a wildcard, which can be "" or "-armhf".
if targetPlatform.isArm32 then "ld-linux*.so.3" else else if targetPlatform.isArm32 then "${libc_lib}/lib/ld-linux*.so.3"
if targetPlatform.system == "aarch64-linux" then "ld-linux-aarch64.so.1" else else if targetPlatform.system == "aarch64-linux" then "${libc_lib}/lib/ld-linux-aarch64.so.1"
if targetPlatform.system == "powerpc-linux" then "ld.so.1" else else if targetPlatform.system == "powerpc-linux" then "${libc_lib}/lib/ld.so.1"
if targetPlatform.system == "mips64el-linux" then "ld.so.1" else else if targetPlatform.system == "mips64el-linux" then "${libc_lib}/lib/ld.so.1"
if targetPlatform.system == "x86_64-darwin" then "/usr/lib/dyld" else else if targetPlatform.system == "x86_64-darwin" then "/usr/lib/dyld"
if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1" else else if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1"
builtins.trace else null;
"Don't know the name of the dynamic linker for platform ${targetPlatform.config}, so guessing instead."
null)
else "";
expand-response-params = if buildPackages.stdenv.cc or null != null && buildPackages.stdenv.cc != "/dev/null" expand-response-params = if buildPackages.stdenv.cc or null != null && buildPackages.stdenv.cc != "/dev/null"
then buildPackages.stdenv.mkDerivation { then buildPackages.stdenv.mkDerivation {
@ -175,39 +173,39 @@ stdenv.mkDerivation {
} }
'' ''
# TODO(@Ericson2314): Unify logic next hash break + optionalString (libc != null) (''
+ optionalString (libc != null) (if (targetPlatform.isDarwin) then '' if [[ -z ''${dynamicLinker+x} ]]; then
echo $dynamicLinker > $out/nix-support/dynamic-linker echo "Don't know the name of the dynamic linker for platform '${targetPlatform.config}', so guessing instead." >&2
dynamicLinker="${libc_lib}/lib/ld*.so.?"
echo "export LD_DYLD_PATH=\"$dynamicLinker\"" >> $out/nix-support/setup-hook
'' else if dynamicLinker != null then ''
dynamicLinker="${libc_lib}/lib/$dynamicLinker"
echo $dynamicLinker > $out/nix-support/dynamic-linker
if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then
echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
fi fi
# The dynamic linker is passed in `ldflagsBefore' to allow # Expand globs to fill array of options
# explicit overrides of the dynamic linker by callers to gcc/ld dynamicLinker=($dynamicLinker)
# (the *last* value counts, so ours should come first).
echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before case ''${#dynamicLinker[@]} in
'' else '' 0) echo "No dynamic linker found for platform '${targetPlatform.config}'." >&2;;
dynamicLinker=`eval 'echo $libc/lib/ld*.so.?'` 1) echo "Using dynamic linker: '$dynamicLinker'" >&2;;
*) echo "Multiple dynamic linkers found for platform '${targetPlatform.config}'." >&2;;
esac
if [ -n "$dynamicLinker" ]; then if [ -n "$dynamicLinker" ]; then
echo $dynamicLinker > $out/nix-support/dynamic-linker echo $dynamicLinker > $out/nix-support/dynamic-linker
'' + (if targetPlatform.isDarwin then ''
printf "export LD_DYLD_PATH+=%q\n" "$dynamicLinker" >> $out/nix-support/setup-hook
'' else ''
if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then
echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32 echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
fi fi
ldflagsBefore="-dynamic-linker $dlinker" ldflagsBefore=(-dynamic-linker "$dynamicLinker")
'') + ''
fi fi
# The dynamic linker is passed in `ldflagsBefore' to allow # The dynamic linker is passed in `ldflagsBefore' to allow
# explicit overrides of the dynamic linker by callers to gcc/ld # explicit overrides of the dynamic linker by callers to gcc/ld
# (the *last* value counts, so ours should come first). # (the *last* value counts, so ours should come first).
echo "$ldflagsBefore" > $out/nix-support/libc-ldflags-before printLines "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before
'') '')
+ optionalString (libc != null) '' + optionalString (libc != null) ''