Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc: don't use old cross-compiler build a new native compiler #249301

Closed
wants to merge 10 commits into from
Closed

gcc: don't use old cross-compiler build a new native compiler #249301

wants to merge 10 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 15, 2023

Description of changes

Closes #244871

This commit checks for the following situation: we are

  • cross-building a native compiler build!=(host==target)
  • using a cross-compiler (build==host)!=target which is older than the compiler being built.

This configuration often fails (see #244871 for one example).

We check both the cross-compiler itself as well as the cross-compiler which was used to build the copy of libgcc against which the target libc is linked.

An example of this situation would be

nix-build -A pkgsCross.aarch64-multiplatform.gcc13

since the current nixpkgs default version of gcc is gcc12.

If you need to cross-build a newer-than-default-gcc-version native compiler for a different platform, you must first build a newer-than-default-gcc-version cross-compiler which targets that platform. Previously, the user had to figure out how to hack in this upgrade on their own. The code added by this commit inserts the extra compiler build automatically. There are fallback asserts to warn us if this automation for some reason does not kick in (or you use .overrideAttrs to circumvent it).

Things done

  • Built on platform(s)
    • x86_64-linux
    • powerpc64le-linux
    • aarch64-linux (cross from x86_64-linux)
    • mips64el-linux (cross from x86_64-linux)

Adam Joseph added 10 commits August 15, 2023 01:55
This commit lifts the default gcc version to a top-level attribute
so it can be overridden.
This commit causes `gccFun` to use `callPackage` with an argument
`gcc_major_version` to indicate which version of gcc is desired.  It
defaults to `default-gcc-version`.
This is stylistic; this code has been inherited from quite a long
time ago, and I never understood what the `1` meant.  Let's just use
`binutilsNoLibc.libc`, which is what `libcCross1` is defined to be,
instead.
This commit causes `gccWithoutTargetLibc` to use `callPackage` with
an argument `gcc_major_version` to indicate which version of gcc is
desired.  It defaults to `default-gcc-version`.
…uild

gccWithoutTargetLibc is useful not only for building cross
compilers, but also for cross-building native compilers.  Let's
allow it to be used in that situation.
This commit simply changes

```
pkg = lowPrio (wrapCC ... )
```

into

```
pkg = ...
```

and wraps the sole occurrence of `pkg` with `lowPrio (wrapCC ... )`.
It has no effect on eval.  I am placing it in a separate commit
simply to make the next commit easier to understand.
This commit checks that libgcc is being built by gcc, and that the
gcc it is being built by is exactly the same version.  Any other
combination of compiler and libgcc is unlikely to work.
Closes #244871

This commit checks for the following situation: we are
cross-building a native compiler (build!=(host==target)) using a
cross-compiler ((build==host)!=target) which is *older than* the
compiler being built.  We check both the cross-compiler itself as
well as the cross-compiler which was used to build the copy of
libgcc against which the target libc is linked.

This configuration often fails (see
#244871 for one example).

If you need to cross-build a newer-than-default-gcc-version native
compiler, you must first build a newer-than-default-gcc-version
cross-compiler.  Previously, the user had to figure out how to hack
in this upgrade on their own.  The code added by this commit inserts
the extra compiler build automatically.
@ghost ghost changed the title gcc: do not use an old cross-compiler build a new native compiler gcc: don't use old cross-compiler build a new native compiler Aug 15, 2023
@ofborg ofborg bot added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Aug 15, 2023
@ghost ghost closed this Jan 23, 2024
@ghost ghost deleted the pr/gcc/never-build-with-older-compiler branch January 23, 2024 06:48
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: cross-compilation Building packages on a different platform than they will be used on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pkgsCross.aarch64-multiplatform.gcc13 (and other cross-builds) fail to build due to gcc version mismatch
0 participants