Skip to content

gcc: for cross compilers, don't build libgcc twice#249682

Merged
Artturin merged 1 commit intomasterfrom
unknown repository
Sep 8, 2023
Merged

gcc: for cross compilers, don't build libgcc twice#249682
Artturin merged 1 commit intomasterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Aug 17, 2023

Description of changes

Cross-compiled binaries currently end up with two different libgcc outpaths in their closure. This is harmless, but confusing.

The two libgccs are:

  • One of them is the "first" targetPlatform libgcc, which is built by the "first" cross-compiler. This "first libgcc" and "first compiler" are used to build the targetPlatform glibc.

  • Once glibc is built, we rebuild the cross-compiler, since gcc can't enable most of its features unless you give it an already-compiled targetPlatform glibc. When this "second" compiler is built, it also builds an extra copy of libgcc.

This commit discards the second, extra libgcc, and instead puts a reference to the first (correct) libgcc into the "second compiler" .passthru.libgcc, so that anybody expecting stdenv.cc.cc.libgcc to exist will still find it there.

Closes #249680

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release 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.

@ofborg ofborg bot added 6.topic: cross-compilation Building packages on a different platform than they will be used on 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Aug 17, 2023
@ghost ghost marked this pull request as ready for review August 17, 2023 09:06
@ghost ghost requested a review from matthewbauer as a code owner August 17, 2023 09:06
@Artturin Artturin self-requested a review September 8, 2023 03:28
Cross-compiled binaries currently end up with two different libgcc
outpaths in their closure.  This is harmless, but confusing.

The two libgccs are:

- One of them is the "first" targetPlatform libgcc, which is built
  by the "first" cross-compiler.  This "first libgcc" and "first
  compiler" are used to build the targetPlatform glibc.

- Once glibc is built, we *rebuild* the cross-compiler, since gcc
  can't enable most of its features unless you give it an
  already-compiled targetPlatform glibc.  When this "second"
  compiler is built, it also builds an extra copy of libgcc.

This commit discards the second, extra libgcc, and instead puts a
reference to the first (correct) libgcc into the "second compiler"
`.passthru.libgcc`, so that anybody expecting `stdenv.cc.cc.libgcc`
to exist will still find it there.

Closes #249680
@Artturin
Copy link
Copy Markdown
Member

Artturin commented Sep 8, 2023

before:

$ nix path-info -rsSh $(chase result) | LC_ALL=C sort -hk3
/nix/store/ryg2qa9qmzgv3gbj5x1s3ngj9an4dlir-libgcc-aarch64-unknown-linux-gnu-12.3.0                	535.6K	535.6K
/nix/store/20x7c06lpvkzzaz5gif7qv3slj8js13g-linux-headers-6.4                                      	  6.0M	  6.0M
/nix/store/zb4kxl0a6mmb456jb82c8250yk337hpp-glibc-aarch64-unknown-linux-gnu-2.37-8                 	 39.5M	 40.0M
/nix/store/15dk0vg596r9s4qnbhdrv8f17j85d6m1-glibc-aarch64-unknown-linux-gnu-2.37-8-bin             	  2.9M	 42.9M
/nix/store/ks5pfn0i1hhg0lyvg3vs9w4ss34074d2-ncurses-aarch64-unknown-linux-gnu-6.4                  	  3.9M	 43.9M
/nix/store/597n4rdf9pvkl0xwisf7vp85g4b7550n-glibc-aarch64-unknown-linux-gnu-2.37-8-dev             	  2.2M	 51.1M
/nix/store/z7hdlh9az0921i0lndb92kbm5yw1sssw-aarch64-unknown-linux-gnu-stage-final-gcc-12.3.0-libgcc	480.8K	 51.5M
/nix/store/c6a6p6z0gp1cfc8xpkijkklpslddy5dd-aarch64-unknown-linux-gnu-stage-final-gcc-12.3.0-lib   	  8.0M	 59.5M
/nix/store/1vspj5rw3anw190m753by8b9avja2hw3-gmp-with-cxx-aarch64-unknown-linux-gnu-6.3.0           	656.0K	 60.1M
/nix/store/cjzravcp3qwyzp0vw4lkc3axplys98al-spigot-aarch64-unknown-linux-gnu-20220606.eb585f8      	  1.2M	 65.2M

after:

$ nix path-info -rsSh $(chase result) | LC_ALL=C sort -hk3
/nix/store/ryg2qa9qmzgv3gbj5x1s3ngj9an4dlir-libgcc-aarch64-unknown-linux-gnu-12.3.0             	535.6K	535.6K
/nix/store/zb4kxl0a6mmb456jb82c8250yk337hpp-glibc-aarch64-unknown-linux-gnu-2.37-8              	 39.5M	 40.0M
/nix/store/prj327q5afj9xx9ghzg0kdq2qwxi25ng-ncurses-aarch64-unknown-linux-gnu-6.4               	  3.9M	 43.9M
/nix/store/0hs8ldbjxrbjihpfag054f6jpfr1jmq7-aarch64-unknown-linux-gnu-stage-final-gcc-12.3.0-lib	  8.1M	 48.1M
/nix/store/jfp807gjzxnfjffhpjgvfjaw127a13m9-gmp-with-cxx-aarch64-unknown-linux-gnu-6.3.0        	656.0K	 48.8M
/nix/store/w633g3prpnn25gi2nig064wfj176pwsx-spigot-aarch64-unknown-linux-gnu-20220606.eb585f8   	  1.2M	 53.9M
$ qemu-aarch64 ./result/bin/spigot "1+1"
2

works

@delroth delroth added the 12.approvals: 1 This PR was reviewed and approved by one person. label Sep 8, 2023
@Artturin Artturin merged commit 864112c into NixOS:master Sep 8, 2023
@ghost ghost deleted the dont-build-libgcc-twice branch October 22, 2023 11:22
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 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cross-compiled binaries have two different libgccs in their closure

2 participants