NetBSD Problem Report #60518

From www@netbsd.org  Wed Jul 29 21:38:28 2026
Return-Path: <www@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)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.netbsd.org", Issuer "YR2" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 13FEE1A923B
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 29 Jul 2026 21:38:28 +0000 (UTC)
Message-Id: <20260729213826.B665C1A923C@mollari.NetBSD.org>
Date: Wed, 29 Jul 2026 21:38:26 +0000 (UTC)
From: uwe@stderr.spb.ru
Reply-To: uwe@stderr.spb.ru
To: gnats-bugs@NetBSD.org
Subject: sparc64 compat32 is not compatible enough
X-Send-Pr-Version: www-1.0
X-From4GNATS: "uwe@stderr.spb.ru via gnats" <gnats-admin@NetBSD.org>

>Number:         60518
>Category:       port-sparc64
>Synopsis:       sparc64 compat32 is not compatible enough
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-sparc64-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 29 21:40:00 +0000 2026
>Last-Modified:  Thu Jul 30 09:30:01 +0000 2026
>Originator:     Valery Ushakov
>Release:        NetBSD 11.99
>Organization:
>Environment:
NetBSD aurinko 11.99.7 NetBSD 11.99.7 (ULTRA1) #0: Thu Jul 23 00:59:41 MSK 2026  uwe@supi:/home/uwe/work/netbsd/cvs/src/sys/arch/sparc64/compile/ULTRA1 sparc64

>Description:
sparc64 ships compat32 libs, however the sparc64 32-bit libc has a
different set of sync/atomic functions compared to sparc 32-bit libc.
This makes it impossible to run some sparc binaries on sparc64 with
compat32 libs, notably sparc 32-bit gdb[*].

[*] port-sparc64/58976: sparc64 gdb cannot debug 32-bit binaries

>How-To-Repeat:
gdb32 copied over from the sparc build:

$ ldd ~/bin/gdb32
/home/uwe/bin/gdb32:
        -lexpat.2 => /usr/lib/sparc/libexpat.so.2
        -lgcc_s.1 => /usr/lib/sparc/libgcc_s.so.1
        -lc.12 => /usr/lib/sparc/libc.so.12
        -llzma.2 => /usr/lib/sparc/liblzma.so.2
        -lpthread.1 => /usr/lib/sparc/libpthread.so.1
        -lz.1 => /usr/lib/sparc/libz.so.1
        -lcurses.9 => /usr/lib/sparc/libcurses.so.9
        -lterminfo.2 => /usr/lib/sparc/libterminfo.so.2
        -lintl.1 => /usr/lib/sparc/libintl.so.1
        -lkvm.6 => /usr/lib/sparc/libkvm.so.6
        -lutil.7 => /usr/lib/sparc/libutil.so.7
        -lstdc++.9 => /usr/lib/sparc/libstdc++.so.9
        -lm.0 => /usr/lib/sparc/libm.so.0

Try to run it

$ cc -m32 -g hello.c
$ gdb32 -q a.out 
Reading symbols from a.out...
(gdb) /home/uwe/bin/gdb32: Undefined PLT symbol "__atomic_compare_exchange_1" (symnum = 325)
$ LD_BIND_NOW=1 gdb32 -q
/home/uwe/bin/gdb32: Undefined PLT symbol "__sync_bool_compare_and_swap_4" (symnum = 153)

>Fix:
Is it for natively compiled 32-bit code `cc -m32`?  Is it for running
sparc binaries?  Both?

I tried to look at the way compat32 libc compiles sync/atomic code,
but it's so meta, I've got lost, and I'm not even sure which set of
functions (all named alike but slightly differently) is expected to be
provided to begin with.  I'd argue that compat32 libc should be link
compatible with natively 32-bit libc from the sparc port.

>Audit-Trail:
From: Taylor R Campbell <riastradh@NetBSD.org>
To: Valery Ushakov <uwe@stderr.spb.ru>
Cc: gnats-bugs@NetBSD.org, netbsd-bugs@NetBSD.org
Subject: Re: port-sparc64/60518: sparc64 compat32 is not compatible enough
Date: Wed, 29 Jul 2026 23:29:53 +0000

 I bet this is the relevant part that's missing files needed for
 __atomic_compare_exchange_1, __sync_bool_compare_and_swap_4, and
 whatever else -- in addition to (or perhaps instead of) what the
 comment says, I think it is used when building compat32 libc.so on
 sparc64:

       5 # This is called with MACHINE=3Dsparc64 && MACHINE_ARCH=3Dsparc whe=
 n building
       6 # 32 bit kernels for ultrasparc hardware
       7 .if ${MACHINE} =3D=3D "sparc64" && \
       8 	(${HAVE_LLVM:Uno} =3D=3D "no" || (defined(LIB) && ${LIB} =3D=3D "k=
 ern"))
       9=20
      10 SPARC64DIR=3D	${.PARSEDIR}/../../sparc64/atomic
      11 .PATH.c: ${SPARC64DIR}
      12 .PATH.S: ${SPARC64DIR}
      13=20
      14 .include "${SPARC64DIR}/Makefile.inc"
      15=20
      16 .if defined(LIB) && (${LIB} =3D=3D "kern" || ${LIB} =3D=3D "c" || $=
 {LIB} =3D=3D "pthread" \
      17 	|| ${LIB} =3D=3D "rump")
      18 SRCS+=3D	atomic_nand_64_cas.c atomic_xor_64_cas.c atomic_sub_64_cas=
 .c \
      19 	atomic_cas_64_cas.c
      20 .endif
      21=20
      22 .else

 https://nxr.NetBSD.org/xref/src/common/lib/libc/arch/sparc/atomic/Makefile.=
 inc?r=3D1.24#5

 Try adding the following files to it (Makefile.inc rev. 1.18 from
 back in 2014):

 atomic_c11_compare_exchange_cas_32.c
 atomic_c11_compare_exchange_cas_16.c
 atomic_c11_compare_exchange_cas_8.c

 Also, try comparing the output of:

 sparc$ nm -gD --defined-only /usr/lib/libc.so
 sparc64$ nm -gD --defined-only /usr/lib/sparc/libc.so

 I bet there'll be other discrepancies too that have been overlooked
 over the years.

From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@NetBSD.org
Cc: Taylor R Campbell <riastradh@NetBSD.org>
Subject: Re: port-sparc64/60518: sparc64 compat32 is not compatible enough
Date: Thu, 30 Jul 2026 12:28:26 +0300

 On Wed, Jul 29, 2026 at 23:29:53 +0000, Taylor R Campbell wrote:

 > https://nxr.NetBSD.org/xref/src/common/lib/libc/arch/sparc/atomic/Makefile.inc?r=1.24#5
 > 
 > Try adding the following files to it (Makefile.inc rev. 1.18 from
 > back in 2014):

 Oh, I did...  I have this patch saved in my tree from ~1.5 years ago
 or so.  I never made it compile b/c of name clashes iirc
 (unfortunately I don't seem to have the logs saved), but I'm really
 just turning various knobs blidly here.  As I said, I have no idea
 which names in that set of several dozens are needed for what etc, and
 working off of the nm diff ran into a wall and I need help from
 someone with a clue.

 I'll try to get back to this patch later this week and see what fails,
 but I'll need a licensed professional to make sense of the results.

 Thanks!

 Index: Makefile.inc
 ===================================================================
 RCS file: /cvsroot/src/common/lib/libc/arch/sparc/atomic/Makefile.inc,v
 retrieving revision 1.24
 diff -u -p -p -r1.24 Makefile.inc
 --- Makefile.inc	30 Mar 2023 15:03:36 -0000	1.24
 +++ Makefile.inc	27 Jun 2026 10:30:02 -0000
 @@ -13,13 +13,57 @@ SPARC64DIR=	${.PARSEDIR}/../../sparc64/a

  .include "${SPARC64DIR}/Makefile.inc"

 -.if defined(LIB) && (${LIB} == "kern" || ${LIB} == "c" || ${LIB} == "pthread" \
 -	|| ${LIB} == "rump")
 +. if defined(LIB)
 +
 +.  if (${LIB} == "kern" || ${LIB} == "c" || ${LIB} == "pthread" \
 +    || ${LIB} == "rump")
 +# sparc64 -m32
  SRCS+=	atomic_nand_64_cas.c atomic_xor_64_cas.c atomic_sub_64_cas.c \
  	atomic_cas_64_cas.c
 +
 +# SRCS+=	atomic_add_32_nv_cas.c	# __atomic_add_fetch_4
  .endif

 -.else
 +
 +.  if ${LIB} == "c"
 +
 +# XXX: also pthread
 +# XXX: multiple inits...
 +# SRCS+=	atomic_init_testset.c
 +
 +# __atomic_compare_exchange_<n>
 +SRCS+=	atomic_c11_compare_exchange_cas_8.c
 +SRCS+=	atomic_c11_compare_exchange_cas_16.c
 +SRCS+=	atomic_c11_compare_exchange_cas_32.c
 +
 +# __atomic_exchange_<n>
 +# __sync_lock_test_and_set_<n>
 +SRCS+=	atomic_swap_8_cas.c atomic_swap_16_cas.c # atomic_swap_32_cas.c
 +
 +# __sync_bool_compare_and_swap_<n>
 +SRCS+=	atomic_cas_8_cas.c  atomic_cas_16_cas.c  atomic_cas_32_cas.c
 +
 +# The 32 versions come from atomic_<op>.c
 +# __atomic_fetch_<op>_<n>
 +# __sync_fetch_and_<op>_<n>
 +# __sync_<op>_and_fetch_<n>
 +SRCS+=	atomic_add_8_cas.c  atomic_add_16_cas.c
 +SRCS+=	atomic_and_8_cas.c  atomic_and_16_cas.c
 +SRCS+=	atomic_nand_8_cas.c atomic_nand_16_cas.c
 +SRCS+=	atomic_or_8_cas.c   atomic_or_16_cas.c
 +SRCS+=	atomic_sub_8_cas.c  atomic_sub_16_cas.c
 +SRCS+=	atomic_xor_8_cas.c  atomic_xor_16_cas.c
 +
 +SRCS+=	atomic_load.c atomic_store.c
 +SRCS+=	atomic_is_lock_free.c
 +
 +.  endif # libc
 +
 +.endif	# LIB
 +
 +
 +
 +.else	# sparc

  . if defined(LIB)



 -uwe

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.