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

stdenv: Nix-driven bootstrap of gcc #209870

Merged
merged 14 commits into from Apr 3, 2023
Merged

stdenv: Nix-driven bootstrap of gcc #209870

merged 14 commits into from Apr 3, 2023

Conversation

ghost
Copy link

@ghost ghost commented Jan 9, 2023

✔️ Good to go.

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 WIP: GCC with separated runtime libraries #132343

Incorporates

Closes

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 acoding binge at an opportune moment, so we wouldn't waste acrisis.

@github-actions github-actions bot added the 6.topic: stdenv Standard environment label Jan 9, 2023
@ghost ghost mentioned this pull request Jan 9, 2023
13 tasks
@trofi
Copy link
Contributor

trofi commented Jan 9, 2023

@ghost

This comment was marked as outdated.

@ghost

This comment was marked as outdated.

@ghost

This comment was marked as outdated.

@ghost

This comment was marked as outdated.

@trofi
Copy link
Contributor

trofi commented Jan 10, 2023

Could you submit this as a standalone PR? My revert-mallinfo2.patch hack doesn't fix the problem on x86_64, but I think your solution does (currently checking).

Yeah, will do.

@trofi
Copy link
Contributor

trofi commented Jan 10, 2023

Could you submit this as a standalone PR? My revert-mallinfo2.patch hack doesn't fix the problem on x86_64, but I think your solution does (currently checking).

Yeah, will do.

Done as #210004

@ghost

This comment was marked as outdated.

@ghost

This comment was marked as outdated.

@ghost

This comment was marked as outdated.

@ghost ghost mentioned this pull request Jan 11, 2023
3 tasks
@ghost

This comment was marked as outdated.

@ghost

This comment was marked as outdated.

@ghost

This comment was marked as outdated.

@ghost

This comment was marked as outdated.

@ghost

This comment was marked as outdated.

@ofborg ofborg bot removed the 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild label Jan 14, 2023
@trofi

This comment was marked as resolved.

@vcunat

This comment was marked as duplicate.

@wegank wegank mentioned this pull request Apr 27, 2023
12 tasks
@ghost ghost mentioned this pull request Apr 27, 2023
PetarKirov added a commit to PetarKirov/dlang.nix that referenced this pull request May 7, 2023
…so.1`

After upgrading to a recent version of Nixpkgs (2023-04-18), the build broke
with the following error:

    ...
    auto-patchelf: 6 dependencies could not be satisfied
    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/lib/libphobos2.so.0.98.0

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/rdmd

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dub

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dustmite

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/ddemangle

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dmd

    auto-patchelf failed to find all the required dependencies.
    ...

After investigation, it turned out that the cuase was a recent [change in
Nixpkgs][0] after which `libgcc_s.so` is no longer part of the `glibc` package:

Before (nixpkgs @ 2022-03-30):

    > nix build --json 'github:NixOS/nixpkgs/710fed5a2483f945b14f4a58af2cd3676b42d8c8#glibc^out' \
        | jq -r '.[0].outputs.out' \
        | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    /nix/store/q29bwjibv9gi9n86203s38n0577w09sx-glibc-2.33-117/lib/libgcc_s.so.1
    /nix/store/q29bwjibv9gi9n86203s38n0577w09sx-glibc-2.33-117/lib/libgcc_s.so

After (nixpkgs @ 2023-04-18):

    > nix build --json 'github:NixOS/nixpkgs/555daa9d339b3df75e58ee558a4fec98ea92521e#glibc^out' \
        | jq -r '.[0].outputs.out' \
        | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    (no output)

Instead, we should use `gccForLibs.libgcc` as it includes exactly what we need:

    > nix build --json 'github:NixOS/nixpkgs/555daa9d339b3df75e58ee558a4fec98ea92521e#gccForLibs^libgcc' \
       | jq -r '.[0].outputs.libgcc' \
       | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    /nix/store/5w5qpm9z3iyib615pdih6nvk9spv3jbv-gcc-12.2.0-libgcc/lib/libgcc_s.so.1
    /nix/store/5w5qpm9z3iyib615pdih6nvk9spv3jbv-gcc-12.2.0-libgcc/lib/libgcc_s.so

    This is nixpkgs again @ 2023-04-18, this time using `gccForLibs.libgcc`
    instead of `glibc.out`.

[`gccForLibs`][1] is essentially `gcc.lib`:
* an alias to `stdenv.cc.cc` if the host and target are the same and are GNU or
* an alias to `gcc.cc` when `stdenv` is LLVM based as then `stdenv.cc.cc` would
  refer to clang and the `lib` output point to libclang libs, which are very
  different from what we need.

[0]: NixOS/nixpkgs#209870
[1]: NixOS/nixpkgs#91293
PatrickShaw added a commit to PatrickShaw/eww that referenced this pull request Jun 23, 2023
@ghost
Copy link
Author

ghost commented Jun 30, 2023

@trofi

This comment was marked as resolved.

PetarKirov added a commit to PetarKirov/dlang.nix that referenced this pull request Sep 4, 2023
…so.1`

After upgrading to a recent version of Nixpkgs (2023-04-18), the build broke
with the following error:

    ...
    auto-patchelf: 6 dependencies could not be satisfied
    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/lib/libphobos2.so.0.98.0

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/rdmd

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dub

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dustmite

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/ddemangle

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dmd

    auto-patchelf failed to find all the required dependencies.
    ...

After investigation, it turned out that the cuase was a recent [change in
Nixpkgs][0] after which `libgcc_s.so` is no longer part of the `glibc` package:

Before (nixpkgs @ 2022-03-30):

    > nix build --json 'github:NixOS/nixpkgs/710fed5a2483f945b14f4a58af2cd3676b42d8c8#glibc^out' \
        | jq -r '.[0].outputs.out' \
        | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    /nix/store/q29bwjibv9gi9n86203s38n0577w09sx-glibc-2.33-117/lib/libgcc_s.so.1
    /nix/store/q29bwjibv9gi9n86203s38n0577w09sx-glibc-2.33-117/lib/libgcc_s.so

After (nixpkgs @ 2023-04-18):

    > nix build --json 'github:NixOS/nixpkgs/555daa9d339b3df75e58ee558a4fec98ea92521e#glibc^out' \
        | jq -r '.[0].outputs.out' \
        | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    (no output)

Instead, we should use `gccForLibs.libgcc` as it includes exactly what we need:

    > nix build --json 'github:NixOS/nixpkgs/555daa9d339b3df75e58ee558a4fec98ea92521e#gccForLibs^libgcc' \
       | jq -r '.[0].outputs.libgcc' \
       | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    /nix/store/5w5qpm9z3iyib615pdih6nvk9spv3jbv-gcc-12.2.0-libgcc/lib/libgcc_s.so.1
    /nix/store/5w5qpm9z3iyib615pdih6nvk9spv3jbv-gcc-12.2.0-libgcc/lib/libgcc_s.so

    This is nixpkgs again @ 2023-04-18, this time using `gccForLibs.libgcc`
    instead of `glibc.out`.

[`gccForLibs`][1] is essentially `gcc.lib`:
* an alias to `stdenv.cc.cc` if the host and target are the same and are GNU or
* an alias to `gcc.cc` when `stdenv` is LLVM based as then `stdenv.cc.cc` would
  refer to clang and the `lib` output point to libclang libs, which are very
  different from what we need.

[0]: NixOS/nixpkgs#209870
[1]: NixOS/nixpkgs#91293
PetarKirov added a commit to PetarKirov/dlang.nix that referenced this pull request Sep 20, 2023
…so.1`

After upgrading to a recent version of Nixpkgs (2023-04-18), the build broke
with the following error:

    ...
    auto-patchelf: 6 dependencies could not be satisfied
    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/lib/libphobos2.so.0.98.0

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/rdmd

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dub

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dustmite

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/ddemangle

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dmd

    auto-patchelf failed to find all the required dependencies.
    ...

After investigation, it turned out that the cuase was a recent [change in
Nixpkgs][0] after which `libgcc_s.so` is no longer part of the `glibc` package:

Before (nixpkgs @ 2022-03-30):

    > nix build --json 'github:NixOS/nixpkgs/710fed5a2483f945b14f4a58af2cd3676b42d8c8#glibc^out' \
        | jq -r '.[0].outputs.out' \
        | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    /nix/store/q29bwjibv9gi9n86203s38n0577w09sx-glibc-2.33-117/lib/libgcc_s.so.1
    /nix/store/q29bwjibv9gi9n86203s38n0577w09sx-glibc-2.33-117/lib/libgcc_s.so

After (nixpkgs @ 2023-04-18):

    > nix build --json 'github:NixOS/nixpkgs/555daa9d339b3df75e58ee558a4fec98ea92521e#glibc^out' \
        | jq -r '.[0].outputs.out' \
        | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    (no output)

Instead, we should use `gccForLibs.libgcc` as it includes exactly what we need:

    > nix build --json 'github:NixOS/nixpkgs/555daa9d339b3df75e58ee558a4fec98ea92521e#gccForLibs^libgcc' \
       | jq -r '.[0].outputs.libgcc' \
       | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    /nix/store/5w5qpm9z3iyib615pdih6nvk9spv3jbv-gcc-12.2.0-libgcc/lib/libgcc_s.so.1
    /nix/store/5w5qpm9z3iyib615pdih6nvk9spv3jbv-gcc-12.2.0-libgcc/lib/libgcc_s.so

    This is nixpkgs again @ 2023-04-18, this time using `gccForLibs.libgcc`
    instead of `glibc.out`.

[`gccForLibs`][1] is essentially `gcc.lib`:
* an alias to `stdenv.cc.cc` if the host and target are the same and are GNU or
* an alias to `gcc.cc` when `stdenv` is LLVM based as then `stdenv.cc.cc` would
  refer to clang and the `lib` output point to libclang libs, which are very
  different from what we need.

[0]: NixOS/nixpkgs#209870
[1]: NixOS/nixpkgs#91293
PetarKirov added a commit to PetarKirov/dlang.nix that referenced this pull request Sep 20, 2023
…so.1`

After upgrading to a recent version of Nixpkgs (2023-04-18), the build broke
with the following error:

    ...
    auto-patchelf: 6 dependencies could not be satisfied
    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/lib/libphobos2.so.0.98.0

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/rdmd

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dub

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dustmite

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/ddemangle

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dmd

    auto-patchelf failed to find all the required dependencies.
    ...

After investigation, it turned out that the cuase was a recent [change in
Nixpkgs][0] after which `libgcc_s.so` is no longer part of the `glibc` package:

Before (nixpkgs @ 2022-03-30):

    > nix build --json 'github:NixOS/nixpkgs/710fed5a2483f945b14f4a58af2cd3676b42d8c8#glibc^out' \
        | jq -r '.[0].outputs.out' \
        | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    /nix/store/q29bwjibv9gi9n86203s38n0577w09sx-glibc-2.33-117/lib/libgcc_s.so.1
    /nix/store/q29bwjibv9gi9n86203s38n0577w09sx-glibc-2.33-117/lib/libgcc_s.so

After (nixpkgs @ 2023-04-18):

    > nix build --json 'github:NixOS/nixpkgs/555daa9d339b3df75e58ee558a4fec98ea92521e#glibc^out' \
        | jq -r '.[0].outputs.out' \
        | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    (no output)

Instead, we should use `gccForLibs.libgcc` as it includes exactly what we need:

    > nix build --json 'github:NixOS/nixpkgs/555daa9d339b3df75e58ee558a4fec98ea92521e#gccForLibs^libgcc' \
       | jq -r '.[0].outputs.libgcc' \
       | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    /nix/store/5w5qpm9z3iyib615pdih6nvk9spv3jbv-gcc-12.2.0-libgcc/lib/libgcc_s.so.1
    /nix/store/5w5qpm9z3iyib615pdih6nvk9spv3jbv-gcc-12.2.0-libgcc/lib/libgcc_s.so

    This is nixpkgs again @ 2023-04-18, this time using `gccForLibs.libgcc`
    instead of `glibc.out`.

[`gccForLibs`][1] is essentially `gcc.lib`:
* an alias to `stdenv.cc.cc` if the host and target are the same and are GNU or
* an alias to `gcc.cc` when `stdenv` is LLVM based as then `stdenv.cc.cc` would
  refer to clang and the `lib` output point to libclang libs, which are very
  different from what we need.

[0]: NixOS/nixpkgs#209870
[1]: NixOS/nixpkgs#91293
PetarKirov added a commit to PetarKirov/dlang.nix that referenced this pull request Sep 20, 2023
…so.1`

After upgrading to a recent version of Nixpkgs (2023-04-18), the build broke
with the following error:

    ...
    auto-patchelf: 6 dependencies could not be satisfied
    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/lib/libphobos2.so.0.98.0

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/rdmd

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dub

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dustmite

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/ddemangle

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dmd

    auto-patchelf failed to find all the required dependencies.
    ...

After investigation, it turned out that the cuase was a recent [change in
Nixpkgs][0] after which `libgcc_s.so` is no longer part of the `glibc` package:

Before (nixpkgs @ 2022-03-30):

    > nix build --json 'github:NixOS/nixpkgs/710fed5a2483f945b14f4a58af2cd3676b42d8c8#glibc^out' \
        | jq -r '.[0].outputs.out' \
        | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    /nix/store/q29bwjibv9gi9n86203s38n0577w09sx-glibc-2.33-117/lib/libgcc_s.so.1
    /nix/store/q29bwjibv9gi9n86203s38n0577w09sx-glibc-2.33-117/lib/libgcc_s.so

After (nixpkgs @ 2023-04-18):

    > nix build --json 'github:NixOS/nixpkgs/555daa9d339b3df75e58ee558a4fec98ea92521e#glibc^out' \
        | jq -r '.[0].outputs.out' \
        | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    (no output)

Instead, we should use `gccForLibs.libgcc` as it includes exactly what we need:

    > nix build --json 'github:NixOS/nixpkgs/555daa9d339b3df75e58ee558a4fec98ea92521e#gccForLibs^libgcc' \
       | jq -r '.[0].outputs.libgcc' \
       | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    /nix/store/5w5qpm9z3iyib615pdih6nvk9spv3jbv-gcc-12.2.0-libgcc/lib/libgcc_s.so.1
    /nix/store/5w5qpm9z3iyib615pdih6nvk9spv3jbv-gcc-12.2.0-libgcc/lib/libgcc_s.so

    This is nixpkgs again @ 2023-04-18, this time using `gccForLibs.libgcc`
    instead of `glibc.out`.

[`gccForLibs`][1] is essentially `gcc.lib`:
* an alias to `stdenv.cc.cc` if the host and target are the same and are GNU or
* an alias to `gcc.cc` when `stdenv` is LLVM based as then `stdenv.cc.cc` would
  refer to clang and the `lib` output point to libclang libs, which are very
  different from what we need.

[0]: NixOS/nixpkgs#209870
[1]: NixOS/nixpkgs#91293
PetarKirov added a commit to PetarKirov/dlang.nix that referenced this pull request Sep 21, 2023
…so.1`

After upgrading to a recent version of Nixpkgs (2023-04-18), the build broke
with the following error:

    ...
    auto-patchelf: 6 dependencies could not be satisfied
    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/lib/libphobos2.so.0.98.0

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/rdmd

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dub

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dustmite

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/ddemangle

    error: auto-patchelf could not satisfy dependency libgcc_s.so.1 wanted by
    /nix/store/kl8bjrlmlzcjz47c0n6kjsj1yxi6zpqm-dmd-binary-2.098.0/bin/dmd

    auto-patchelf failed to find all the required dependencies.
    ...

After investigation, it turned out that the cuase was a recent [change in
Nixpkgs][0] after which `libgcc_s.so` is no longer part of the `glibc` package:

Before (nixpkgs @ 2022-03-30):

    > nix build --json 'github:NixOS/nixpkgs/710fed5a2483f945b14f4a58af2cd3676b42d8c8#glibc^out' \
        | jq -r '.[0].outputs.out' \
        | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    /nix/store/q29bwjibv9gi9n86203s38n0577w09sx-glibc-2.33-117/lib/libgcc_s.so.1
    /nix/store/q29bwjibv9gi9n86203s38n0577w09sx-glibc-2.33-117/lib/libgcc_s.so

After (nixpkgs @ 2023-04-18):

    > nix build --json 'github:NixOS/nixpkgs/555daa9d339b3df75e58ee558a4fec98ea92521e#glibc^out' \
        | jq -r '.[0].outputs.out' \
        | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    (no output)

Instead, we should use `gccForLibs.libgcc` as it includes exactly what we need:

    > nix build --json 'github:NixOS/nixpkgs/555daa9d339b3df75e58ee558a4fec98ea92521e#gccForLibs^libgcc' \
       | jq -r '.[0].outputs.libgcc' \
       | xargs  -I{} find {} \( -type l -or -type f \) -name '*libgcc_s*'

    /nix/store/5w5qpm9z3iyib615pdih6nvk9spv3jbv-gcc-12.2.0-libgcc/lib/libgcc_s.so.1
    /nix/store/5w5qpm9z3iyib615pdih6nvk9spv3jbv-gcc-12.2.0-libgcc/lib/libgcc_s.so

    This is nixpkgs again @ 2023-04-18, this time using `gccForLibs.libgcc`
    instead of `glibc.out`.

[`gccForLibs`][1] is essentially `gcc.lib`:
* an alias to `stdenv.cc.cc` if the host and target are the same and are GNU or
* an alias to `gcc.cc` when `stdenv` is LLVM based as then `stdenv.cc.cc` would
  refer to clang and the `lib` output point to libclang libs, which are very
  different from what we need.

[0]: NixOS/nixpkgs#209870
[1]: NixOS/nixpkgs#91293
@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/why-does-the-nixos-infrastructure-have-to-be-hosted-in-a-centralized-way/46789/41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: emacs Text editor 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: stdenv Standard environment 8.has: clean-up 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 501+ 10.rebuild-darwin: 5001+ 10.rebuild-linux: 501+ 10.rebuild-linux: 5001+ 10.rebuild-linux-stdenv This PR causes stdenv to rebuild
Projects
None yet