Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[gentoo-dev] Allow prefixed systems to be cross-compiled

3 views
Skip to first unread message

James Le Cuirot

unread,
Jan 21, 2023, 5:30:04 PM1/21/23
to
These changes relate to the news item I recently posted here. They've already
had some feedback on GitHub, but they include eclass changes, and protocol says
I must post them here too. I've included the wider package changes, as the
eclass changes alone don't make sense out of context.

In particular, I have not yet had any feedback on the python-utils-r1.eclass
change. It's only a single line.

James Le Cuirot

unread,
Jan 21, 2023, 5:30:04 PM1/21/23
to
The toolchain expects to find the libc's files under its own sysroot. This
sysroot is automatically prepended to paths found in ld scripts, such as those
installed with glibc. We configure standalone prefix systems with a sysroot, so
these paths should not be prefixed. However, Gentoo Prefix has traditionally
left them prefixed and stopped the compiler from passing the sysroot to the
linker instead. It is better to strip the prefix and let the sysroot do its job,
as this makes cross-compiling much less awkward.

prefix-guest systems do not have a sysroot applied, as they use the host's libc,
but they would not install glibc anyway.

This change is not needed for musl, as it does not install any ld scripts.

Signed-off-by: James Le Cuirot <ch...@gentoo.org>
---
profiles/features/prefix/standalone/profile.bashrc | 9 +--------
sys-libs/glibc/glibc-2.36-r6.ebuild | 11 +++++++++++
sys-libs/glibc/glibc-9999.ebuild | 11 +++++++++++
3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/profiles/features/prefix/standalone/profile.bashrc b/profiles/features/prefix/standalone/profile.bashrc
index fd95e43f7f30..3cdda77b9a88 100644
--- a/profiles/features/prefix/standalone/profile.bashrc
+++ b/profiles/features/prefix/standalone/profile.bashrc
@@ -1,5 +1,5 @@
# -*- mode: shell-script; -*-
-# Copyright 2018-2021 Gentoo Authors
+# Copyright 2018-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# RAP specific patches pending upstream:
@@ -24,10 +24,6 @@ if [[ ${CATEGORY}/${PN} == sys-devel/gcc && ${EBUILD_PHASE} == configure ]]; the

# use sysroot of toolchain to get correct include and library at compile time
EXTRA_ECONF="${EXTRA_ECONF} --with-sysroot=${EPREFIX}"
-
- ebegin "remove --sysroot call on ld for native toolchain"
- sed -i 's/--sysroot=%R//' gcc/gcc.c*
- eend $?
elif [[ ${CATEGORY}/${PN} == sys-devel/clang && ${EBUILD_PHASE} == configure ]]; then
ebegin "Use ${EPREFIX} as default sysroot"
sed -i -e "s@DEFAULT_SYSROOT \"\"@DEFAULT_SYSROOT \"${EPREFIX}\"@" "${S}"/CMakeLists.txt
@@ -36,9 +32,6 @@ elif [[ ${CATEGORY}/${PN} == sys-devel/clang && ${EBUILD_PHASE} == configure ]];
ebegin "Use dynamic linker from ${EPREFIX}"
sed -i -e "/LibDir.*Loader/s@return \"\/\"@return \"${EPREFIX%/}/\"@" Linux.cpp
eend $?
- ebegin "Remove --sysroot call on ld for native toolchain"
- sed -i -e "$(grep -n -B1 sysroot= Gnu.cpp | sed -ne '{1s/-.*//;1p}'),+1 d" Gnu.cpp
- eend $?
popd >/dev/null
elif [[ ${CATEGORY}/${PN} == sys-devel/binutils && ${EBUILD_PHASE} == prepare ]]; then
ebegin "Prefixifying native library path"
diff --git a/sys-libs/glibc/glibc-2.36-r6.ebuild b/sys-libs/glibc/glibc-2.36-r6.ebuild
index be82be429c8f..e86bbd923123 100644
--- a/sys-libs/glibc/glibc-2.36-r6.ebuild
+++ b/sys-libs/glibc/glibc-2.36-r6.ebuild
@@ -1314,6 +1314,17 @@ glibc_do_src_install() {
mv "${ED}"/$(alt_usrlibdir)/libm-${upstream_pv}.a "${ED}"/$(alt_usrlibdir)/${P}/libm-${upstream_pv}.a || die
fi

+ # We configure toolchains for standalone prefix systems with a sysroot,
+ # which is prepended to paths in ld scripts, so strip the prefix from these.
+ # Before: GROUP ( /foo/lib64/libc.so.6 /foo/usr/lib64/libc_nonshared.a AS_NEEDED ( /foo/lib64/ld-linux-x86-64.so.2 ) )
+ # After: GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
+ if [[ -n $(host_eprefix) ]] ; then
+ local file
+ grep -lZIF "ld script" "${ED}/$(alt_usrlibdir)"/lib*.{a,so} 2>/dev/null | while read -rd '' file ; do
+ sed -i "s|$(host_eprefix)/|/|g" "${file}" || die
+ done
+ fi
+
# We'll take care of the cache ourselves
rm -f "${ED}"/etc/ld.so.cache

diff --git a/sys-libs/glibc/glibc-9999.ebuild b/sys-libs/glibc/glibc-9999.ebuild
index 33d217dc1787..bf134512eb59 100644
--- a/sys-libs/glibc/glibc-9999.ebuild
+++ b/sys-libs/glibc/glibc-9999.ebuild
@@ -1314,6 +1314,17 @@ glibc_do_src_install() {
mv "${ED}"/$(alt_usrlibdir)/libm-${upstream_pv}.a "${ED}"/$(alt_usrlibdir)/${P}/libm-${upstream_pv}.a || die
fi

+ # We configure toolchains for standalone prefix systems with a sysroot,
+ # which is prepended to paths in ld scripts, so strip the prefix from these.
+ # Before: GROUP ( /foo/lib64/libc.so.6 /foo/usr/lib64/libc_nonshared.a AS_NEEDED ( /foo/lib64/ld-linux-x86-64.so.2 ) )
+ # After: GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
+ if [[ -n $(host_eprefix) ]] ; then
+ local file
+ grep -lZIF "ld script" "${ED}/$(alt_usrlibdir)"/lib*.{a,so} 2>/dev/null | while read -rd '' file ; do
+ sed -i "s|$(host_eprefix)/|/|g" "${file}" || die
+ done
+ fi
+
# We'll take care of the cache ourselves
rm -f "${ED}"/etc/ld.so.cache

--
2.39.1

James Le Cuirot

unread,
Jan 21, 2023, 5:30:04 PM1/21/23
to
Signed-off-by: James Le Cuirot <ch...@gentoo.org>
---
eclass/toolchain.eclass | 13 +++++++++++++
profiles/features/prefix/standalone/profile.bashrc | 14 +-------------
2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/eclass/toolchain.eclass b/eclass/toolchain.eclass
index 479814f0df3e..6d8901d21812 100644
--- a/eclass/toolchain.eclass
+++ b/eclass/toolchain.eclass
@@ -719,6 +719,19 @@ toolchain_src_prepare() {
einfo "Remove texinfo (bug #198182, bug #464008)"
eapply "${FILESDIR}"/gcc-configure-texinfo.patch

+ if ! use prefix-guest && [[ -n ${EPREFIX} ]] ; then
+ einfo "Prefixifying dynamic linkers..."
+ for f in gcc/config/*/*linux*.h ; do
+ ebegin " Updating ${f}"
+ if [[ ${f} == gcc/config/rs6000/linux*.h ]]; then
+ sed -i -r "s,(DYNAMIC_LINKER_PREFIX\s+)\"\",\1\"${EPREFIX}\",g" "${f}" || die
+ else
+ sed -i -r "/_DYNAMIC_LINKER/s,([\":])(/lib),\1${EPREFIX}\2,g" "${f}" || die
+ fi
+ eend $?
+ done
+ fi
+
# >=gcc-4
if [[ -x contrib/gcc_update ]] ; then
einfo "Touching generated files"
diff --git a/profiles/features/prefix/standalone/profile.bashrc b/profiles/features/prefix/standalone/profile.bashrc
index 043f766c37e9..57ec4b57abcb 100644
--- a/profiles/features/prefix/standalone/profile.bashrc
+++ b/profiles/features/prefix/standalone/profile.bashrc
@@ -9,19 +9,7 @@
# Disable RAP trick during bootstrap stage2
[[ -z ${BOOTSTRAP_RAP_STAGE2} ]] || return 0

-if [[ ${CATEGORY}/${PN} == sys-devel/gcc && ${EBUILD_PHASE} == configure ]]; then
- cd "${S}"
- einfo "Prefixifying dynamic linkers..."
- for h in gcc/config/*/*linux*.h; do
- ebegin " Updating $h"
- if [[ "${h}" == gcc/config/rs6000/linux*.h ]]; then
- sed -i -r "s,(DYNAMIC_LINKER_PREFIX\s+)\"\",\1\"${EPREFIX}\",g" $h
- else
- sed -i -r "/_DYNAMIC_LINKER/s,([\":])(/lib),\1${EPREFIX}\2,g" $h
- fi
- eend $?
- done
-elif [[ ${CATEGORY}/${PN} == sys-devel/clang && ${EBUILD_PHASE} == configure ]]; then
+if [[ ${CATEGORY}/${PN} == sys-devel/clang && ${EBUILD_PHASE} == configure ]]; then
ebegin "Use ${EPREFIX} as default sysroot"
sed -i -e "s@DEFAULT_SYSROOT \"\"@DEFAULT_SYSROOT \"${EPREFIX}\"@" "${S}"/CMakeLists.txt
eend $?
--
2.39.1
0 new messages