From c2e2152afc513fa4eda51b96dc5c7f349c3497da Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 19 Jun 2017 11:10:27 -0400 Subject: cc-wrapper: Port over finding of dynamic linker from gcc-cross-wrapper At the next break, we can deduplicate and go for the best of both worlds. --- pkgs/build-support/cc-wrapper/default.nix | 60 ++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 21 deletions(-) (limited to 'pkgs/build-support/cc-wrapper/default.nix') diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 3a155b26319d..35a5e90583b8 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -102,6 +102,24 @@ let sed -i $out -E -e "s~NIX_${infixSalt_}$var([^a-zA-Z_]|$)~NIX_$var\1~g" done ''); + + # The dynamic linker has different names on different platforms. + dynamicLinker = + if !nativeLibc then + (if targetPlatform.system == "i686-linux" then "ld-linux.so.2" else + if targetPlatform.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else + # ARM with a wildcard, which can be "" or "-armhf". + if targetPlatform.isArm32 then "ld-linux*.so.3" else + if targetPlatform.system == "aarch64-linux" then "ld-linux-aarch64.so.1" else + if targetPlatform.system == "powerpc-linux" then "ld.so.1" else + if targetPlatform.system == "mips64el-linux" then "ld.so.1" else + if targetPlatform.system == "x86_64-darwin" then "/usr/lib/dyld" else + if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1" else + builtins.trace + "Don't know the name of the dynamic linker for platform ${targetPlatform.config}, so guessing instead." + null) + else ""; + in stdenv.mkDerivation { @@ -144,7 +162,12 @@ stdenv.mkDerivation { } '' - + optionalString (libc != null) (if (!targetPlatform.isDarwin) then '' + # TODO(@Ericson2314): Unify logic next hash break + + optionalString (libc != null) (if (targetPlatform.isDarwin) then '' + echo $dynamicLinker > $out/nix-support/dynamic-linker + + 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 @@ -157,9 +180,21 @@ stdenv.mkDerivation { # (the *last* value counts, so ours should come first). echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before '' else '' - echo $dynamicLinker > $out/nix-support/dynamic-linker + dynamicLinker=`eval 'echo $libc/lib/ld*.so.?'` + if [ -n "$dynamicLinker" ]; then + echo $dynamicLinker > $out/nix-support/dynamic-linker - echo "export LD_DYLD_PATH=\"$dynamicLinker\"" >> $out/nix-support/setup-hook + 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 + + ldflagsBefore="-dynamic-linker $dlinker" + fi + + # The dynamic linker is passed in `ldflagsBefore' to allow + # explicit overrides of the dynamic linker by callers to gcc/ld + # (the *last* value counts, so ours should come first). + echo "$ldflagsBefore" > $out/nix-support/libc-ldflags-before '') + optionalString (libc != null) '' @@ -331,24 +366,7 @@ stdenv.mkDerivation { '' + extraBuildCommands; - # The dynamic linker has different names on different Linux platforms. - # - # TODO(1b62c9c06173f4d5e6b090e5ae0c68fa5f478faf): This is not the best way to - # do this. I think the reference should be the style in the gcc-cross-wrapper, - # but to keep a stable stdenv now I do this sufficient if/else. - dynamicLinker = - if !nativeLibc then - (if targetPlatform.system == "i686-linux" then "ld-linux.so.2" else - if targetPlatform.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else - # ARM with a wildcard, which can be "" or "-armhf". - if targetPlatform.isArm32 then "ld-linux*.so.3" else - if targetPlatform.system == "aarch64-linux" then "ld-linux-aarch64.so.1" else - if targetPlatform.system == "powerpc-linux" then "ld.so.1" else - if targetPlatform.system == "mips64el-linux" then "ld.so.1" else - if targetPlatform.system == "x86_64-darwin" then "/usr/lib/dyld" else - if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1" else - abort "Don't know the name of the dynamic linker for this platform.") - else ""; + inherit dynamicLinker; crossAttrs = { shell = shell.crossDrv + shell.crossDrv.shellPath; -- cgit 1.4.1