Index | Thread | Search

From:
James Cook <falsifian@falsifian.org>
Subject:
Re: -current Haskell ports aborting with SIGILL
To:
Greg Steuck <gnezdo@openbsd.org>
Cc:
Evan Silberman <evan@jklol.net>, Greg Steuck <greg@nest.cx>, ports@openbsd.org, Antoine Jacoutot <ajacoutot@bsdfrog.org>
Date:
Sun, 21 Apr 2024 21:03:30 +0000

Download raw body.

Thread
On Sun, Apr 21, 2024 at 11:49:46AM -0700, Greg Steuck wrote:
> Stuart Henderson <stu@spacehopper.org> writes:
> 
> > This is in the avx512 checks in the text library again, I think it must
> > be patch-libraries_text_cbits_measure_off_c (the simdutf one doesn't
> > explicitly check for xgetbv but it does check for osxsave so I think
> > wouldn't have executed the xgetbv opcode on this cpu).
> >
> > As -current does now have avx512 support in the kernel we probably
> > should be able to remove that patch, but it needs testing on an avx512
> > machine as well as that old Phenom.
> 
> Sadly I have neither nearby. Furthermore, sumdutf upstream doesn't have
> a fix for this issue either. So this will have to be original work.
> 
> https://github.com/simdutf/simdutf/blob/master/include/simdutf/internal/isadetection.h#L232
> 
> Thanks
> Greg

The following patch fixes at least the ghci example on my AMD machine:

	$ ghci              
	GHCi, version 9.6.4: https://www.haskell.org/ghc/  :? for help
	ghci> import qualified Data.Text as T
	ghci> T.take 1 $ T.pack "aa"
	"a"

It simply patches has_avx512_vl_bw to always return false. Would
this be a good candidate for the stable branch, which doesn't support
AVX-512 anyway?

I will try building pandoc now with the new ghc to see if it's
fixed. (I'm a little fuzzy on how libraries are included... hopefully
pandoc will take the patched library from the updated ghc? Or does
it not work like that?)

-- 
James


Index: Makefile
===================================================================
RCS file: /cvs/ports/lang/ghc/Makefile,v
diff -u -p -u -p -r1.223.2.1 Makefile
--- Makefile	21 Mar 2024 20:52:54 -0000	1.223.2.1
+++ Makefile	21 Apr 2024 20:59:59 -0000
@@ -14,7 +14,7 @@ USE_NOEXECONLY =	Yes
 USE_NOBTCFI =		Yes
 
 GHC_VERSION =		9.6.4
-REVISION =		2
+REVISION =		3
 DISTNAME =		ghc-${GHC_VERSION}
 CATEGORIES =		lang devel
 HOMEPAGE =		https://www.haskell.org/ghc/
Index: patches/patch-libraries_text_cbits_measure_off_c
===================================================================
RCS file: /cvs/ports/lang/ghc/patches/patch-libraries_text_cbits_measure_off_c,v
diff -u -p -u -p -r1.2 patch-libraries_text_cbits_measure_off_c
--- patches/patch-libraries_text_cbits_measure_off_c	23 Feb 2024 19:45:04 -0000	1.2
+++ patches/patch-libraries_text_cbits_measure_off_c	21 Apr 2024 20:59:59 -0000
@@ -1,23 +1,24 @@
-Don't attempt to use avx512 kernels when the OS doesn't support them
+Don't attempt to use avx512 kernels, because OpenBSD 7.5 doesn't support them
 
 Index: libraries/text/cbits/measure_off.c
 --- libraries/text/cbits/measure_off.c.orig
 +++ libraries/text/cbits/measure_off.c
-@@ -44,12 +44,16 @@
+@@ -42,17 +42,8 @@
+ 
+ #if defined(__x86_64__) && defined(COMPILER_SUPPORTS_AVX512)
  bool has_avx512_vl_bw() {
- #if (__GNUC__ >= 7 || __GNUC__ == 6 && __GNUC_MINOR__ >= 3) || defined(__clang_major__)
-   uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
-+  uint64_t xcr0;
-   __get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx);
-   // https://en.wikipedia.org/wiki/CPUID#EAX=7,_ECX=0:_Extended_Features
-+  __asm__("xgetbv\n\t" : "=a" (xcr0) : "c" (0));
-   const bool has_avx512_bw = ebx & (1 << 30);
-   const bool has_avx512_vl = ebx & (1 << 31);
-+  // XCR0 bits 5, 6, and 7
-+  const bool avx512_os_enabled = (xcr0 & 0xE0) == 0xE0;
-   // printf("cpuid=%d=cpuid\n", has_avx512_bw && has_avx512_vl);
+-#if (__GNUC__ >= 7 || __GNUC__ == 6 && __GNUC_MINOR__ >= 3) || defined(__clang_major__)
+-  uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
+-  __get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx);
+-  // https://en.wikipedia.org/wiki/CPUID#EAX=7,_ECX=0:_Extended_Features
+-  const bool has_avx512_bw = ebx & (1 << 30);
+-  const bool has_avx512_vl = ebx & (1 << 31);
+-  // printf("cpuid=%d=cpuid\n", has_avx512_bw && has_avx512_vl);
 -  return has_avx512_bw && has_avx512_vl;
-+  return has_avx512_bw && has_avx512_vl && avx512_os_enabled;
- #else
+-#else
++  /* OpenBSD 7.5 doesn't support AVX-512. */
    return false;
+-#endif
+ }
  #endif
+