From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B52E115800F for ; Mon, 20 Feb 2023 13:48:33 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8ACE7E0ADB; Mon, 20 Feb 2023 13:48:32 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id C5A39E0ADB for ; Mon, 20 Feb 2023 13:48:31 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id CA889340D1D for ; Mon, 20 Feb 2023 13:48:30 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 68409888 for ; Mon, 20 Feb 2023 13:48:28 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1676900896.3ab5b78c47ee2dcfdb2de0ae84f43c96d2e9c210.sam@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: sys-devel/flex/, sys-devel/flex/files/ X-VCS-Repository: repo/gentoo X-VCS-Files: sys-devel/flex/files/flex-2.6.4-fix-apple-m1-crash-by-explicit-pointer-cast.patch sys-devel/flex/flex-2.6.4-r6.ebuild X-VCS-Directories: sys-devel/flex/files/ sys-devel/flex/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 3ab5b78c47ee2dcfdb2de0ae84f43c96d2e9c210 X-VCS-Branch: master Date: Mon, 20 Feb 2023 13:48:28 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: f4561354-1f34-48c4-9d0e-20e6a40f611d X-Archives-Hash: a1add138394129c12efe7c9babcd00be commit: 3ab5b78c47ee2dcfdb2de0ae84f43c96d2e9c210 Author: Yifeng Li tomli me> AuthorDate: Mon Feb 20 10:35:16 2023 +0000 Commit: Sam James gentoo org> CommitDate: Mon Feb 20 13:48:16 2023 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=3ab5b78c sys-devel/flex: fix crash on Apple M1 due to undefined behavior. Currently, when the NULL-terminated variadic function filter_create_ext() 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 filter_create_ext(). This is undefined behavior in C, correct operation is not guaranteed. In fact, it causes flex to crash on Apple M1 when GCC is used - the loop is not terminated when it should, instead, it keeps running, corrupting the argument list for invoking m4. As a result, it creates the following error: > flex: fatal internal error, exec of gm4 failed This commit fixes the problem by explicitly casting the value 0 to the correct pointer type (char *). Since the existence of the bug doesn't always prevent a Gentoo Prefix bootstrapping, 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/871324 Signed-off-by: Yifeng Li tomli.me> Signed-off-by: Sam James gentoo.org> ...x-apple-m1-crash-by-explicit-pointer-cast.patch | 48 ++++++++++ sys-devel/flex/flex-2.6.4-r6.ebuild | 101 +++++++++++++++++++++ 2 files changed, 149 insertions(+) diff --git a/sys-devel/flex/files/flex-2.6.4-fix-apple-m1-crash-by-explicit-pointer-cast.patch b/sys-devel/flex/files/flex-2.6.4-fix-apple-m1-crash-by-explicit-pointer-cast.patch new file mode 100644 index 000000000000..c594262d2cb0 --- /dev/null +++ b/sys-devel/flex/files/flex-2.6.4-fix-apple-m1-crash-by-explicit-pointer-cast.patch @@ -0,0 +1,48 @@ +https://github.com/westes/flex/issues/539 +https://github.com/westes/flex/pull/554 +https://bugs.gentoo.org/871324 + +This is a backported version for applying to v2.6.4 +instead of git. + +From cce2df853386d5b5b60445b1204dcca08e9f259e Mon Sep 17 00:00:00 2001 +From: Yifeng Li +Date: Mon, 20 Feb 2023 11:23:52 +0000 +Subject: [PATCH] Fix #539 crash on Apple M1 by casting 0 to (char *) + explicitly + +Currently, when the NULL-terminated variadic function +filter_create_ext() 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 filter_create_ext(). + +This is undefined behavior in C, correct operation is not +guaranteed. In fact, it causes flex to crash on Apple M1 +when GCC is used - the loop is not terminated when it should, +instead, it keeps running, corrupting the argument list for +invoking m4. As a result, it creates the following error: + +> flex: fatal internal error, exec of gm4 failed + +This commit fixes the problem by explicitly casting the value 0 to +the correct pointer type (char *). + +Signed-off-by: Yifeng Li +--- + src/main.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/main.c b/src/main.c +index e5eac44fe..5c9086183 100644 +--- a/src/main.c ++++ b/src/main.c +@@ -380,7 +380,7 @@ void check_options (void) + } + } + } +- filter_create_ext(output_chain, m4, "-P", 0); ++ filter_create_ext(output_chain, m4, "-P", (char *) 0); + filter_create_int(output_chain, filter_fix_linedirs, NULL); + + /* For debugging, only run the requested number of filters. */ diff --git a/sys-devel/flex/flex-2.6.4-r6.ebuild b/sys-devel/flex/flex-2.6.4-r6.ebuild new file mode 100644 index 000000000000..6da72c3dfe33 --- /dev/null +++ b/sys-devel/flex/flex-2.6.4-r6.ebuild @@ -0,0 +1,101 @@ +# Copyright 1999-2022 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +inherit flag-o-matic libtool multilib-minimal toolchain-funcs + +DESCRIPTION="The Fast Lexical Analyzer" +HOMEPAGE="https://github.com/westes/flex" +SRC_URI="https://github.com/westes/${PN}/releases/download/v${PV}/${P}.tar.gz" +SRC_URI+=" https://dev.gentoo.org/~sam/distfiles/${CATEGORY}/${PN}/${P}-autotools-regenerate.patch.xz" + +LICENSE="FLEX" +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="nls static test" +RESTRICT="!test? ( test )" + +RDEPEND="sys-devel/m4" +# We want bison explicitly and not yacc in general, bug #381273 +BDEPEND=" + ${RDEPEND} + nls? ( sys-devel/gettext ) + test? ( sys-devel/bison ) +" +PDEPEND="app-alternatives/lex" + +PATCHES=( + "${FILESDIR}"/${P}-libobjdir.patch + "${FILESDIR}"/${P}-fix-build-with-glibc2.26.patch + "${FILESDIR}"/${P}-fix-apple-m1-crash-by-explicit-pointer-cast.patch + + "${WORKDIR}"/${P}-autotools-regenerate.patch +) + +src_prepare() { + default + + # Drop on next release when we can remove ${P}-autotools-regenerate.patch + touch configure.ac aclocal.m4 Makefile.in configure src/config.h.in || die + + # Disable running in the tests/ subdir as it has a bunch of built sources + # that cannot be made conditional (automake limitation). bug #568842 + if ! use test ; then + sed -i \ + -e '/^SUBDIRS =/,/^$/{/tests/d}' \ + Makefile.in || die + fi + + # Prefix always needs this + elibtoolize +} + +src_configure() { + use static && append-ldflags -static + + multilib-minimal_src_configure +} + +multilib_src_configure() { + # Do not install shared libs, #503522 + ECONF_SOURCE="${S}" econf \ + CC_FOR_BUILD="$(tc-getBUILD_CC)" \ + --disable-shared \ + $(use_enable nls) +} + +multilib_src_compile() { + if multilib_is_native_abi; then + default + else + emake -C src -f Makefile -f - lib <<< 'lib: $(lib_LTLIBRARIES)' + fi +} + +multilib_src_test() { + multilib_is_native_abi && emake check +} + +multilib_src_install() { + if multilib_is_native_abi; then + default + else + emake -C src DESTDIR="${D}" install-libLTLIBRARIES install-includeHEADERS + fi +} + +multilib_src_install_all() { + einstalldocs + dodoc ONEWS + find "${ED}" -name '*.la' -type f -delete || die + rm "${ED}"/usr/share/doc/${PF}/COPYING || die +} + +pkg_postinst() { + # ensure to preserve the symlink before app-alternatives/lex + # is installed + if [[ ! -h ${EROOT}/usr/bin/lex ]]; then + ln -s flex "${EROOT}/usr/bin/lex" || die + fi +}