Bug#1059616: "wc -l" gives "illegal instruction"

2024-05-21 Thread Marc Haber
On Fri, Dec 29, 2023 at 03:38:32PM +, Pádraig Brady wrote:
> On 29/12/2023 09:52, gates.ocarina...@icloud.com wrote:
> > When I run command wc -l, it gives “illegal instruction”.

I can confirm this for at least one of my machines.

> https://github.com/coreutils/coreutils/commit/91a74d361.patch
> https://github.com/coreutils/coreutils/commit/7814596fa.patch

I can confirm that those two patches fix the issue for me on Debian
bookworm. They don't apply cleanly to the sources in bookworm, but the
result is still fine. I'll attach the new quilt patch file.

Since I am not using Debian's default kernel and the issue only happens
on one of my machines, I won't raise the severity, but if this also
happens with a Debian kernel, this would be an RC bug for me and warrant
a bookworm point release upload.

Greetings
Marc

--- a/configure.ac
+++ b/configure.ac
@@ -544,27 +544,6 @@ CFLAGS=$ac_save_CFLAGS
 LDFLAGS=$ac_save_LDFLAGS
 ac_c_werror_flag=$cu_save_c_werror_flag
 
-AC_MSG_CHECKING([if __get_cpuid available])
-AC_LINK_IFELSE(
-  [AC_LANG_SOURCE([[
-#include 
-
-int
-main (void)
-{
-  unsigned int eax, ebx, ecx, edx;
-  __get_cpuid (1, &eax, &ebx, &ecx, &edx);
-  return 1;
-}
-  ]])
-  ],[
-AC_MSG_RESULT([yes])
-AC_DEFINE([HAVE_CPUID], [1], [__get_cpuid available])
-cpuid_exists=yes
-  ],[
-AC_MSG_RESULT([no])
-  ])
-
 ac_save_CFLAGS=$CFLAGS
 CFLAGS="-mavx -mpclmul $CFLAGS"
 AC_MSG_CHECKING([if pclmul intrinsic exists])
@@ -628,23 +607,20 @@ AC_COMPILE_IFELSE(
 {
   __m256i a, b;
   a = _mm256_sad_epu8 (a, b);
-  return 1;
+  return __builtin_cpu_supports ("avx2");
 }
   ]])
   ],[
-AC_MSG_RESULT([yes])
-AC_DEFINE([HAVE_AVX2_INTRINSIC], [1], [avx2 intrinsics exists])
 avx2_intrinsic_exists=yes
   ],[
-AC_MSG_RESULT([no])
+avx2_intrinsic_exists=no
   ])
-if test "x$get_cpuid_count_exists" = "xyes" &&
-   test "x$avx2_intrinsic_exists" = "xyes"; then
+AC_MSG_RESULT([$avx2_intrinsic_exists])
+if test $avx2_intrinsic_exists = yes; then
   AC_DEFINE([USE_AVX2_WC_LINECOUNT], [1], [Counting lines with AVX2 enabled])
 fi
 AM_CONDITIONAL([USE_AVX2_WC_LINECOUNT],
-   [test "x$get_cpuid_count_exists" = "xyes" &&
-test "x$avx2_intrinsic_exists" = "xyes"])
+   [test $avx2_intrinsic_exists = yes])
 
 CFLAGS=$ac_save_CFLAGS
 
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,9 @@ GNU coreutils NEWS
   for B when A is a directory, possibly inflooping.
   [bug introduced in coreutils-6.3]
 
+  'wc -l' no longer crashes on x86 Linux kernels that disable XSAVE YMM.
+  [bug introduced in coreutils-9.0]
+
 ** Changes in behavior
 
   cat now uses the copy_file_range syscall if available, when doing
--- a/src/cksum.c
+++ b/src/cksum.c
@@ -159,29 +159,16 @@ static bool
 pclmul_supported (void)
 {
 # if USE_PCLMUL_CRC32
-  unsigned int eax = 0;
-  unsigned int ebx = 0;
-  unsigned int ecx = 0;
-  unsigned int edx = 0;
-
-  if (! __get_cpuid (1, &eax, &ebx, &ecx, &edx))
-{
-  if (cksum_debug)
-error (0, 0, "%s", _("failed to get cpuid"));
-  return false;
-}
-
-  if (! (ecx & bit_PCLMUL) || ! (ecx & bit_AVX))
-{
-  if (cksum_debug)
-error (0, 0, "%s", _("pclmul support not detected"));
-  return false;
-}
+  bool pclmul_enabled = (0 < __builtin_cpu_supports ("pclmul")
+ && 0 < __builtin_cpu_supports ("avx"));
 
   if (cksum_debug)
-error (0, 0, "%s", _("using pclmul hardware support"));
+error (0, 0, "%s",
+   (pclmul_enabled
+? _("using pclmul hardware support")
+: _("pclmul support not detected")));
 
-  return true;
+  return pclmul_enabled;
 # else
   if (cksum_debug)
 error (0, 0, "%s", _("using generic hardware support"));
--- a/src/wc.c
+++ b/src/wc.c
@@ -132,52 +132,14 @@ static struct option const longopts[] =
 static bool
 avx2_supported (void)
 {
-  unsigned int eax = 0;
-  unsigned int ebx = 0;
-  unsigned int ecx = 0;
-  unsigned int edx = 0;
-  bool getcpuid_ok = false;
-  bool avx_enabled = false;
+  bool avx_enabled = 0 < __builtin_cpu_supports ("avx2");
 
-  if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-{
-  getcpuid_ok = true;
-  if (ecx & bit_OSXSAVE)
-avx_enabled = true;  /* Support is not disabled.  */
-}
+  if (debug)
+error (0, 0, (avx_enabled
+  ? _("using avx2 hardware support")
+  : _("avx2 support not detected")));
 
-
-  if (avx_enabled)
-{
-  eax = ebx = ecx = edx = 0;
-  if (! __get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
-getcpuid_ok = false;
-  else
-{
-  if (! (ebx & bit_AVX2))
-avx_enabled = false;  /* Hardware doesn't support it.  */
-}
-}
-
-
-  if (! getcpuid_ok)
-{
-  if (debug)
-error (0, 0, "%s", _("failed to get cpuid"));
-  return false;
-}
-  else if (! avx_enabled)
-{
-  if (debug)
-error (0, 0,

Bug#1059616: "wc -l" gives "illegal instruction"

2023-12-29 Thread Pádraig Brady

On 29/12/2023 09:52, gates.ocarina...@icloud.com wrote:


Package: coreutils
Version: 9.1-1

When I run command wc -l, it gives “illegal instruction”.
I reinstalled the coreutils package:

$ wc -l

Illegal instruction


$ ls -l | wc -l

Illegal instruction


$ ls -l | wc -lw

       4      29


$ wc test.txt

10  8 18 test.txt


$ cat test.txt | wc -mwl

      10       8      18


$ wc -l test.txt

Illegal instruction


$ cat test.txt | wc -l

Illegal instruction


These upstream patches should address the issue:

https://github.com/coreutils/coreutils/commit/91a74d361.patch
https://github.com/coreutils/coreutils/commit/7814596fa.patch



Bug#1059616: "wc -l" gives "illegal instruction"

2023-12-29 Thread gates . ocarina-0e

Package: coreutils
Version: 9.1-1

When I run command wc -l, it gives “illegal instruction”.
I reinstalled the coreutils package:

$ wc -l
Illegal instruction

$ ls -l | wc -l
Illegal instruction

$ ls -l | wc -lw
  4  29

$ wc test.txt 
10  8 18 test.txt

$ cat test.txt | wc -mwl
 10   8  18

$ wc -l test.txt 
Illegal instruction

$ cat test.txt | wc -l
Illegal instruction


Linux 6.1.0-16-amd64, Debian 6.1.67-1