NetBSD Problem Report #59805

From ivan@siamics.net  Sat Nov 29 20:40:12 2025
Return-Path: <ivan@siamics.net>
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 "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id B18391A923A
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 29 Nov 2025 20:40:11 +0000 (UTC)
Message-Id: <53JHcxgEPbJI0suNsywcYVkRkD6KIMlG@violet.siamics.net>
Date: Sat, 29 Nov 2025 20:30:42 +0000
From: Ivan Shmakov <ivan@siamics.net>
To: gnats-bugs@netbsd.org
Subject: undefined reference to `_kvm_kvatop_i386pae' when building with -m32 on amd64 

>Number:         59805
>Category:       lib
>Synopsis:       undefined reference to `_kvm_kvatop_i386pae' when building with -m32 on amd64
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Nov 29 20:45:00 +0000 2025
>Closed-Date:    
>Last-Modified:  Sat Nov 29 21:26:05 +0000 2025
>Originator:     Ivan Shmakov
>Release:        NetBSD 10.1
>Organization:
Dbus-free station.
>Environment:
Architecture: x86_64
Machine: amd64
>Description:

	When attempting to build software for i386 on an amd64 host
	with -m32, linking with -lkvm fails like this (pkgsrc-2025Q3/
	sysutils/xosview; note the last two lines):

c++ -m32 -Wl,-zrelro -lkvm -Wl,-R/usr/pkg/lib -L/usr/pkg/lib -o xosview Host.o Xrm.o bitfieldmeter.o bitmeter.o defaultstring.o fieldmeter.o fieldmeterdecay.o fieldmetergraph.o llist.o main.o meter.o xosview.o xwin.o sensorfieldmeter.o bsd/MeterMaker.o bsd/btrymeter.o bsd/cpumeter.o bsd/diskmeter.o bsd/intmeter.o bsd/intratemeter.o bsd/kernel.o bsd/loadmeter.o bsd/memmeter.o bsd/netmeter.o bsd/pagemeter.o bsd/swapmeter.o bsd/sensor.o bsd/coretemp.o -lkvm -lprop -lX11 -lXpm -lm
ld: bsd/kernel.o: in function `BSDGetSensor(char const*, char const*, float*, char*)':
kernel.cc:(.text+0x1434): warning: this program uses prop_string_cstring_nocopy(), which is deprecated; use prop_string_value() instead.
ld: bsd/kernel.o: in function `BSDGetBatteryInfo(int*, unsigned int*)':
kernel.cc:(.text+0x1a6c): warning: this program uses prop_string_equals_cstring(), which is deprecated; prop_string_equals_string() instead.
ld: bsd/kernel.o: in function `BSDGetCPUTemperature(float*, float*)':
kernel.cc:(.text+0x11b3): warning: this program uses prop_number_integer_value(), which is deprecated; use prop_number_signed_value() instead.
ld: kernel.cc:(.text+0x10f5): warning: this program uses prop_dictionary_keysym_cstring_nocopy(), which is deprecated; use prop_dictionary_keysym_value() instead.
ld: /usr/lib/../lib/i386/libkvm.so: undefined reference to `_kvm_kvatop_i386pae'
gmake: *** [Makefile:130: xosview] Error 1

	The relevant linker invocation in work/.work.log:

[*] c++ -m32 -Wl,-zrelro -lkvm -Wl,-R/usr/pkg/lib -L/usr/pkg/lib -o xosview Host.o Xrm.o bitfieldmeter.o bitmeter.o defaultstring.o fieldmeter.o fieldmeterdecay.o fieldmetergraph.o llist.o main.o meter.o xosview.o xwin.o sensorfieldmeter.o bsd/MeterMaker.o bsd/btrymeter.o bsd/cpumeter.o bsd/diskmeter.o bsd/intmeter.o bsd/intratemeter.o bsd/kernel.o bsd/loadmeter.o bsd/memmeter.o bsd/netmeter.o bsd/pagemeter.o bsd/swapmeter.o bsd/sensor.o bsd/coretemp.o -lkvm -lprop -lX11 -lXpm -lm
<.> /.../pkgsrc/sysutils/xosview/work/.gcc/bin/g++ -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-zrelro -fPIC -m32 -Wl,-zrelro -lkvm -Wl,-rpath,/usr/pkg/lib -L/.../pkgsrc/sysutils/xosview/work/.buildlink/lib -o xosview Host.o Xrm.o bitfieldmeter.o bitmeter.o defaultstring.o fieldmeter.o fieldmeterdecay.o fieldmetergraph.o llist.o main.o meter.o xosview.o xwin.o sensorfieldmeter.o bsd/MeterMaker.o bsd/btrymeter.o bsd/cpumeter.o bsd/diskmeter.o bsd/intmeter.o bsd/intratemeter.o bsd/kernel.o bsd/loadmeter.o bsd/memmeter.o bsd/netmeter.o bsd/pagemeter.o bsd/swapmeter.o bsd/sensor.o bsd/coretemp.o -lkvm -lprop -lX11 -lXpm -lm -std=gnu++98 -I/.../pkgsrc/sysutils/xosview/work/.buildlink/include -pie

	And indeed, examining libkvm.so with nm(1) gives:

$ nm  /usr/lib/i386/libkvm.so 
...
00004314 T _kvm_kvatop
00004159 T _kvm_kvatop_i386
         U _kvm_kvatop_i386pae
0000467d T _kvm_malloc
00004384 T _kvm_mdopen
...

	The symbol /is/ defined in the version of the library from
	i386/binary/sets/base.tgz :

00004005 T _kvm_kvatop_i386pae

	Same failure happens for sysutils/lsof and devel/cmake.

	(On the plus side, it prompted me to look how many packages
	I can build without cmake somewhere in their dependency graph.
	Turns out, with a bit of patching, there're quite a few.)

>How-To-Repeat:

	I'm using the following /etc/mk.conf fragment so that -m32
	is used when building pkgsrc packages.  It works surprisingly
	well (the packages I've tried that have test suites generally
	pass them), though every once in a while there'll be a package
	that ignores the flags for one reason or another.

CFLAGS      += -m32 -mcpu=i486 -mtune=i586

## Some packages will use CFLAGS for CXX and linking, but some will not
CXXFLAGS    += -m32 -mcpu=i486 -mtune=i586
LDFLAGS     += -m32

## Imake-based packages require these instead
MAKE_FLAGS  +=  CCOPTIONS="-m32 -mcpu=i486 -mtune=i586"
MAKE_FLAGS  += CXXOPTIONS="-m32 -mcpu=i486 -mtune=i586"

MACHINE_ARCH = i386
MACHINE_GNU_ARCH = i386

## NB: there is /usr/lib/i386, but no /usr/X11R7/lib/i386
X11_TYPE = modular

	Once pkgsrc is set up:

$ cd sysutils/xosview && make build 
$ cd sysutils/lsof && make build 
$ cd devel/cmake && make build 

>Fix:

	I haven't tried, but I /think/ that changing usr/src/lib/
	libkvm/Makefile as follows might solve it.  (No idea about
	LINTFLAGS+=-w, though.)

--- src/lib/libkvm/Makefile.~1~	2016-01-24 16:07:48.000000000 +0000
+++ src/lib/libkvm/Makefile	2025-11-29 20:27:37 +0000
@@ -32,7 +32,7 @@
 	@false
 .endif

-.if ${MACHINE_ARCH} == "i386"
+.if (${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64")
 LINTFLAGS+=-w
 SRCS+=	kvm_i386pae.c # Hook PAE support in the i386 build
 .endif

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: lib-bug-people->riastradh
Responsible-Changed-By: riastradh@NetBSD.org
Responsible-Changed-When: Sat, 29 Nov 2025 21:02:05 +0000
Responsible-Changed-Why:
I'll take a whack at it


State-Changed-From-To: open->analyzed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sat, 29 Nov 2025 21:02:05 +0000
State-Changed-Why:
The patch you suggested is not quite right: it doesn't make sense for
the _native_ amd64 libkvm build, if I'm not mistakenn.  Instead, I
think this should use KVM_MACHINE_ARCH rather than MACHINE_ARCH: for
the compat i386 build on amd64, MACHINE_ARCH=x86_64 but
KVM_MACHINE_ARCH=i386.

(This will also require KVM_MACHINE_ARCH?=${MACHINE_ARCH} at the top.)


Responsible-Changed-From-To: riastradh->lib-bug-people
Responsible-Changed-By: riastradh@NetBSD.org
Responsible-Changed-When: Sat, 29 Nov 2025 21:26:05 +0000
Responsible-Changed-Why:
unlick this cookie


State-Changed-From-To: analyzed->open
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sat, 29 Nov 2025 21:26:05 +0000
State-Changed-Why:
Not sure this is right on second thought.  Drafted the following patch
and grew doubtful while writing the commit message.  Out of time to
think about this for now, but maybe someone else can think harder about
it.


# HG changeset patch
# User Taylor R Campbell <riastradh@NetBSD.org>
# Date 1764451378 0
#      Sat Nov 29 21:22:58 2025 +0000
# Branch trunk
# Node ID 466961a5186c16cae5b8c8bd15e225566d655542
# Parent  e2e753d86d5e78bb624fe387656a44c8b77f364b
# EXP-Topic riastradh-pr59805-libkvmcompatarch
WIP: libkvm: Use KVM_MACHINE_ARCH, not MACHINE_ARCH.

Without this, the compat i386 build includes kvm_i386.c but not
kvm_i386pae.c, so it lacks the symbol _kvm_kvatop_i386pae.

XXX Except, is this right?  Does it even make sense to use kvm_i386.c
on an amd64 kernel?  Shouldn't we do some kind of i386 build of
kvm_x86_64.c so that an i386 userland can get at the amd64 kernel
data structures?

PR lib/59805: undefined reference to `_kvm_kvatop_i386pae' when
building with -m32 on amd64

diff -r e2e753d86d5e -r 466961a5186c lib/libkvm/Makefile
--- a/lib/libkvm/Makefile	Fri Nov 28 16:47:59 2025 +0000
+++ b/lib/libkvm/Makefile	Sat Nov 29 21:22:58 2025 +0000
@@ -12,6 +12,9 @@ CPPFLAGS+=-DLIBC_SCCS -I${NETBSDSRCDIR}/

 SRCS=	kvm.c kvm_file.c kvm_getloadavg.c kvm_proc.c

+KVM_MACHINE_ARCH?=	${MACHINE_ARCH}
+KVM_MACHINE_CPU?=	${MACHINE_CPU}
+
 # This library should compile to the same thing on all variants of
 # ${MACHINE} with the same ${MACHINE_ARCH} so shared /usr works.
 # If it is necessary to run different code based on ${MACHINE} then
@@ -32,7 +35,7 @@ SRCS+=	kvm_${MACHINE_CPU}.c
 	@false
 .endif

-.if ${MACHINE_ARCH} == "i386"
+.if ${KVM_MACHINE_ARCH} == "i386"
 LINTFLAGS+=-w
 LINTFLAGS+=	-X 351		# 'extern' declaration outside header
 LINTFLAGS+=	-X 352		# 'extern' declaration in function body


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.