Gentoo Archives: gentoo-dev

From: James Le Cuirot <chewi@g.o>
To: gentoo-dev <gentoo-dev@l.g.o>
Cc: James Le Cuirot <chewi@g.o>
Subject: [gentoo-dev] [PATCH 1/7] sys-libs/glibc: Strip prefix from ld scripts for better cross-compiling
Date: Sat, 21 Jan 2023 22:21:37
Message-Id: 20230121222037.29094-2-chewi@gentoo.org
In Reply to: [gentoo-dev] Allow prefixed systems to be cross-compiled by James Le Cuirot
1 The toolchain expects to find the libc's files under its own sysroot. This
2 sysroot is automatically prepended to paths found in ld scripts, such as those
3 installed with glibc. We configure standalone prefix systems with a sysroot, so
4 these paths should not be prefixed. However, Gentoo Prefix has traditionally
5 left them prefixed and stopped the compiler from passing the sysroot to the
6 linker instead. It is better to strip the prefix and let the sysroot do its job,
7 as this makes cross-compiling much less awkward.
8
9 prefix-guest systems do not have a sysroot applied, as they use the host's libc,
10 but they would not install glibc anyway.
11
12 This change is not needed for musl, as it does not install any ld scripts.
13
14 Signed-off-by: James Le Cuirot <chewi@g.o>
15 ---
16 profiles/features/prefix/standalone/profile.bashrc | 9 +--------
17 sys-libs/glibc/glibc-2.36-r6.ebuild | 11 +++++++++++
18 sys-libs/glibc/glibc-9999.ebuild | 11 +++++++++++
19 3 files changed, 23 insertions(+), 8 deletions(-)
20
21 diff --git a/profiles/features/prefix/standalone/profile.bashrc b/profiles/features/prefix/standalone/profile.bashrc
22 index fd95e43f7f30..3cdda77b9a88 100644
23 --- a/profiles/features/prefix/standalone/profile.bashrc
24 +++ b/profiles/features/prefix/standalone/profile.bashrc
25 @@ -1,5 +1,5 @@
26 # -*- mode: shell-script; -*-
27 -# Copyright 2018-2021 Gentoo Authors
28 +# Copyright 2018-2022 Gentoo Authors
29 # Distributed under the terms of the GNU General Public License v2
30
31 # RAP specific patches pending upstream:
32 @@ -24,10 +24,6 @@ if [[ ${CATEGORY}/${PN} == sys-devel/gcc && ${EBUILD_PHASE} == configure ]]; the
33
34 # use sysroot of toolchain to get correct include and library at compile time
35 EXTRA_ECONF="${EXTRA_ECONF} --with-sysroot=${EPREFIX}"
36 -
37 - ebegin "remove --sysroot call on ld for native toolchain"
38 - sed -i 's/--sysroot=%R//' gcc/gcc.c*
39 - eend $?
40 elif [[ ${CATEGORY}/${PN} == sys-devel/clang && ${EBUILD_PHASE} == configure ]]; then
41 ebegin "Use ${EPREFIX} as default sysroot"
42 sed -i -e "s@DEFAULT_SYSROOT \"\"@DEFAULT_SYSROOT \"${EPREFIX}\"@" "${S}"/CMakeLists.txt
43 @@ -36,9 +32,6 @@ elif [[ ${CATEGORY}/${PN} == sys-devel/clang && ${EBUILD_PHASE} == configure ]];
44 ebegin "Use dynamic linker from ${EPREFIX}"
45 sed -i -e "/LibDir.*Loader/s@return \"\/\"@return \"${EPREFIX%/}/\"@" Linux.cpp
46 eend $?
47 - ebegin "Remove --sysroot call on ld for native toolchain"
48 - sed -i -e "$(grep -n -B1 sysroot= Gnu.cpp | sed -ne '{1s/-.*//;1p}'),+1 d" Gnu.cpp
49 - eend $?
50 popd >/dev/null
51 elif [[ ${CATEGORY}/${PN} == sys-devel/binutils && ${EBUILD_PHASE} == prepare ]]; then
52 ebegin "Prefixifying native library path"
53 diff --git a/sys-libs/glibc/glibc-2.36-r6.ebuild b/sys-libs/glibc/glibc-2.36-r6.ebuild
54 index be82be429c8f..e86bbd923123 100644
55 --- a/sys-libs/glibc/glibc-2.36-r6.ebuild
56 +++ b/sys-libs/glibc/glibc-2.36-r6.ebuild
57 @@ -1314,6 +1314,17 @@ glibc_do_src_install() {
58 mv "${ED}"/$(alt_usrlibdir)/libm-${upstream_pv}.a "${ED}"/$(alt_usrlibdir)/${P}/libm-${upstream_pv}.a || die
59 fi
60
61 + # We configure toolchains for standalone prefix systems with a sysroot,
62 + # which is prepended to paths in ld scripts, so strip the prefix from these.
63 + # Before: GROUP ( /foo/lib64/libc.so.6 /foo/usr/lib64/libc_nonshared.a AS_NEEDED ( /foo/lib64/ld-linux-x86-64.so.2 ) )
64 + # After: GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
65 + if [[ -n $(host_eprefix) ]] ; then
66 + local file
67 + grep -lZIF "ld script" "${ED}/$(alt_usrlibdir)"/lib*.{a,so} 2>/dev/null | while read -rd '' file ; do
68 + sed -i "s|$(host_eprefix)/|/|g" "${file}" || die
69 + done
70 + fi
71 +
72 # We'll take care of the cache ourselves
73 rm -f "${ED}"/etc/ld.so.cache
74
75 diff --git a/sys-libs/glibc/glibc-9999.ebuild b/sys-libs/glibc/glibc-9999.ebuild
76 index 33d217dc1787..bf134512eb59 100644
77 --- a/sys-libs/glibc/glibc-9999.ebuild
78 +++ b/sys-libs/glibc/glibc-9999.ebuild
79 @@ -1314,6 +1314,17 @@ glibc_do_src_install() {
80 mv "${ED}"/$(alt_usrlibdir)/libm-${upstream_pv}.a "${ED}"/$(alt_usrlibdir)/${P}/libm-${upstream_pv}.a || die
81 fi
82
83 + # We configure toolchains for standalone prefix systems with a sysroot,
84 + # which is prepended to paths in ld scripts, so strip the prefix from these.
85 + # Before: GROUP ( /foo/lib64/libc.so.6 /foo/usr/lib64/libc_nonshared.a AS_NEEDED ( /foo/lib64/ld-linux-x86-64.so.2 ) )
86 + # After: GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
87 + if [[ -n $(host_eprefix) ]] ; then
88 + local file
89 + grep -lZIF "ld script" "${ED}/$(alt_usrlibdir)"/lib*.{a,so} 2>/dev/null | while read -rd '' file ; do
90 + sed -i "s|$(host_eprefix)/|/|g" "${file}" || die
91 + done
92 + fi
93 +
94 # We'll take care of the cache ourselves
95 rm -f "${ED}"/etc/ld.so.cache
96
97 --
98 2.39.1