git.iko.soy/typeable/nixpkgs
on master help sign in
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.

commitc2e2152afc513fa4eda51b96dc5c7f349c3497da authorJohn Ericson <Ericson2314@Yahoo.com> dateMon 19 Jun 2017, 11:10 (9 years ago) parent0aee847
1 file changed+39−21
pkgs/build-support/cc-wrapper/default.nix+39−21
pkgs/build-support/cc-wrapper/default.nix+39−21
@@ -102,6 +102,24 @@ let
102102 sed -i $out -E -e "s~NIX_${infixSalt_}$var([^a-zA-Z_]|$)~NIX_$var\1~g"
103103 done
104104 '');
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+
105123in
106124
107125stdenv.mkDerivation {
@@ -144,7 +162,12 @@ stdenv.mkDerivation {
144162 }
145163 ''
146164
147− + optionalString (libc != null) (if (!targetPlatform.isDarwin) then ''
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 ''
148171 dynamicLinker="${libc_lib}/lib/$dynamicLinker"
149172 echo $dynamicLinker > $out/nix-support/dynamic-linker
150173
@@ -157,9 +180,21 @@ stdenv.mkDerivation {
157180 # (the *last* value counts, so ours should come first).
158181 echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before
159182 '' else ''
160− echo $dynamicLinker > $out/nix-support/dynamic-linker
183+ dynamicLinker=`eval 'echo $libc/lib/ld*.so.?'`
184+ if [ -n "$dynamicLinker" ]; then
185+ echo $dynamicLinker > $out/nix-support/dynamic-linker
161186
162− echo "export LD_DYLD_PATH=\"$dynamicLinker\"" >> $out/nix-support/setup-hook
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
163198 '')
164199
165200 + optionalString (libc != null) ''
@@ -331,24 +366,7 @@ stdenv.mkDerivation {
331366 ''
332367 + extraBuildCommands;
333368
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 "";
369+ inherit dynamicLinker;
352370
353371 crossAttrs = {
354372 shell = shell.crossDrv + shell.crossDrv.shellPath;