nixpkgs/pkgs/development/compilers/gcc
Sergei Trofimovich 34636efced gcc: pass --with-build-sysroot=/ for gcc builds
Without this change cross-built gcc fails to detect stack protector style:

    $ nix log -f pkgs/stdenv/linux/make-bootstrap-tools-cross.nix powerpc64le.bootGCC | fgrep __stack_chk_fail
    checking __stack_chk_fail in target C library... no
    checking __stack_chk_fail in target C library... no

It happens because gcc treats search paths differently:

    https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/configure.ac;h=446747311a6aec3c810ad6aa4190f7bd383b94f7;hb=HEAD#l2458

     if test x$host != x$target || test "x$TARGET_SYSTEM_ROOT" != x ||
        test x$build != x$host || test "x$with_build_sysroot" != x; then
       ...
       if test "x$with_build_sysroot" != "x"; then
         target_header_dir="${with_build_sysroot}${native_system_header_dir}"
       elif test "x$with_sysroot" = x; then
         target_header_dir="${test_exec_prefix}/${target_noncanonical}/sys-include"
       elif test "x$with_sysroot" = xyes; then
         target_header_dir="${test_exec_prefix}/${target_noncanonical}/sys-root${native_system_header_dir}"
       else
         target_header_dir="${with_sysroot}${native_system_header_dir}"
       fi
     else
       target_header_dir=${native_system_header_dir}
     fi

By passing --with-build-sysroot=/ we trick cross-case to use
`target_header_dir="${with_sysroot}${native_system_header_dir}"`
which makes it equivalent to non-cross
`target_header_dir="${with_build_sysroot}${native_system_header_dir}"`

Tested the following setups:
- cross-compiler without libc headers (powerpc64le-static)
- cross-compiler with libc headers (powerpc64le-debug)
- cross-build compiler with libc headers (powerpc64le bootstrapTools)

Before the change only 2 of 3 compilers detected libc headers.
After the change all 3 compilers detected libc headers.

For darwin we silently ignore '-syslibroot //' argument as it does not
introduce impurities.

While at it dropped mingw special case for no-libc build. Before the change
we passed both '--without-headers --with-native-system-headers-dir' for
no-libc gcc-static builds. This tricked darwin builds to find sys/sdt.h
and fail inhibid_libc builds. Now all targets avoid passing native headers
for gcc-static builds.

While at it fixed correct headers passing to
--with-native-system-headers-dir= in host != target case: we were passing
host's headers where intention was to pass target's headers.
Noticed the mismatch as a build failure on pkgsCross.powernv.stdenv.cc
on darwin where `sys/sdt.h` is present in host's headers (libSystem)
but not target's headers (`glibc`).

Co-authored-by: Adam Joseph <54836058+amjoseph-nixpkgs@users.noreply.github.com>
2022-07-23 18:40:07 +01:00
..
4.8 gcc{4..10}: add aarch64-darwin to badPlatforms 2022-04-14 10:02:19 -07:00
4.9 gcc49: Fix build on darwin 2022-06-23 10:42:39 -04:00
6 gcc{4..10}: add aarch64-darwin to badPlatforms 2022-04-14 10:02:19 -07:00
7 gcc{4..10}: add aarch64-darwin to badPlatforms 2022-04-14 10:02:19 -07:00
8 gcc{4..10}: add aarch64-darwin to badPlatforms 2022-04-14 10:02:19 -07:00
9 gcc9: 9.3.0 -> 9.5.0 2022-06-05 23:24:46 +02:00
10 gcc10: 10.3.0 -> 10.4.0 2022-06-29 10:07:32 +02:00
11 gdc: match gcc version 2022-05-20 13:49:55 +02:00
12 pkgsMusl.gcc12: backport build fix (PR106102) 2022-07-09 09:35:25 +01:00
common gcc: pass --with-build-sysroot=/ for gcc builds 2022-07-23 18:40:07 +01:00
builder.sh pkgsStatic.stdenv.cc.cc: put static libs in $lib 2022-03-22 17:56:11 +00:00
gcc-12-gfortran-driving.patch gcc12, gfortran12, gnat12: init at 12.1.0 2022-05-07 13:50:47 +01:00
gcc-12-no-sys-dirs.patch gcc12, gfortran12, gnat12: init at 12.1.0 2022-05-07 13:50:47 +01:00
gfortran-darwin-NXConstStr.patch
gfortran-driving.patch
gnat-cflags-11.patch gnat11: extract gnat-cflags-11.patch from gnat-cflags.patch 2021-05-04 20:14:01 -07:00
gnat-cflags.patch
libgomp-dont-force-initial-exec.patch
libphobos.patch
libsanitizer-no-cyclades-9.patch gcc: remove <cyclades.h> from libsanitizer 2021-09-20 19:37:19 +01:00
libsanitizer-no-cyclades.patch gcc: remove <cyclades.h> from libsanitizer 2021-09-20 19:37:19 +01:00
libstdc++-netbsd-ctypes.patch
libstdc++-target.patch
no-sys-dirs-riscv-gcc9.patch gcc9: Add no-sys-dir patch for RISC-V (#154230) 2022-01-12 06:27:48 -05:00
no-sys-dirs-riscv.patch gcc{10,11}: add no-sys-dir patch for RiscV 2021-11-30 16:58:45 +08:00
no-sys-dirs.patch
parallel-bconfig.patch
ppc-musl.patch
res_state-not-declared.patch
sigsegv-not-declared.patch
struct-sigaltstack-4.9.patch
struct-sigaltstack.patch
struct-ucontext-4.5.patch
struct-ucontext-4.8.patch
struct-ucontext-libjava.patch
struct-ucontext.patch
update-mcfgthread-patches.sh
use-source-date-epoch.patch