nixpkgs-suyu/pkgs/build-support
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
..
add-opengl-runpath
agda
alternatives
appimage appimageTools.wrapAppImage: default produced derivations to sourceProvenance binaryNativeCode 2022-06-11 17:17:12 +01:00
bintools-wrapper gcc: pass --with-build-sysroot=/ for gcc builds 2022-07-23 18:40:07 +01:00
build-bazel-package
build-fhs-userenv buildFHSUserEnv: append graphics share to XDG_DATA_DIR 2022-03-24 12:53:39 -07:00
build-fhs-userenv-bubblewrap Merge pull request #164825 from ilya-fedin/fhs-less-copy 2022-04-11 16:37:01 +03:00
build-graalvm-native-image buildGraalvmNativeImage: allow LC_ALL overrides 2022-07-03 18:16:38 +01:00
build-setupcfg
buildenv
cc-wrapper cc-wrapper: fix typo in shell script 2022-06-17 20:25:27 -04:00
coq Do not rely on legacy ocaml passthru value. 2022-07-08 14:33:24 +02:00
dhall
docker dockerTools: use list of strings for configureFlags 2022-07-15 10:23:07 +10:00
dotnet Merge pull request #173889 from IvarWithoutBones/fix/dotnet-cross 2022-07-16 12:37:11 +02:00
emacs emacsWithPackages: Rely on package.el for autoloads 2022-07-11 20:22:20 -05:00
expand-response-params treewide: add enableParallelBuilding's to bootstrap packages so hashes stay the same 2022-05-25 16:03:14 +03:00
fake-nss fakeNss: move to toplevel 2022-03-24 18:47:30 +01:00
fetchbitbucket
fetchbower
fetchbzr
fetchcvs
fetchdarcs
fetchdocker
fetchfirefoxaddon testers.invalidateFetcherByDrvHash: Move from top-level 2022-05-05 12:08:50 +02:00
fetchfossil
fetchgit Revert "nix-prefetch-git: Fix inconsistency with fetchgit regarding deepClone" 2022-06-30 11:52:36 +00:00
fetchgitea
fetchgithub unstableGitUpdater: fix updating fetchzip-based sources 2022-05-24 19:12:12 +02:00
fetchgitiles
fetchgitlab unstableGitUpdater: fix updating fetchzip-based sources 2022-05-24 19:12:12 +02:00
fetchgitlocal
fetchgx
fetchhg
fetchipfs treewide: clean up obsolete version checks 2022-03-22 10:54:11 +00:00
fetchmavenartifact
fetchmtn
fetchnextcloudapp treewide: remove nativeBuildInputs that are in stdenv 2022-04-16 21:46:46 +03:00
fetchpatch testers.invalidateFetcherByDrvHash: Move from top-level 2022-05-05 12:08:50 +02:00
fetchrepoorcz
fetchrepoproject
fetchs3
fetchsavannah
fetchsourcehut treewide: extraPostFetch -> postFetch 2022-05-23 17:18:50 +03:00
fetchsvn
fetchsvnrevision
fetchsvnssh
fetchurl Merge pull request #164662 from infinisil/fetchurl-curlOpts-list 2022-06-30 21:10:57 +02:00
fetchzip fetchzip: force UTF-8 compatibel locale to unpack non-ASCII symbols 2022-06-11 11:25:58 +01:00
flutter
go garble: 0.5.1 -> 0.6.0 2022-03-23 06:31:49 +00:00
icon-conv-tools
install-shell-files
java
kernel compressFirmwareXz: fix with empty lib/firmware 2022-05-26 07:08:50 +00:00
libredirect
make-darwin-bundle Merge pull request #165111 from toonn/darwin-bundle-outputBin 2022-04-22 12:04:09 +01:00
make-desktopitem build-support/makeDesktopItem: make overridable 2022-06-09 15:32:44 +01:00
make-startupitem
make-symlinks
mkshell
mono-dll-fixer
nix-gitignore treewide: clean up obsolete version checks 2022-03-22 10:54:11 +00:00
node/fetch-yarn-deps fetchYarnDeps: support hash in pkg.integrity (#177255) 2022-06-15 20:13:41 +02:00
nuke-references treewide: add enableParallelBuilding's to bootstrap packages so hashes stay the same 2022-05-25 16:03:14 +03:00
ocaml treewide: Simplify negated uses of versionAtLeast, versionOlder 2022-04-25 13:35:24 -07:00
oci-tools
pkg-config-wrapper treewide: add enableParallelBuilding's to bootstrap packages so hashes stay the same 2022-05-25 16:03:14 +03:00
prefer-remote-fetch prefer-remote-fetch: don't overwrite fetcher's which set preferLocalBuild explicitly 2022-06-03 14:05:37 +02:00
references-by-popularity
release
remove-references-to
replace-secret
rust tests.buildRustCrate: add rcgen test 2022-06-14 20:09:33 -04:00
setup-hooks Merge pull request #172769 from ncfavier/wrappers-append-args 2022-06-12 11:46:03 +01:00
singularity-tools singularity: enable setting vm mem in buildImage 2022-03-03 17:09:48 -05:00
skaware skawarePackages.buildPackage: fix typo in comment 2022-05-09 15:52:56 +00:00
snap
src-only srcOnly: fix with separateDebugInfo and/or multiple outputs 2022-07-02 19:32:24 +02:00
substitute
substitute-files
templaterpm maintainers: remove tstrobel 2022-06-29 00:54:53 +02:00
testers testers.testVersion: if grep failed then print the output of the command 2022-05-16 16:16:35 +03:00
trivial-builders treewide: nixosTest -> testers.nixosTest 2022-05-09 14:16:06 +02:00
vm treewide: change some glibc to stdenv.cc.libc 2022-05-27 05:57:43 +03:00
wrapper-common
writers builders/writeHaskell: build with threaded GHC runtime 2022-06-30 10:12:50 +02:00
build-maven.nix
build-pecl.nix
closure-info.nix
plugins.nix
replace-dependency.nix replace-dependency: fix a syntax error while generating references.nix 2022-06-12 06:44:30 +04:00
setup-systemd-units.nix
source-from-head-fun.nix
trivial-builders.nix treewide: remove usage of runCommandNoCC aliases 2022-06-07 16:57:06 +02:00