commit: 5d9341ed5b240e838abea81a582717aa92381dc6 Author: James Le Cuirot <chewi <AT> gentoo <DOT> org> AuthorDate: Sat Dec 23 14:50:47 2023 +0000 Commit: James Le Cuirot <chewi <AT> gentoo <DOT> org> CommitDate: Sat Jan 6 11:47:39 2024 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5d9341ed
sys-devel/binutils: Add conditional patch to fix ld.bfd prefix handling As before, this may make it into our patchset once it's been proven to work. Our track record here hasn't been great so far! Closes: https://bugs.gentoo.org/892549 Closes: https://github.com/gentoo/gentoo/pull/34446 Bug: https://github.com/gentoo/binutils-gdb/pull/5 Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org> ...inutils-9999.ebuild => binutils-2.41-r4.ebuild} | 22 ++++++--- sys-devel/binutils/binutils-9999.ebuild | 9 +++- .../files/binutils-2.41-linker-prefix.patch | 56 ++++++++++++++++++++++ 3 files changed, 79 insertions(+), 8 deletions(-) diff --git a/sys-devel/binutils/binutils-9999.ebuild b/sys-devel/binutils/binutils-2.41-r4.ebuild similarity index 95% copy from sys-devel/binutils/binutils-9999.ebuild copy to sys-devel/binutils/binutils-2.41-r4.ebuild index 71f57af9f840..0fe91dacf35e 100644 --- a/sys-devel/binutils/binutils-9999.ebuild +++ b/sys-devel/binutils/binutils-2.41-r4.ebuild @@ -1,4 +1,4 @@ -# Copyright 1999-2024 Gentoo Authors +# Copyright 1999-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=7 @@ -19,7 +19,7 @@ IUSE="cet debuginfod doc gold gprofng hardened multitarget +nls pgo +plugins sta # PATCH_DEV - Use download URI https://dev.gentoo.org/~{PATCH_DEV}/distfiles/... # for the patchsets -PATCH_VER=1 +PATCH_VER=4 PATCH_DEV=dilfridge if [[ ${PV} == 9999* ]]; then @@ -32,7 +32,7 @@ else [[ -z ${PATCH_VER} ]] || SRC_URI="${SRC_URI} https://dev.gentoo.org/~${PATCH_DEV}/distfiles/binutils-${PATCH_BINUTILS_VER}-patches-${PATCH_VER}.tar.xz" SLOT=$(ver_cut 1-2) - #KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86" + KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86" fi # @@ -119,7 +119,8 @@ src_prepare() { # This is applied conditionally for now just out of caution. # It should be okay on non-prefix systems though. See bug #892549. if is_cross || use prefix; then - eapply "${FILESDIR}"/binutils-2.40-linker-search-path.patch + eapply "${FILESDIR}"/binutils-2.40-linker-search-path.patch \ + "${FILESDIR}"/binutils-2.41-linker-prefix.patch fi fi fi @@ -183,7 +184,12 @@ src_configure() { use cet && filter-flags -mindirect-branch -mindirect-branch=* use elibc_musl && append-ldflags -Wl,-z,stack-size=2097152 - append-ldflags $(test-flags-CCLD -Wl,--undefined-version) + # ideally we want !tc-ld-is-bfd for best future-proofing, but it needs + # https://github.com/gentoo/gentoo/pull/28355 + # mold needs this too but right now tc-ld-is-mold is also not available + if tc-ld-is-lld; then + append-ldflags -Wl,--undefined-version + fi local x echo @@ -351,7 +357,11 @@ src_compile() { cd "${MY_BUILDDIR}" || die # see Note [tooldir hack for ldscripts] - emake tooldir="${EPREFIX}${TOOLPATH}" all + # see linker prefix patch + emake \ + tooldir="${EPREFIX}${TOOLPATH}" \ + gentoo_prefix=$(usex prefix-guest "${EPREFIX}"/usr /usr) \ + all # only build info pages if the user wants them if use doc ; then diff --git a/sys-devel/binutils/binutils-9999.ebuild b/sys-devel/binutils/binutils-9999.ebuild index 71f57af9f840..f08bf54fb8ff 100644 --- a/sys-devel/binutils/binutils-9999.ebuild +++ b/sys-devel/binutils/binutils-9999.ebuild @@ -119,7 +119,8 @@ src_prepare() { # This is applied conditionally for now just out of caution. # It should be okay on non-prefix systems though. See bug #892549. if is_cross || use prefix; then - eapply "${FILESDIR}"/binutils-2.40-linker-search-path.patch + eapply "${FILESDIR}"/binutils-2.40-linker-search-path.patch \ + "${FILESDIR}"/binutils-2.41-linker-prefix.patch fi fi fi @@ -351,7 +352,11 @@ src_compile() { cd "${MY_BUILDDIR}" || die # see Note [tooldir hack for ldscripts] - emake tooldir="${EPREFIX}${TOOLPATH}" all + # see linker prefix patch + emake \ + tooldir="${EPREFIX}${TOOLPATH}" \ + gentoo_prefix=$(usex prefix-guest "${EPREFIX}"/usr /usr) \ + all # only build info pages if the user wants them if use doc ; then diff --git a/sys-devel/binutils/files/binutils-2.41-linker-prefix.patch b/sys-devel/binutils/files/binutils-2.41-linker-prefix.patch new file mode 100644 index 000000000000..d97a15599209 --- /dev/null +++ b/sys-devel/binutils/files/binutils-2.41-linker-prefix.patch @@ -0,0 +1,56 @@ +https://bugs.gentoo.org/892549 +https://github.com/gentoo/binutils-gdb/pull/5 + +From 531bc1536dfc3070c1f7d03e98fa14bcb81fdcd0 Mon Sep 17 00:00:00 2001 +From: James Le Cuirot <[email protected]> +Date: Sat, 23 Dec 2023 13:48:10 +0000 +Subject: [PATCH 2/2] ld: Allow a Gentoo-specific prefix to override the prefix + used by ld.bfd + +This prefix is only used to locate $prefix/etc/ld.so.conf, with $prefix +usually being /usr. This file is important on Gentoo Prefix systems, +where the /usr prefix is within another directory. The problem is that +Gentoo already passes the same directory as the sysroot, and ld.bfd +therefore looks for /myprefix/myprefix/usr/etc/ld.so.conf. + +The sysroot is dynamic, while the prefix is hardcoded. A hardcoded +prefix that isn't just /usr is unhelpful, not just because of the +doubled prefix issue above, but also because it prevents ld.bfd from +working effectively outside its native environment. We will therefore +hardcode it to just /usr. + +This change does not simply do that though and sets up a $gentoo_prefix +variable instead, with $prefix as a fallback. This is necessary because +Gentoo prefix-guest systems, which use the host's libc, do not apply a +sysroot like RAP prefix systems do. In that case, we must preserve the +existing behaviour. The binutils ebuild will be responsible for setting +this variable appropriately. +--- + ld/emultempl/elf.em | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em +index 3f67f8b09d9..78c8e909b6c 100644 +--- a/ld/emultempl/elf.em ++++ b/ld/emultempl/elf.em +@@ -138,7 +138,7 @@ gld${EMULATION_NAME}_before_plugin_all_symbols_read (void) + ldelf_before_plugin_all_symbols_read ($IS_LIBPATH, $IS_NATIVE, + $IS_LINUX_TARGET, + $IS_FREEBSD_TARGET, +- $ELFSIZE, "$prefix"); ++ $ELFSIZE, "${gentoo_prefix-${prefix}}"); + } + + /* This is called after all the input files have been opened. */ +@@ -147,7 +147,7 @@ static void + gld${EMULATION_NAME}_after_open (void) + { + ldelf_after_open ($IS_LIBPATH, $IS_NATIVE, +- $IS_LINUX_TARGET, $IS_FREEBSD_TARGET, $ELFSIZE, "$prefix"); ++ $IS_LINUX_TARGET, $IS_FREEBSD_TARGET, $ELFSIZE, "${gentoo_prefix-${prefix}}"); + } + + EOF +-- +2.43.0 +
