From bfad44e56d482df7a299f110778ab7cfcdd3fdd2 Mon Sep 17 00:00:00 2001 From: Johnothan King Date: Mon, 29 Nov 2021 04:38:17 -0800 Subject: [PATCH] Fix memory fault on ARM-based Macs (#354) Ksh segfaults on M1 Macs, apparently because Apple's compiler optimizer can't cope with overriding bzero(3) with libast's implementation (though it's nothing more than "memset(b, 0, n);"). Apple has disabled libast's bzero function since 2018-12-04: https://opensource.apple.com/source/ksh/ksh-27/patches/src__lib__libast__comp__omitted.c.diff.auto.html src/lib/libast/comp/omitted.c: - Only fall back to the libast bzero function if the OS lacks an implementation of bzero. - Remove the bzero undef since this fallback is only reached if the OS doesn't have bzero. NEWS: - Add compat info for macOS on ARM64. This notes that macOS Monterey can now compile and run ksh, although there is one regression test failure: builtins.sh[345]: printf %H: invalid UTF-8 characters (expected %3F%C2%86%3F%3F%3F; got %3F%C2%86%3F%3Fv%3F%3F) Thanks to @DesantBucie for the report and the testing. Resolves: https://github.com/ksh93/ksh/issues/329 --- NEWS | 2 ++ src/cmd/ksh93/README | 1 + src/lib/libast/comp/omitted.c | 4 +--- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index ff16465c2..9f00893ae 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ Any uppercase BUG_* names are modernish shell bug IDs. 2021-11-29: +- Fixed a memory fault that prevented ksh from functioning on ARM-based Macs. + - A bug that caused the time keyword to override the errexit shell option has been fixed. diff --git a/src/cmd/ksh93/README b/src/cmd/ksh93/README index d7229946d..9c5abd031 100644 --- a/src/cmd/ksh93/README +++ b/src/cmd/ksh93/README @@ -262,6 +262,7 @@ failures (crashes, and/or important functionality does not work). * illumos: OmniOS 2020-08-19 (gcc) on x86_64 macOS 10.13.6 (High Sierra) on x86_64 macOS 10.14.6 (Mojave) on x86_64 +* macOS 12.0.1 (Monterey) on ARM64 * NetBSD 8.1 on x86_64 * NetBSD 9.2 on x86_64 * OpenBSD 6.8 on x86_64 diff --git a/src/lib/libast/comp/omitted.c b/src/lib/libast/comp/omitted.c index 247aa52bf..4668b7ac7 100644 --- a/src/lib/libast/comp/omitted.c +++ b/src/lib/libast/comp/omitted.c @@ -1092,9 +1092,7 @@ utime(const char* path, const struct utimbuf* ut) * own bsd-like macros */ -#if !_lib_bzero || defined(bzero) - -#undef bzero +#if !_lib_bzero void bzero(void* b, size_t n)