summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYifeng Li <tomli@tomli.me>2023-02-20 10:54:29 +0000
committerSam James <sam@gentoo.org>2023-02-20 13:48:17 +0000
commit806ed912c90eece112c9225c5308f0f837ef0b5a (patch)
treeced0bdb6fa014772a31c6403b5d37d02b414068c
parentsys-devel/flex: fix crash on Apple M1 due to undefined behavior. (diff)
downloadgentoo-806ed912c90eece112c9225c5308f0f837ef0b5a.tar.gz
gentoo-806ed912c90eece112c9225c5308f0f837ef0b5a.tar.bz2
gentoo-806ed912c90eece112c9225c5308f0f837ef0b5a.zip
dev-util/b2: fix crash on Apple M1 due to undefined behavior.
Currently, the build system dev-util/b2-4.9.3, notably used by Boost, crashes on Apple M1 w/ macOS with a Segmentation Fault. This prevents one from using the tool, and also making building Boost impossible. It's also notable since it contains the keyword "~x64-macos", so it should receive first-class macOS support. It has been determined that when the NULL-terminated variadic function call_rule() is invoked, the value 0 is passed as the last argument to act as a terminator. However, this is an integer value, which is incompatible with the pointer data type expected by call_rule(). This is undefined behavior in C, correct operation is not guaranteed. In fact, it causes b2 to crash on Apple M1 when GCC is used - the loop is not terminated when it should, instead, it keeps running, creating the following error: lol_add failed due to reached limit of 19 elements In some cases, it can even corrupt the internal state of the program, creating an infinite loop. This commit fixes the problem by explicitly casting the value 0 to the correct pointer type (OBJECT *). Since the existence of the bug doesn't prevent one from installing the package, it can lurk inside the system and remain undetected, furthermore, it's technically a C programming bug, other platforms could've been affected as well in theory. Thus, we also bump the package version. Closes: https://bugs.gentoo.org/895524 Signed-off-by: Yifeng Li <tomli@tomli.me> Closes: https://github.com/gentoo/gentoo/pull/29681 Signed-off-by: Sam James <sam@gentoo.org>
-rw-r--r--dev-util/b2/b2-4.9.3-r1.ebuild67
-rw-r--r--dev-util/b2/files/b2-4.9.3-fix-apple-m1-crash-by-explicit-pointer-cast.patch55
2 files changed, 122 insertions, 0 deletions
diff --git a/dev-util/b2/b2-4.9.3-r1.ebuild b/dev-util/b2/b2-4.9.3-r1.ebuild
new file mode 100644
index 000000000000..7ce4a20f5de2
--- /dev/null
+++ b/dev-util/b2/b2-4.9.3-r1.ebuild
@@ -0,0 +1,67 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+inherit edo flag-o-matic toolchain-funcs
+
+MY_PV="$(ver_rs 1- _)"
+
+DESCRIPTION="A system for large project software construction, simple to use and powerful"
+HOMEPAGE="https://www.bfgroup.xyz/b2/"
+SRC_URI="https://github.com/bfgroup/b2/archive/refs/tags/${PV}.tar.gz -> ${P}.tar.gz"
+S="${WORKDIR}/${P}/src"
+
+LICENSE="Boost-1.0"
+SLOT="0"
+KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~loong ~m68k ~mips ppc ppc64 ~riscv ~s390 sparc x86 ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
+IUSE="examples"
+RESTRICT="test"
+
+RDEPEND="!dev-util/boost-build"
+
+PATCHES=(
+ "${FILESDIR}"/${PN}-4.9.2-disable_python_rpath.patch
+ "${FILESDIR}"/${PN}-4.9.2-darwin-gentoo-toolchain.patch
+ "${FILESDIR}"/${PN}-4.9.2-add-none-feature-options.patch
+ "${FILESDIR}"/${PN}-4.9.2-no-implicit-march-flags.patch
+ "${FILESDIR}"/${PN}-4.9.2-odr.patch
+ "${FILESDIR}"/${PN}-4.9.3-fix-apple-m1-crash-by-explicit-pointer-cast.patch
+)
+
+src_configure() {
+ # need to enable LFS explicitly for 64-bit offsets on 32-bit hosts (#761100)
+ append-lfs-flags
+}
+
+src_compile() {
+ cd engine || die
+
+ # upstream doesn't want separate flags for CPPFLAGS/LDFLAGS
+ # https://github.com/bfgroup/b2/pull/187#issuecomment-1335688424
+ edo ${CONFIG_SHELL:-${BASH}} ./build.sh cxx --cxx="$(tc-getCXX)" --cxxflags="${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}" -d+2 --without-python
+}
+
+src_test() {
+ # Forget tests, b2 is a lost cause
+ :
+}
+
+src_install() {
+ dobin engine/b2
+
+ insinto /usr/share/b2/src
+ doins -r "${FILESDIR}/site-config.jam" \
+ bootstrap.jam build-system.jam ../example/user-config.jam \
+ build kernel options tools util
+
+ find "${ED}"/usr/share/b2/src -iname '*.py' -delete || die
+
+ dodoc ../notes/{changes,release_procedure,build_dir_option,relative_source_paths}.txt
+
+ if use examples; then
+ docinto examples
+ dodoc -r ../example/.
+ docompress -x /usr/share/doc/${PF}/examples
+ fi
+}
diff --git a/dev-util/b2/files/b2-4.9.3-fix-apple-m1-crash-by-explicit-pointer-cast.patch b/dev-util/b2/files/b2-4.9.3-fix-apple-m1-crash-by-explicit-pointer-cast.patch
new file mode 100644
index 000000000000..753c60fd14ce
--- /dev/null
+++ b/dev-util/b2/files/b2-4.9.3-fix-apple-m1-crash-by-explicit-pointer-cast.patch
@@ -0,0 +1,55 @@
+https://github.com/bfgroup/b2/issues/152
+https://github.com/bfgroup/b2/pull/214
+https://bugs.gentoo.org/895524
+
+From 62dc6ff74a0b9717b4a8dd61ce06770e6fb7c177 Mon Sep 17 00:00:00 2001
+From: Yifeng Li <tomli@tomli.me>
+Date: Mon, 20 Feb 2023 09:52:32 +0000
+Subject: [PATCH] Fix #152 crash on Apple M1 by casting 0 to (OBJECT *)
+ explicitly.
+
+Currently, when the NULL-terminated variadic function call_rule()
+is invoked, the value "0" is passed as the last argument to act
+as a terminator. However, this is an integer value, which is
+incompatible with the pointer data type expected by call_rule().
+
+This is undefined behavior in C, correct operation is not
+guaranteed. In fact, it causes b2 to crash on Apple M1 when GCC
+is used - the loop is not terminated when it should, instead, it
+keeps running, creating the following error:
+
+> lol_add failed due to reached limit of 19 elements
+
+In some cases, it can even corrupt the internal state of the program,
+creating an infinite loop.
+
+This commit fixes the problem by explicitly casting the value 0 to
+the correct pointer type (OBJECT *).
+
+Signed-off-by: Yifeng Li <tomli@tomli.me>
+---
+ src/engine/modules/property-set.cpp | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/engine/modules/property-set.cpp b/src/engine/modules/property-set.cpp
+index 6e190a7639..b0d3c2dab8 100644
+--- src/engine/modules/property-set.cpp
++++ src/engine/modules/property-set.cpp
+@@ -162,7 +162,7 @@ LIST * property_set_create( FRAME * frame, int flags )
+ OBJECT * rulename = object_new( "new" );
+ OBJECT * varname = object_new( "self.raw" );
+ LIST * val = call_rule( rulename, frame,
+- list_new( object_new( "property-set" ) ), 0 );
++ list_new( object_new( "property-set" ) ), (OBJECT *) 0 );
+ LISTITER iter, end;
+ object_free( rulename );
+ pos->value = object_copy( list_front( val ) );
+@@ -183,7 +183,7 @@ LIST * property_set_create( FRAME * frame, int flags )
+ import_module( imports, frame->module );
+ rulename = object_new( "errors.error" );
+ call_rule( rulename, frame,
+- list_new( object_new( message->value ) ), 0 );
++ list_new( object_new( message->value ) ), (OBJECT *) 0 );
+ /* unreachable */
+ string_free( message );
+ list_free( imports );