Skip to content

Commit 504e3ec

Browse files
authored
gcc: do not allow version skew when cross-building gcc (#352821)
2 parents 2de990d + 9047491 commit 504e3ec

File tree

1 file changed

+21
-3
lines changed
  • pkgs/development/compilers/gcc

1 file changed

+21
-3
lines changed

pkgs/development/compilers/gcc/all.nix

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{ lib
22
, stdenv
3-
, gccStdenv
4-
, gcc9Stdenv
3+
, pkgs
54
, callPackage
65
, isl_0_20
76
, libcCross
@@ -15,6 +14,7 @@ let
1514
versions = import ./versions.nix;
1615
gccForMajorMinorVersion = majorMinorVersion:
1716
let
17+
majorVersion = lib.versions.major majorMinorVersion;
1818
atLeast = lib.versionAtLeast majorMinorVersion;
1919
attrName = "gcc${lib.replaceStrings ["."] [""] majorMinorVersion}";
2020
pkg = lowPrio (wrapCC (callPackage ./default.nix {
@@ -24,7 +24,25 @@ let
2424
profiledCompiler = false;
2525
libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then args.libcCross else null;
2626
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCross else { };
27-
isl = if stdenv.hostPlatform.isDarwin then null else isl_0_20;
27+
# do not allow version skew when cross-building gcc
28+
#
29+
# When `gcc` is cross-built (`build` != `target` && `host` == `target`)
30+
# `gcc` assumes that it has a compatible cross-compiler in the environment
31+
# that can build target libraries. Version of a cross-compiler has to
32+
# match the compiler being cross-built as libraries frequently use fresh
33+
# compiler features, like `-std=c++26` or target-specific types like
34+
# `_Bfloat16`.
35+
# Version mismatch causes build failures like:
36+
# https://github.com/NixOS/nixpkgs/issues/351905
37+
#
38+
# Similar problems (but on a smaller scale) happen when a `gcc`
39+
# cross-compiler is built (`build` == `host` && `host` != `target`) built
40+
# by a mismatching version of a native compiler (`build` == `host` &&
41+
# `host` == `target`).
42+
#
43+
# Let's fix both problems by requiring the same compiler version for
44+
# cross-case.
45+
stdenv = if (stdenv.targetPlatform != stdenv.buildPlatform || stdenv.hostPlatform != stdenv.targetPlatform) && stdenv.cc.isGNU then pkgs."gcc${majorVersion}Stdenv" else stdenv;
2846
}));
2947
in
3048
lib.nameValuePair attrName pkg;

0 commit comments

Comments
 (0)