summaryrefslogtreecommitdiff
path: root/sys-devel/binutils
diff options
context:
space:
mode:
authorSam James <sam@gentoo.org>2025-05-25 06:04:36 +0100
committerSam James <sam@gentoo.org>2025-06-16 02:27:46 +0100
commite88da3a4be0f6398768ba09f42da1d0059e29856 (patch)
tree630bc69f0cbe5b831d6853d7d29c6562b6d1cbf7 /sys-devel/binutils
parentde0ee43ae3b1f4941058c76501b4e55e77cd1112 (diff)
downloadgentoo-e88da3a4be0f6398768ba09f42da1d0059e29856.tar.gz
gentoo-e88da3a4be0f6398768ba09f42da1d0059e29856.tar.bz2
gentoo-e88da3a4be0f6398768ba09f42da1d0059e29856.zip
sys-devel/binutils: add last-minute sanity check (WIP)
Takes inspiration from sys-libs/glibc's sanity check as well as the one I recently added for sys-libs/musl (c1078bc34bba21a2ff31289744e17f5addc07c89). The idea is to just check that the new binutils (gas, ld) produce working binaries for a trivial example. PR32991 is a nice example of where this could help find a problem. This doesn't help with all cases, but it is somewhat related to the linked Gentoo bugs. It's more important for the case where the user is on an odd target or has specified some unusual flags and binutils is completely broken to avoid merging and bricking the machine (as a fixed binutils won't be buildable). Better safe than sorry. Future work: * Check all ABIs (like -m32) * Do the same for gcc? Bug: https://bugs.gentoo.org/622690 Bug: https://bugs.gentoo.org/802036 Bug: https://sourceware.org/PR32991 Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'sys-devel/binutils')
-rw-r--r--sys-devel/binutils/binutils-9999.ebuild51
1 files changed, 51 insertions, 0 deletions
diff --git a/sys-devel/binutils/binutils-9999.ebuild b/sys-devel/binutils/binutils-9999.ebuild
index 56005f5b75eb..97ab5db61c07 100644
--- a/sys-devel/binutils/binutils-9999.ebuild
+++ b/sys-devel/binutils/binutils-9999.ebuild
@@ -526,6 +526,57 @@ src_install() {
find "${ED}" -depth -type d -exec rmdir {} + 2>/dev/null
}
+# Simple test to make sure our new binutils isn't completely broken.
+# Skip if this binutils is a cross compiler.
+#
+# If coreutils is built with USE=multicall, some of these files
+# will just be wrapper scripts, not actual ELFs we can test.
+binutils_sanity_check() {
+ pushd "${T}" >/dev/null
+
+ einfo "Last-minute run tests with binutils in ${ED}${BINPATH} ..."
+
+ cat <<-EOF > "${T}"/number.c
+ int get_magic_number() {
+ return 42;
+ }
+ EOF
+
+ cat <<-EOF > "${T}"/test.c
+ #include <stdio.h>
+ int get_magic_number();
+
+ int main() {
+ printf("Hello Gentoo! Your magic number is: %d\n", get_magic_number());
+ }
+ EOF
+
+ local -x LD_LIBRARY_PATH="${ED}${LIBPATH}${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
+
+ local opt opt2
+ # TODO: test multilib variants?
+ for opt in '' '-O2' ; do
+ for opt2 in '-static' '-static-pie' '-fno-PIE -no-pie' ; do
+ $(tc-getCC) ${opt} ${opt2} -B"${ED}${BINPATH}" "${T}"/number.c "${T}"/test.c -o "${T}"/test
+ if "${T}"/test | grep -q "Hello Gentoo! Your magic number is: 42" ; then
+ :;
+ else
+ die "Test with '${opt} ${opt2}' failed! Aborting to avoid broken binutils!"
+ fi
+ done
+ done
+
+ popd >/dev/null
+}
+
+pkg_preinst() {
+ [[ -n ${ROOT} ]] && return 0
+ [[ -d ${ED}${BINPATH} ]] || return 0
+ [[ -n ${BOOTSTRAP_RAP} ]] || return 0
+ is_cross && return 0
+ binutils_sanity_check
+}
+
pkg_postinst() {
# Make sure this ${CTARGET} has a binutils version selected
[[ -e ${EROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0