NetBSD Problem Report #60048

From bsiegert@netbsd.org  Sun Mar  1 14:27:07 2026
Return-Path: <bsiegert@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.netbsd.org", Issuer "R13" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 558261A9239
	for <gnats-bugs@gnats.NetBSD.org>; Sun,  1 Mar 2026 14:27:07 +0000 (UTC)
Message-Id: <20260301142706.DC52684D89@mail.netbsd.org>
Date: Sun,  1 Mar 2026 14:27:06 +0000 (UTC)
From: bsiegert@netbsd.org
Reply-To: bsiegert@netbsd.org
To: gnats-bugs@NetBSD.org
Subject: Illegal instruction when cross-compiling
X-Send-Pr-Version: 3.95
X-From4GNATS: "bsiegert@netbsd.org via gnats" <gnats-admin@NetBSD.org>

>Number:         60048
>Category:       toolchain
>Synopsis:       Illegal instruction when cross-compiling
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Mar 01 14:30:00 +0000 2026
>Last-Modified:  Mon Mar 02 14:05:00 +0000 2026
>Originator:     Benny Siegert
>Release:        NetBSD 11.99.5
>Organization:
The NetBSD Foundation
>Environment:
System: NetBSD xxx 11.0_BETA NetBSD 11.0_BETA (GENERIC) #0: Mon Oct 20 14:11:07 UTC 2025  mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
When cross-compiling on a NetBSD/amd64 machine for a riscv64 target, building a kernel fails. The failure is always in a floating-point multiplication in a const. There are several of these in the kernel, so with -j higher than 1, you sometimes hit one or the other. For example this (with -j 1):

#   compile  kern/rngtest.o
/usr/src/obj/tooldir.NetBSD-11.0_BETA-amd64/bin/riscv64--netbsd-gcc -mcmodel=medany -ffreestanding -fno-zero-initialized-in-bss  -fno-delete-null-pointer-checks   -O2 -fno-omit-frame-pointer  -fstack-usage -Wstack-usage=3584  -fno-strict-aliasing -fno-common     -std=gnu11   -Werror -Wall -Wno-main -Wno-format-zero-length -Wpointer-arith -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -Wno-unreachable-code -Wno-pointer-sign -Wno-attributes -Wno-type-limits -Wno-sign-compare    -Wno-address-of-packed-member  -Walloca      --sysroot=/usr/src/obj/destdir.riscv -I/usr/src/sys/lib/libkern/arch/riscv --sysroot=/usr/src/obj/destdir.riscv -Driscv -I../../. -I/usr/src/sys/external/bsd/libnv/dist -I/usr/src/sys/external/bsd/acpica/dist -I/usr/src/sys/../common/lib/libx86emu -I/usr/src/sys/../common/lib/libc/misc -I/usr/src/sys/../common/include -I/usr/src/sys/arch -I/usr/src/sys -nostdinc -DCOMPAT_UTILS -D__HAVE_PCI_CONF_HOOK -DFPE 
 -DCOMPAT_44 -DDIAGNOSTIC -DDEBUG -D_KERNEL -D_KERNEL_OPT -std=gnu11 -I/usr/src/sys/lib/libkern/../../../common/lib/libc/quad -I/usr/src/sys/lib/libkern/../../../common/lib/libc/string -I/usr/src/sys/lib/libkern/../../../common/lib/libc/arch/riscv/string -I/usr/src/sys/lib/libkern/../../../common/lib/libc/arch/riscv/atomic -I/usr/src/sys/lib/libkern/../../../common/lib/libc/hash/sha3 -I/usr/src/sys/external/bsd/libfdt/dist -I/usr/src/sys/external/bsd/libnv/dist  -I/usr/src/sys/lib/libkern/../../../common/lib/libc/quad -I/usr/src/sys/lib/libkern/../../../common/lib/libc/string -I/usr/src/sys/lib/libkern/../../../common/lib/libc/arch/riscv/string -I/usr/src/sys/lib/libkern/../../../common/lib/libc/arch/riscv/atomic -I/usr/src/sys/lib/libkern/../../../common/lib/libc/hash/sha3 -I/usr/src/sys/lib/libkern/../../../common/include -I/usr/src/sys/lib/libkern/../../../common/include/libc -I/usr/src/sys/lib/libkern/../../../common/libc/hash/sha3  -c    /usr/src/sys/lib/libkern/rngtest.c -o rng
 test.o
/usr/src/sys/lib/libkern/rngtest.c:169:1: internal compiler error: Illegal instruction
               169 | const long long minpoke = (MINPOKE * PRECISION);
                   | ^~~~~
Please submit a full bug report, with preprocessed source (by using -freport-bug).
See <http://www.NetBSD.org/support/send-pr.html> for instructions.

*** Failed target:  rngtest.o

When run with -j 4, another one of these bombs first:

/usr/src/sys/kern/kern_synch.c:1123:1: internal compiler error: Illegal instruction
 1123 | const fixpt_t ccpu = 0.95122942450071400909 * FSCALE;
      | ^~~~~
Please submit a full bug report, with preprocessed source (by using -freport-bug).
See <http://www.NetBSD.org/support/send-pr.html> for instructions.

*** Failed target: kern_synch.o
*** In directory: /usr/obj/sys/arch/riscv/compile/GENERIC64


I have seen the same issues when compiling for aarch64 (MACHINE=evbarm64) from amd64.
>How-To-Repeat:
On a fresh checkout of src:

$ ./build.sh -j 4 -N 1 -U -m riscv -a riscv64 tools kernel=GENERIC64
>Fix:
I would love to see a fix! This is supposed to work, no?

>Audit-Trail:
From: "David H. Gutteridge" <david@gutteridge.ca>
To: Gnats Bugs <gnats-bugs@netbsd.org>
Cc: 
Subject: Re: toolchain/60048: Illegal instruction when cross-compiling
Date: Sun, 01 Mar 2026 18:08:54 -0500

 As another data point, this is not reproducible for me, building an
 11.99.5 riscv GENERIC64 on 11.99.5 amd64. Perhaps there is something
 amiss on the netbsd-11 branch.

 Dave

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: toolchain/60048: Illegal instruction when cross-compiling
Date: Mon, 2 Mar 2026 07:52:29 +0100

 On Sun, Mar 01, 2026 at 11:10:01PM +0000, David H. Gutteridge via gnats wrote:
 >  As another data point, this is not reproducible for me, building an
 >  11.99.5 riscv GENERIC64 on 11.99.5 amd64. Perhaps there is something
 >  amiss on the netbsd-11 branch.

 It is a different gcc version (14.3 on -current, 12.5 on -11).

 Martin

From: "David H. Gutteridge" <david@gutteridge.ca>
To: Gnats Bugs <gnats-bugs@netbsd.org>
Cc: 
Subject: Re: toolchain/60048: Illegal instruction when cross-compiling
Date: Mon, 02 Mar 2026 09:00:23 -0500

 On Mon, 2 Mar 2026 at 06:55:02 +0000 (UTC), Martin Husemann wrote:
 >  It is a different gcc version (14.3 on -current, 12.5 on -11).

 Right, though I guess the big question is why it doesn't fail in releng
 builds for the 11 branch. Hmm.

 (The GCC 14 change -- for riscv, specifically -- hadn't made it into
 the doc/CHANGES document, so I just updated it.)

 It was also noted

 >> I have seen the same issues when compiling for aarch64
 >> (MACHINE=evbarm64) from amd64.

 I've been regularly cross-compiling HEAD for aarch64 on amd64 for many
 months (before the GCC update to 14.3) and have never encountered this
 issue there (on more than one machine, ranging from -j 4 to -j 16).

 Dave

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.