Specify header path in CT_CC_SYSROOT_ARG only for glibc

When building a non-sysrooted toolchain, `--with-headers` argument is
specified in `CT_CC_SYSROOT_ARG` as a hack, supposedly because "final
gcc will define disable_glibc while building libgcc, and you'll have no
profiling."

This, however, leads to `--with-headers` being specified multiple times
when building libstdc++ for additional libc variants (e.g. newlib-nano
and picolibc) and results in wrong libc headers being used by the
libstdc++ build under certain circumstances -- GCC does not use the last
specified `--with-headers` when building for macOS and Windows hosts.

Since the above hack is intended for glibc only, this commit adds a
check to ensure that `--with-headers` is added to `CT_CC_SYSROOT_ARG`
only when building glibc.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
This commit is contained in:
Stephanos Ioannidis 2024-09-23 17:36:29 +09:00 committed by Chris Packham
parent 0d2e5c751b
commit 9884db4c87

View File

@ -361,10 +361,12 @@ if [ -z "${CT_RESTART}" ]; then
# binutils 2.14 and later obey it, older binutils ignore it.
# Lets you build a working 32->64 bit cross gcc
CT_BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
# Use --with-headers, else final gcc will define disable_glibc while
# building libgcc, and you'll have no profiling
CT_CC_CORE_SYSROOT_ARG=("--without-headers")
CT_CC_SYSROOT_ARG=("--with-headers=${CT_HEADERS_DIR}")
if [ "${CT_LIBC_GLIBC}" = "y" ]; then
# Use --with-headers, else final gcc will define disable_glibc while
# building libgcc, and you'll have no profiling
CT_CC_SYSROOT_ARG=("--with-headers=${CT_HEADERS_DIR}")
fi
fi
CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}"
CT_DoExecLog ALL mkdir -p "${CT_DEBUGROOT_DIR}"