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.

authored by John Ericson and committed by John Ericson c2e2152a 0aee8478

+39 -21
+39 -21
pkgs/build-support/cc-wrapper/default.nix
··· 102 sed -i $out -E -e "s~NIX_${infixSalt_}$var([^a-zA-Z_]|$)~NIX_$var\1~g" 103 done 104 ''); 105 in 106 107 stdenv.mkDerivation { ··· 144 } 145 '' 146 147 - + optionalString (libc != null) (if (!targetPlatform.isDarwin) then '' 148 dynamicLinker="${libc_lib}/lib/$dynamicLinker" 149 echo $dynamicLinker > $out/nix-support/dynamic-linker 150 ··· 157 # (the *last* value counts, so ours should come first). 158 echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before 159 '' else '' 160 - echo $dynamicLinker > $out/nix-support/dynamic-linker 161 162 - echo "export LD_DYLD_PATH=\"$dynamicLinker\"" >> $out/nix-support/setup-hook 163 '') 164 165 + optionalString (libc != null) '' ··· 331 '' 332 + extraBuildCommands; 333 334 - # The dynamic linker has different names on different Linux platforms. 335 - # 336 - # TODO(1b62c9c06173f4d5e6b090e5ae0c68fa5f478faf): This is not the best way to 337 - # do this. I think the reference should be the style in the gcc-cross-wrapper, 338 - # but to keep a stable stdenv now I do this sufficient if/else. 339 - dynamicLinker = 340 - if !nativeLibc then 341 - (if targetPlatform.system == "i686-linux" then "ld-linux.so.2" else 342 - if targetPlatform.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else 343 - # ARM with a wildcard, which can be "" or "-armhf". 344 - if targetPlatform.isArm32 then "ld-linux*.so.3" else 345 - if targetPlatform.system == "aarch64-linux" then "ld-linux-aarch64.so.1" else 346 - if targetPlatform.system == "powerpc-linux" then "ld.so.1" else 347 - if targetPlatform.system == "mips64el-linux" then "ld.so.1" else 348 - if targetPlatform.system == "x86_64-darwin" then "/usr/lib/dyld" else 349 - if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1" else 350 - abort "Don't know the name of the dynamic linker for this platform.") 351 - else ""; 352 353 crossAttrs = { 354 shell = shell.crossDrv + shell.crossDrv.shellPath;
··· 102 sed -i $out -E -e "s~NIX_${infixSalt_}$var([^a-zA-Z_]|$)~NIX_$var\1~g" 103 done 104 ''); 105 + 106 + # The dynamic linker has different names on different platforms. 107 + dynamicLinker = 108 + if !nativeLibc then 109 + (if targetPlatform.system == "i686-linux" then "ld-linux.so.2" else 110 + if targetPlatform.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else 111 + # ARM with a wildcard, which can be "" or "-armhf". 112 + if targetPlatform.isArm32 then "ld-linux*.so.3" else 113 + if targetPlatform.system == "aarch64-linux" then "ld-linux-aarch64.so.1" else 114 + if targetPlatform.system == "powerpc-linux" then "ld.so.1" else 115 + if targetPlatform.system == "mips64el-linux" then "ld.so.1" else 116 + if targetPlatform.system == "x86_64-darwin" then "/usr/lib/dyld" else 117 + if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1" else 118 + builtins.trace 119 + "Don't know the name of the dynamic linker for platform ${targetPlatform.config}, so guessing instead." 120 + null) 121 + else ""; 122 + 123 in 124 125 stdenv.mkDerivation { ··· 162 } 163 '' 164 165 + # TODO(@Ericson2314): Unify logic next hash break 166 + + optionalString (libc != null) (if (targetPlatform.isDarwin) then '' 167 + echo $dynamicLinker > $out/nix-support/dynamic-linker 168 + 169 + echo "export LD_DYLD_PATH=\"$dynamicLinker\"" >> $out/nix-support/setup-hook 170 + '' else if dynamicLinker != null then '' 171 dynamicLinker="${libc_lib}/lib/$dynamicLinker" 172 echo $dynamicLinker > $out/nix-support/dynamic-linker 173 ··· 180 # (the *last* value counts, so ours should come first). 181 echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before 182 '' else '' 183 + dynamicLinker=`eval 'echo $libc/lib/ld*.so.?'` 184 + if [ -n "$dynamicLinker" ]; then 185 + echo $dynamicLinker > $out/nix-support/dynamic-linker 186 187 + if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then 188 + echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32 189 + fi 190 + 191 + ldflagsBefore="-dynamic-linker $dlinker" 192 + fi 193 + 194 + # The dynamic linker is passed in `ldflagsBefore' to allow 195 + # explicit overrides of the dynamic linker by callers to gcc/ld 196 + # (the *last* value counts, so ours should come first). 197 + echo "$ldflagsBefore" > $out/nix-support/libc-ldflags-before 198 '') 199 200 + optionalString (libc != null) '' ··· 366 '' 367 + extraBuildCommands; 368 369 + inherit dynamicLinker; 370 371 crossAttrs = { 372 shell = shell.crossDrv + shell.crossDrv.shellPath;