binutils: Specify sysroot for libtool during build

libbfd is enabled and it invokes libtool relink step to get rid of
rpaths during install step. libtool 2.4 patches rightly prepend
lt_sysroot to target libdir which relink step would use, such a patch
is also upstreamed into libtool [1]

However, when we do not specify --with-libtool-sysroot, lt_sysoot prefix
turns out to be empty and relink step adds -L/usr/lib to linker command
line. it cause all sort of problems e.g. when the build host has zlib
installed then libbfd tries to link with /usr/lib/libz.so instead of the
one in target sysroot, fortunately OE linker reports host path contamination
and fails the build. Second problem seen when building target binutils on
musl, it links with libc.so correctly but libtool relink step resolves
libc.so in /usr/lib due to this path and expands it into libc.so.6 and
ld-linux-x86-64.so.2 ( glibc host's libc.so is a linker stub ) in
DT_NEEDED ELF section which does not work with
musl linker and build QA detects this anamoly as well.

ERROR: binutils-2.44-r0 do_package_qa: QA Issue: /usr/lib/libbfd-2.44.so contained in package libbfd requires libc.so.6(GLIBC_2.34)(64bit), but no providers found in RDEPENDS:libbfd? [file-rdeps]

This inconsistency may cause produced binaries mistakenly linked against
libraries from the host distro.

Add libtool sysroot to point libtool to correct sysroot location during
build.

[1] https://git.savannah.gnu.org/cgit/libtool.git/commit/?id=3221f9f0fb98d5740ab5d0e8db6a731302520644

(From OE-Core rev: 89e984bd7edb9a2013b65d0215fd6af9aadd59e8)

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Khem Raj 2025-04-29 02:27:01 -07:00 committed by Richard Purdie
parent 90a5add3b6
commit 15e88b968e

View File

@ -5,6 +5,7 @@ require binutils-${PV}.inc
DEPENDS += "zlib perl-native"
EXTRA_OECONF += "--with-sysroot=/ \
--with-libtool-sysroot=${STAGING_DIR_HOST} \
--enable-install-libbfd \
--enable-install-libiberty \
--enable-shared \