[Bug 281081] sysutils/ncdu2: Illegal instruction on some machines (amd64)

From: <bugzilla-noreply_at_freebsd.org>
Date: Mon, 26 Aug 2024 18:10:13 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=281081

            Bug ID: 281081
           Summary: sysutils/ncdu2: Illegal instruction on some machines
                    (amd64)
           Product: Ports & Packages
           Version: Latest
          Hardware: amd64
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: Individual Port(s)
          Assignee: sunpoet@FreeBSD.org
          Reporter: hpaluch@seznam.cz
             Flags: maintainer-feedback?(sunpoet@FreeBSD.org)
          Assignee: sunpoet@FreeBSD.org

Latest ncdu2 package (tested 2.4_1/amd64) is optimized for build server (that
is default behavior of Zig compiler) and thus it causes "Illegal instruction
error" on some CPUs.

How to reproduce:

$ freebsd-version 

14.1-RELEASE-p3

$ dmesg | fgrep CPU:

CPU: AMD Athlon(tm) 64 X2 Dual Core Processor 3800+ (2000.12-MHz K8-class CPU)

$ doas pkg install ncdu2

$ pkg info | fgrep ncdu2

ncdu2-2.4_1                    NCurses Disk Usage (stable version written in
Zig)


$ ncdu2

Illegal instruction (core dumped)



To get illegal instruction opcode we can use gdb:

gdb /usr/local/bin/ncdu2 
GNU gdb (GDB) 14.1 [GDB v14.1 for FreeBSD]
...
(gdb) run
Starting program: /usr/local/bin/ncdu2 

Program received signal SIGILL, Illegal instruction.
Privileged opcode.
0x00000000010a5c17 in ?? ()
(gdb) bt
#0  0x00000000010a5c17 in ?? ()
#1  0x0000000001060f54 in ?? ()
#2  0x0000000001057ab3 in ?? ()
#3  0x000000000104ff44 in ?? ()
#4  0x000000000104fc9c in ?? ()
#5  0x0000000801300a6a in __libc_start1 () from /lib/libc.so.7
#6  0x000000000104fa20 in ?? ()

(gdb) x/4i 0x00000000010a5c17
=> 0x10a5c17:   vpxor  %xmm0,%xmm0,%xmm0
   0x10a5c1b:   vmovdqa %ymm0,0xa0(%rsp)
   0x10a5c24:   mov    %rax,0x120(%rsp)
   0x10a5c2c:   mov    0x118(%rsp),%rax


There are some references on Internet that (v)pxor requires AVX2 set, but I was
uanble to find authoritative source.

Cause: Zig compiler always produces binary optimized for CPU on build server
unless instructed otherwise.

Workaround: pass "-Dcpu=x86_64" to Zig compiler - it should produce generic
amd64 binary.

Here are details of my CPU from dmesg:

CPU: AMD Athlon(tm) 64 X2 Dual Core Processor 3800+ (2000.12-MHz K8-class CPU)
  Origin="AuthenticAMD"  Id=0x40fb2  Family=0xf  Model=0x4b  Stepping=2
 
Features=0x178bfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,MMX,FXSR,SSE,SSE2,HTT>
  Features2=0x2001<SSE3,CX16>
  AMD Features=0xea500800<SYSCALL,NX,MMX+,FFXSR,RDTSCP,LM,3DNow!+,3DNow!>
  AMD Features2=0x1f<LAHF,CMP,SVM,ExtAPIC,CR8>
  SVM: NAsids=64

Same Illegal instruction error also occurs on another PC with "Intel(R)
Celeron(R) CPU N3450 @ 1.10GHz" (ZOTAC CI327 Nano )

-- 
You are receiving this mail because:
You are the assignee for the bug.