commit: ec695aaabeef9ef78ca38e22294b6523ed4075da
Author: Matt Whitlock <gentoo <AT> mattwhitlock <DOT> name>
AuthorDate: Sat Sep 6 17:56:30 2025 +0000
Commit: James Le Cuirot <chewi <AT> gentoo <DOT> org>
CommitDate: Sat Jan 3 09:01:47 2026 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ec695aaa
multilib.eclass: derive BUILD_* before appending ABI flags
Per [1], we cannot have ${MULTILIB_USEDEP} in BDEPEND because it would
break cross-compiles, as ${MULTILIB_USEDEP} specifies ABIs of CHOST, not
of CBUILD.
However, this leads to a problem, as multilib.eclass does not preserve
the default build-machine toolchain before it appends the ABI flags to
the host-machine toolchain. Thus, when $(tc-getBUILD_CC) later pulls a
default value for BUILD_CC from CC, the ABI flags have already been
appended to CC, and BUILD_CC inherits those flags, thus causing any
build-time helper executables to be built for a non-default ABI, whose
build-time dependencies may not be installed in ${BROOT} since
${MULTILIB_USEDEP} makes no sense in BDEPEND.
Note, the behavior is inconsistent if the user has set BUILD_CC and
friends via their package.env, as then the ABI flags are *not* applied
to the build-machine toolchain via defaulting from the host-machine
toolchain.
This commit fixes up multilib.eclass so that it derives the build-
machine toolchain variables _before_ it appends the ABI flags to the
host-machine toolchain variables and so that it overrides CBUILD to the
default ABI in the non-cross-compiling case. The result is that build-
time helper executables are always built for the build machine's
_default_ ABI, even in the non-cross-compiling case.
[1] https://bugs.gentoo.org/960506#c9
Bug: https://bugs.gentoo.org/960506
Signed-off-by: Matt Whitlock <gentoo <AT> mattwhitlock.name>
Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org>
eclass/multilib.eclass | 41 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 36 insertions(+), 5 deletions(-)
diff --git a/eclass/multilib.eclass b/eclass/multilib.eclass
index c28fee7aa1ef..5d9e8498aefa 100644
--- a/eclass/multilib.eclass
+++ b/eclass/multilib.eclass
@@ -487,6 +487,17 @@ multilib_toolchain_setup() {
local save_restore_variables=(
CBUILD
CHOST
+ BUILD_AR
+ BUILD_CC
+ BUILD_CXX
+ BUILD_LD
+ BUILD_NM
+ BUILD_OBJCOPY
+ BUILD_PKG_CONFIG
+ BUILD_RANLIB
+ BUILD_READELF
+ BUILD_STRINGS
+ BUILD_STRIP
AR
CC
CXX
@@ -525,17 +536,31 @@ multilib_toolchain_setup() {
done
export _DEFAULT_ABI_SAVED="true"
- # Set CBUILD only if not cross-compiling.
- if [[ ${CBUILD} == "${CHOST}" ]]; then
- export CBUILD=$(get_abi_CHOST $1)
- fi
-
# Set the CHOST native first so that we pick up the native
# toolchain and not a cross-compiler by accident #202811.
#
# Make sure ${save_restore_variables[@]} list matches below.
export CHOST=$(get_abi_CHOST ${DEFAULT_ABI})
+ # Set CBUILD only if not cross-compiling.
+ if [[ "${_abi_saved_CBUILD:-${_abi_saved_CHOST}}" ==
"${_abi_saved_CHOST}" ]]; then
+ export CBUILD=${CHOST}
+ fi
+
+ # Derive the build-machine toolchain variables before we
+ # override the host-machine toolchain variables.
+ export BUILD_AR="$(tc-getBUILD_AR)" # Avoid 'ar', use
"${CBUILD}-ar"
+ export BUILD_CC="$(tc-getBUILD_CC)" # Default ABI
+ export BUILD_CXX="$(tc-getBUILD_CXX)" # Default ABI
+ export BUILD_LD="$(tc-getBUILD_LD)" # Default ABI
+ export BUILD_NM="$(tc-getBUILD_NM)" # Avoid 'nm', use
"${CBUILD}-nm"
+ export BUILD_OBJCOPY="$(tc-getBUILD_OBJCOPY)" # Avoid
'objcopy', use "${CBUILD}-objcopy"
+ export BUILD_PKG_CONFIG="$(tc-getBUILD_PKG_CONFIG)"
+ export BUILD_RANLIB="$(tc-getBUILD_RANLIB)" # Avoid 'ranlib',
use "${CBUILD}-ranlib"
+ export BUILD_READELF="$(tc-getBUILD_READELF)" # Avoid
'readelf', use "${CBUILD}-readelf"
+ export BUILD_STRINGS="$(tc-getBUILD_STRINGS)" # Avoid
'strings', use "${CBUILD}-strings"
+ export BUILD_STRIP="$(tc-getBUILD_STRIP)" # Avoid 'strip', use
"${CBUILD}-strip"
+
export AR="$(tc-getAR)" # Avoid 'ar', use '${CHOST}-ar'
export CC="$(tc-getCC) $(get_abi_CFLAGS)"
export CXX="$(tc-getCXX) $(get_abi_CFLAGS)"
@@ -556,6 +581,12 @@ multilib_toolchain_setup() {
export PKG_CONFIG_PATH=${ESYSROOT}/usr/share/pkgconfig
export PKG_CONFIG_SYSTEM_INCLUDE_PATH=${ESYSROOT}/usr/include
export
PKG_CONFIG_SYSTEM_LIBRARY_PATH=${ESYSROOT}/$(get_libdir):${ESYSROOT}/usr/$(get_libdir)
+
+ # Also set CBUILD so as not to trigger cross-compilation
+ # mode falsely in build systems.
+ if [[ "${_abi_saved_CBUILD:-${_abi_saved_CHOST}}" ==
"${_abi_saved_CHOST}" ]]; then
+ export CBUILD=${CHOST}
+ fi
fi
}