Skip to content

Conversation

@alexfmpe
Copy link
Member

@alexfmpe alexfmpe commented Aug 1, 2021

Motivation for this change

Opening bare bones PR to collaborate on #132340
cc @Ericson2314 @sternenseemann

Things done

All cross compilation from x86_64-unknown-linux-{gnu,musl}. Plug in the config in --crossSystem "{ config = \"$config\"; useGccNg = true; }"

  • buildPackages.gccNgPackages.gcc-unwrapped
    • draft package committed
    • aarch64-unknown-linux-gnu
    • aarch64-unknown-linux-musl
  • gccNgPackages.libgcc
    • draft package committed
    • aarch64-unknown-linux-gnu
    • aarch64-unknown-linux-musl
  • libcCross
    • draft package committed
    • aarch64-unknown-linux-gnu
    • aarch64-unknown-linux-musl
  • gccNgPackages.libatomic
    • draft package committed
    • aarch64-unknown-linux-gnu
    • aarch64-unknown-linux-musl
  • gccNgPackages.libstdcxx
    • draft package committed
    • aarch64-unknown-linux-gnu
    • aarch64-unknown-linux-musl
      • Linking errors due to messed up relocations, evidentally because of mixing -fPIC and -fno-PIC

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • 21.11 Release Notes (or backporting 21.05 Relase notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.
Upstream patches

Ericson2314 and others added 7 commits August 1, 2021 18:06
Taking a bunch of stuff from 11 packages
* `builtins.attrNames gccNgPackages_11` now evaluates

* Added missing inputs

* Removed a bunch of clang-related things

  - clang-only packages: compiler-rt, libcxx, libcxxabi, openmp

  - useLLVM logic

  - stdenvs / cc-wrappers which are not applicable anymore

* Removed LLVM-specific relics like the default callPackage bindings,
  clean up default callPackage scopes for libraries and tools

* Add runtime libraries (may forgot some) to libraries set
@Ericson2314
Copy link
Member

Ericson2314 commented Aug 6, 2021

Oh no, I forgot to push my stuff! I'll merge. Actually comments won't be too bad.

@github-actions github-actions bot added the 6.topic: stdenv Standard environment label Aug 6, 2021
mkdir -p "$out/lib" "$dev/include"
ln -s "$out/lib/gcc/${stdenv.hostPlatform.config}/${version}"/* "$out/lib"
ln -s "$dev/lib/gcc/${stdenv.hostPlatform.config}/${version}/include"/* "$dev/include/"
'';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meta is missing.

@Ericson2314 Ericson2314 added the 6.topic: bootstrap Bootstrapping, avoiding pre-built binaries. Often overlaps with cross-compilation. label Oct 7, 2021
@Mindavi Mindavi mentioned this pull request Oct 13, 2021
8 tasks
@stale
Copy link

stale bot commented Apr 16, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 16, 2022
@alexfmpe
Copy link
Member Author

Unmark stale

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 20, 2022
@SuperSandro2000 SuperSandro2000 added the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 21, 2022
@Ericson2314 Ericson2314 mentioned this pull request Nov 20, 2022
13 tasks
@ghost
Copy link

ghost commented Feb 21, 2023

Hi,

It is a bummer that this sort of fell by the wayside. I just wanted to mention that enabling the goals of this PR is one of the major benefits sought by #209870.

Specifically, if that PR merges, my next project will be to start moving the libraries that are bundled with gcc into separate packages -- like this PR, but one at a time, and incrementally rather than in a big rewrite. I would like to reuse as much of the work here as possible.

@Ericson2314
Copy link
Member

https://github.com/Ericson2314/nixpkgs/tree/gcc-ng-12 This was me trying to update this to a new GCC.

@Ericson2314
Copy link
Member

@amjoseph-nixpkgs

#132343 (comment) it is a bummer, and I would love to pair with you on this to get it over the hill at some point. there was just some things I was banging my head against the wall debugging that I need another pair of eyes on.

@infinisil infinisil added the 1.severity: significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc. label Oct 31, 2023
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-10-31-nixpkgs-architecture-team-meeting-45/34846/1

@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 19, 2024
ConnorBaker pushed a commit to nixos-cuda/cuda-legacy that referenced this pull request Apr 14, 2025
 #### Summary

By default, when you type `make`, GCC will compile itself three
times.  This PR inhibits that behavior by configuring GCC with
`--disable-bootstrap`, and reimplements the triple-rebuild using
Nix rather than `make`/`sh`.

 #### Immediate Benefits

- Allow `gcc11` and `gcc12` on `aarch64` (without needing new
  `bootstrapFiles`)
- Faster stdenv rebuilds: the third compilation of gcc
  (i.e. stageCompare) is no longer a `drvInput` of the final stdenv.
  This allows Nix to build stageCompare in parallel with the rest of
  nixpkgs instead of in series.
- No more copying `libgcc_s` out of the bootstrap-files or other
  derivations
- No more Frankenstein compiler: the final gcc and the libraries it
  links against (mpfr, mpc, isl, glibc) are all built by the same
  compiler (xgcc) instead of a mixture of the bootstrapFiles'
  compiler and xgcc.
- No more [static lib{mpfr,mpc,gmp,isl}.a hack]
- Many other small `stdenv` hacks eliminated
- `gcc` and `clang` share the same codepath for more of `cc-wrapper`.

 #### Future Benefits

- This should allow using a [foreign] `bootstrap-files` so long as
  `hostPlatform.canExecute bootstrapFiles`.
- This should allow each of the libraries that ship with `gcc`
  (lib{backtrace, atomic, cc1, decnumber, ffi, gomp, iberty,
  offloadatomic, quadmath, sanitizer, ssp, stdc++-v3, vtv}) to be
  built in separate (one-liner) derivations which `inherit src;`
  from `gcc`, much like NixOS/nixpkgs#132343

 #### Incorporates

- NixOS/nixpkgs#210004
- NixOS/nixpkgs#36948 (unreverted)
- NixOS/nixpkgs#210325
- NixOS/nixpkgs#210118
- NixOS/nixpkgs#210132
- NixOS/nixpkgs#210109
- NixOS/nixpkgs#213909
- NixOS/nixpkgs#216136
- NixOS/nixpkgs#216237
- NixOS/nixpkgs#210019
- NixOS/nixpkgs#216232
- NixOS/nixpkgs#216016
- NixOS/nixpkgs#217977
- NixOS/nixpkgs#217995

 #### Closes

- Closes #108305
- Closes #108111
- Closes #201254
- Closes #208412

 #### Credits

This project was made possible by three important insights, none of
which were mine:

1. @Ericson2314 was the first to advocate for this change, and
   probably the first to appreciate its advantages.  Nix-driven
   (external) bootstrap is "cross by default".

2. @trofi has figured out a lot about how to get gcc to not mix up
   the copy of `libstdc++` that it depends on with the copy that it
   builds, by moving the `bootstrapFiles`' `libstdc++` into a
   [versioned directory].  This allows a Nix-driven bootstrap of gcc
   without the final gcc would still having references to the
   `bootstrapFiles`.

3. Using the undocumented variable [`user-defined-trusted-dirs`]
   when building glibc.  When glibc `dlopen()`s `libgcc_s.so`, it
   uses a completely different and totally special set of rules for
   finding `libgcc_s.so`.  This trick is the only way we can put
   `libgcc_s.so` in its own separate outpath without creating
   circular dependencies or dependencies on the bootstrapFiles.  I
   would never have guessed to use this (or that it existed!) if it
   were not for a [comment in guix] which @Mic92 [mentioned].

My own role in this PR was basically: being available to go on a
coding binge at an opportune moment, so we wouldn't waste a
[crisis].

[aarch64-compare-ofborg]: https://github.com/NixOS/nixpkgs/pull/209870/checks?check_run_id=10662822938
[amd64-compare-ofborg]: https://github.com/NixOS/nixpkgs/pull/209870/checks?check_run_id=10662825857
[nonexistent sysroot]: NixOS/nixpkgs#210004
[versioned directory]: NixOS/nixpkgs#209054
[`user-defined-trusted-dirs`]: https://sourceware.org/legacy-ml/libc-help/2013-11/msg00026.html
[comment in guix]: https://github.com/guix-mirror/guix/blob/5e4ec8218142eee8e6e148e787381a5ef891c5b1/gnu/packages/gcc.scm#L253
[mentioned]: NixOS/nixpkgs#210112 (comment)
[crisis]: NixOS/nixpkgs#108305
[foreign]: NixOS/nixpkgs#170857 (comment)
[static lib{mpfr,mpc,gmp,isl}.a hack]: https://github.com/NixOS/nixpkgs/blob/2f1948af9c984ebb82dfd618e67dc949755823e2/pkgs/stdenv/linux/default.nix#L380
@Ericson2314
Copy link
Member

Replaced by #414299

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 13, 2025
@alexfmpe alexfmpe deleted the gcc-ng branch June 14, 2025 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.severity: significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc. 2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: bootstrap Bootstrapping, avoiding pre-built binaries. Often overlaps with cross-compilation. 6.topic: stdenv Standard environment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants