about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--pkgs/build-support/bintools-wrapper/ld-wrapper.sh5
-rw-r--r--pkgs/development/compilers/gcc/common/configure-flags.nix26
2 files changed, 29 insertions, 2 deletions
diff --git a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh
index f8bddabbc6871..86a7416022010 100644
--- a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh
+++ b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh
@@ -50,6 +50,11 @@ if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "${NIX_STORE:-}"
             n+=1; skip "$p2"
         elif [ "$p" = -dynamic-linker ] && badPath "$p2"; then
             n+=1; skip "$p2"
+        elif [ "$p" = -syslibroot ] && [ $p2 == // ]; then
+            # When gcc is built on darwin --with-build-sysroot=/
+            # produces '-syslibroot //' linker flag. It's a no-op,
+            # which does not introduce impurities.
+            n+=1; skip "$p2"
         elif [ "${p:0:1}" = / ] && badPath "$p"; then
             # We cannot skip this; barf.
             echo "impure path \`$p' used in link" >&2
diff --git a/pkgs/development/compilers/gcc/common/configure-flags.nix b/pkgs/development/compilers/gcc/common/configure-flags.nix
index bebf91114d702..d6884eb8ba635 100644
--- a/pkgs/development/compilers/gcc/common/configure-flags.nix
+++ b/pkgs/development/compilers/gcc/common/configure-flags.nix
@@ -111,8 +111,30 @@ let
       "--with-mpc=${libmpc}"
     ]
     ++ lib.optional (libelf != null) "--with-libelf=${libelf}"
-    ++ lib.optional (!(crossMingw && crossStageStatic))
-      "--with-native-system-header-dir=${lib.getDev stdenv.cc.libc}/include"
+    ++ lib.optionals (!crossStageStatic) [
+      (if libcCross == null
+       then "--with-native-system-header-dir=${lib.getDev stdenv.cc.libc}/include"
+       else "--with-native-system-header-dir=${lib.getDev libcCross}${libcCross.incdir or "/include"}")
+      # gcc builds for cross-compilers (build != host) or cross-built
+      # gcc (host != target) always apply the offset prefix to disentangle
+      # target headers from build or host headers:
+      #     ${with_build_sysroot}${native_system_header_dir}
+      #  or ${test_exec_prefix}/${target_noncanonical}/sys-include
+      #  or ${with_sysroot}${native_system_header_dir}
+      # While native build (build == host == target) uses passed headers
+      # path as is:
+      #    ${native_system_header_dir}
+      #
+      # Nixpkgs uses flat directory structure for both native and cross
+      # cases. As a result libc headers don't get found for cross case
+      # and many modern features get disabled (libssp is used instead of
+      # target-specific implementations and similar). More details at:
+      #   https://github.com/NixOS/nixpkgs/pull/181802#issuecomment-1186822355
+      #
+      # We pick "/" path to effectively avoid sysroot offset and make it work
+      # as a native case.
+      "--with-build-sysroot=/"
+    ]
 
     # Basic configuration
     ++ [