Summary: | toolchain.eclass should set CFLAGS_FOR_TARGET/CXXFLAGS_FOR_TARGET | ||
---|---|---|---|
Product: | Gentoo Linux | Reporter: | Andrii Batyiev <batyiev> |
Component: | Eclasses | Assignee: | Gentoo Toolchain Maintainers <toolchain> |
Status: | UNCONFIRMED --- | ||
Severity: | enhancement | CC: | arsen, batyiev, sam |
Priority: | Normal | ||
Version: | unspecified | ||
Hardware: | All | ||
OS: | Linux | ||
Whiteboard: | |||
Package list: | Runtime testing required: | --- |
Description
Andrii Batyiev
2024-01-21 16:15:31 UTC
From configure.ac: ``` # During gcc bootstrap, if we use some random cc for stage1 then CFLAGS # might be empty or "-g". We don't require a C++ compiler, so CXXFLAGS # might also be empty (or "-g", if a non-GCC C++ compiler is in the path). # We want to ensure that TARGET libraries (which we know are built with # gcc) are built with "-O2 -g", so include those options when setting # CFLAGS_FOR_TARGET and CXXFLAGS_FOR_TARGET. if test "x$CFLAGS_FOR_TARGET" = x; then if test "x${is_cross_compiler}" = xyes; then CFLAGS_FOR_TARGET="-g -O2" else CFLAGS_FOR_TARGET=$CFLAGS case " $CFLAGS " in *" -O2 "*) ;; *) CFLAGS_FOR_TARGET="-O2 $CFLAGS_FOR_TARGET" ;; esac case " $CFLAGS " in *" -g "* | *" -g3 "*) ;; *) CFLAGS_FOR_TARGET="-g $CFLAGS_FOR_TARGET" ;; esac fi fi AC_SUBST(CFLAGS_FOR_TARGET) ``` It defaults to CFLAGS (resp. CXXFLAGS). Pretty sure Arsen and I looked at this and concluded the above when we did the last *FLAGS rework in the eclass in commit bb2d045c02a6ca647ef3280f4987cbc0d14e5a7e Author: Sam James <sam@gentoo.org> Date: Fri Sep 29 00:27:06 2023 +0100 toolchain.eclass: rework bootstrapping logic [...] Please provide some explanation as to why you believe this is not the case, or why that's not sufficient. But you filter CFLAGS/CXXFLAGS for gcc in `gcc_do_filter_flags()` function, so libraries would also use filtered flags - I don't think it is expected (I just wanted `-Oz` instead of `-O2` for libstdc++). I feel like two things are getting mixed here, though. Setting CFLAGS_FOR_TARGET and CXXFLAGS_FOR_TARGET doesn't fix the filtering problem, does it? If we do: ``` --- a/eclass/toolchain.eclass +++ b/eclass/toolchain.eclass @@ -1722,6 +1722,8 @@ gcc_do_make() { STAGE1_LDFLAGS=${STAGE1_LDFLAGS-"${abi_ldflags} ${LDFLAGS}"} BOOT_CFLAGS=${BOOT_CFLAGS-"$(get_abi_CFLAGS ${TARGET_DEFAULT_ABI}) ${CFLAGS}"} BOOT_LDFLAGS=${BOOT_LDFLAGS-"${abi_ldflags} ${LDFLAGS}"} + CFLAGS_FOR_TARGET="${CFLAGS_FOR_TARGET:-${CFLAGS}}" + CXXFLAGS_FOR_TARGET="${CXXFLAGS_FOR_TARGET:-${CXXFLAGS}}" LDFLAGS_FOR_TARGET="${LDFLAGS_FOR_TARGET:-${LDFLAGS}}" emakeargs+=( @@ -1729,6 +1731,8 @@ gcc_do_make() { STAGE1_LDFLAGS="${STAGE1_LDFLAGS}" BOOT_CFLAGS="${BOOT_CFLAGS}" BOOT_LDFLAGS="${BOOT_LDFLAGS}" + CFLAGS_FOR_TARGET="${CFLAGS_FOR_TARGET}" + CXXFLAGS_FOR_TARGET="${CXXFLAGS_FOR_TARGET}" LDFLAGS_FOR_TARGET="${LDFLAGS_FOR_TARGET}" ) fi ``` which is what the title & comment 0 suggests, how does that avoid the filtering? By that point, the filtering is already done. (In reply to Sam James from comment #4) > I feel like two things are getting mixed here, though. > > Setting CFLAGS_FOR_TARGET and CXXFLAGS_FOR_TARGET doesn't fix the filtering > problem, does it? > The *_FOR_TARGET could be set before filtering (I'm not sure how the crosscompile should be handled here): --- a/eclass/toolchain.eclass 2024-01-23 06:10:40.000000000 -0000 +++ b/eclass/toolchain.eclass 2024-01-29 18:26:22.351685558 -0000 @@ -755,6 +755,11 @@ BUILD_CONFIG_TARGETS=() is-flagq '-O3' && BUILD_CONFIG_TARGETS+=( bootstrap-O3 ) + if ! is_crosscompile ; then + CFLAGS_FOR_TARGET="${CFLAGS_FOR_TARGET:-${CFLAGS}}" + CXXFLAGS_FOR_TARGET="${CXXFLAGS_FOR_TARGET:-${CXXFLAGS}}" + fi + downgrade_arch_flags gcc_do_filter_flags @@ -767,6 +772,8 @@ einfo "CFLAGS=\"${CFLAGS}\"" einfo "CXXFLAGS=\"${CXXFLAGS}\"" einfo "LDFLAGS=\"${LDFLAGS}\"" + einfo "CFLAGS_FOR_TARGET=\"${CFLAGS_FOR_TARGET}\"" + einfo "CXXFLAGS_FOR_TARGET=\"${CXXFLAGS_FOR_TARGET}\"" # Force internal zip based jar script to avoid random # issues with 3rd party jar implementations. bug #384291 @@ -1729,6 +1736,8 @@ STAGE1_LDFLAGS="${STAGE1_LDFLAGS}" BOOT_CFLAGS="${BOOT_CFLAGS}" BOOT_LDFLAGS="${BOOT_LDFLAGS}" + CFLAGS_FOR_TARGET="${CFLAGS_FOR_TARGET}" + CXXFLAGS_FOR_TARGET="${CXXFLAGS_FOR_TARGET}" LDFLAGS_FOR_TARGET="${LDFLAGS_FOR_TARGET}" ) fi |