From 2946b819c209f4a1a9e87a725fc9e5ed2452c178 Mon Sep 17 00:00:00 2001 From: Daniel Fullmer Date: Thu, 22 Sep 2022 09:41:40 -0700 Subject: [PATCH] cc-wrapper: fix linking against GCC libs for non-GCC Currently, clang++ statically links against libstdc++ instead of dynamically links, because the -L path included in the cc-wrapper is incorrect. The gccForLibs.lib output only contains the architecture subdirectory if the target and host platform are not the same. (See targetConfig set in gcc//default.nix and the gcc/builder.nix) This fixes the incorrect linking by using the correct path for both the cross and native cases. This also matches the cc_solib set above in cc-wrapper/default.nix Tested by compiling a simple cpp binary and noting that it now correctly dynamically links against libstdc++, natively on x86_64 and arm64, as well as x86_64 -> arm64 cross compilation. Co-Authored-By: Sebastian Ullrich --- pkgs/build-support/cc-wrapper/default.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index f8e28c452c33..beb213473b6e 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -70,6 +70,8 @@ let && !(stdenv.targetPlatform.useAndroidPrebuilt or false) && !(stdenv.targetPlatform.isiOS or false) && gccForLibs != null; + gccForLibs_solib = getLib gccForLibs + + optionalString (targetPlatform != hostPlatform) "/${targetPlatform.config}"; # older compilers (for example bootstrap's GCC 5) fail with -march=too-modern-cpu isGccArchSupported = arch: @@ -311,7 +313,7 @@ stdenv.mkDerivation { echo "-B${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version}" >> $out/nix-support/cc-cflags echo "-L${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version}" >> $out/nix-support/cc-ldflags - echo "-L${gccForLibs.lib}/${targetPlatform.config}/lib" >> $out/nix-support/cc-ldflags + echo "-L${gccForLibs_solib}/lib" >> $out/nix-support/cc-ldflags '' # TODO We would like to connect this to `useGccForLibs`, but we cannot yet