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: do not install sys-include headers for cross-compilers. #219811

Merged
merged 1 commit into from
Mar 11, 2023

Conversation

trofi
Copy link
Contributor

@trofi trofi commented Mar 6, 2023

Before the change include headers for cross-compilers like pkgsStatic looked like this:

$ nix build -L --impure --expr 'with import ./. {}; pkgsStatic.stdenv.mkDerivation { name = "probe"; buildCommand = "echo | $CXX -x c++ -E -v - |& fgrep -B10 search; exit 1"; }' |& unnix

#include "..." search starts here:
#include <...> search starts here:
 /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1
 /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1/x86_64-unknown-linux-musl
 /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1/backward
 /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/sys-include
 /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include
 /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include
 /<<NIX>>/musl-static-x86_64-unknown-linux-musl-1.2.3-dev/include
 /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include-fixed
End of search list.

Note that .../sys-include inhibits the effect of musl-static-x86_64-unknown-linux-musl-1.2.3-dev/include.

After the change the paths look as expected:

$ nix build -L --impure --expr 'with import ./. {}; pkgsStatic.stdenv.mkDerivation { name = "probe"; buildCommand = "echo | $CXX -x c++ -E -v - |& fgrep -B10 search; exit 1"; }' |& unnix

#include "..." search starts here:
#include <...> search starts here:
 /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1
 /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1/x86_64-unknown-linux-musl
 /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1/backward
 /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include
 /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include
 /<<NIX>>/musl-static-x86_64-unknown-linux-musl-1.2.3-dev/include
 /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include-fixed
End of search list.
Description of changes
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.05 Release Notes (or backporting 22.11 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.

Before the change include headers for cross-compilers like `pkgsStatic`
looked like this:

    $ nix build -L --impure --expr 'with import ./. {}; pkgsStatic.stdenv.mkDerivation { name = "probe"; buildCommand = "echo | $CXX -x c++ -E -v - |& fgrep -B10 search; exit 1"; }' |& unnix

    #include "..." search starts here:
    #include <...> search starts here:
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1/x86_64-unknown-linux-musl
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1/backward
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/sys-include
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include
     /<<NIX>>/musl-static-x86_64-unknown-linux-musl-1.2.3-dev/include
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include-fixed
    End of search list.

Note that `.../sys-include` inhibits the effect of `musl-static-x86_64-unknown-linux-musl-1.2.3-dev/include`.

After the change the paths look as expected:

    $ nix build -L --impure --expr 'with import ./. {}; pkgsStatic.stdenv.mkDerivation { name = "probe"; buildCommand = "echo | $CXX -x c++ -E -v - |& fgrep -B10 search; exit 1"; }' |& unnix

    #include "..." search starts here:
    #include <...> search starts here:
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1/x86_64-unknown-linux-musl
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include/c++/13.0.1/backward
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/../../../../x86_64-unknown-linux-musl/include
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include
     /<<NIX>>/musl-static-x86_64-unknown-linux-musl-1.2.3-dev/include
     /<<NIX>>/x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include-fixed
    End of search list.
@trofi
Copy link
Contributor Author

trofi commented Mar 11, 2023

Lightly tested a few targets from x86_64-linux host:

  • pkgsCross.mingw64
  • pkgsCross.riscv64
  • pkgsCross.mmix
  • pkgsMusl
  • pkgsi686Linux
  • pkgsStatic

All seem to work.

@trofi trofi merged commit d65d457 into NixOS:staging Mar 11, 2023
@trofi trofi deleted the gcc-cross-no-sys-includes branch March 11, 2023 20:49
@alyssais
Copy link
Member

This change has broken pkgsStatic.netbsd.compat on staging-next, which is needed for fts, for example by glib.

@trofi
Copy link
Contributor Author

trofi commented Mar 17, 2023

Can reproduce locally as:

$ nix build -f. -L pkgsStatic.netbsd.compat
...
       > checking how to run the C preprocessor... x86_64-unknown-linux-musl-cpp
       > configure: error: in `/build/cvs-export/tools/compat':
       > configure: error: C preprocessor "x86_64-unknown-linux-musl-cpp" fails sanity check
       > See `config.log' for more details

I suspect we are using unwrapped version of cpp here and are missing standard -idirafter flags. It was previously masked by the default path. Looking to confirm.

@trofi
Copy link
Contributor Author

trofi commented Mar 17, 2023

Confirmed it's unwrapped:

bash-5.2$ dev>which x86_64-unknown-linux-musl-gcc
/nix/store/dskdlhryjxq1bdk8qsmjncc4z7ak79yn-x86_64-unknown-linux-musl-stage-final-gcc-wrapper-13.0.0/bin/x86_64-unknown-linux-musl-gcc

bash-5.2$ dev>which x86_64-unknown-linux-musl-cpp
/nix/store/bsh1kvhm5sia7ps46fyzcgycjfqg1jyi-x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/bin/x86_64-unknown-linux-musl-cpp

And preoprocessor is validated against system headers without any extra include paths:

configure:3142: x86_64-unknown-linux-musl-cpp  conftest.c
In file included from /nix/store/bsh1kvhm5sia7ps46fyzcgycjfqg1jyi-x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include/syslimits.h:7,
                 from /nix/store/bsh1kvhm5sia7ps46fyzcgycjfqg1jyi-x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include/limits.h:34,
                 from conftest.c:10:
/nix/store/bsh1kvhm5sia7ps46fyzcgycjfqg1jyi-x86_64-unknown-linux-musl-stage-final-gcc-13.0.0/lib/gcc/x86_64-unknown-linux-musl/13.0.1/include/limits.h:205:75: error: no include path in which to search for limits.h
  205 | #include_next <limits.h>                /* recurse down to the real one */
      |                                                                           ^
configure:3142: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "libnbcompat"
| #define PACKAGE_TARNAME "libnbcompat"
| #define PACKAGE_VERSION "noversion"
| #define PACKAGE_STRING "libnbcompat noversion"
| #define PACKAGE_BUGREPORT "lib-bug-people@NetBSD.org"
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
| #ifdef __STDC__
| # include <limits.h>
| #else
| # include <assert.h>
| #endif
|                    Syntax error
configure:3172: error: in `/home/slyfox/dev/git/nixpkgs/cvs-export/tools/compat':
configure:3174: error: C preprocessor "x86_64-unknown-linux-musl-cpp" fails sanity check
See `config.log' for more details

As a workaround you can try to pass CPP="$CC -E". Ideally we will need to wrap cpp as well.

If it's a wider spread breakage we'll need to roll the sys-include removal back and try again when more fixes are applied.

@trofi
Copy link
Contributor Author

trofi commented Mar 17, 2023

Proposed the cpp wrapping fix as #221677

@trofi
Copy link
Contributor Author

trofi commented Jul 26, 2023

Another regression manifested itself: #245455

Proposed the revert in #245550

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants