NetBSD Problem Report #56188

From cjep@netbsd.org  Tue May 18 18:25:46 2021
Return-Path: <cjep@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))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 4CB181A92B5
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 18 May 2021 18:25:46 +0000 (UTC)
Message-Id: <20210518182544.A6A9E1A92B6@mollari.NetBSD.org>
Date: Tue, 18 May 2021 18:25:44 +0000 (UTC)
From: cjep@netbsd.org
Reply-To: cjep@netbsd.org
To: gnats-bugs@NetBSD.org
Subject: port-amiga does not cross-build (build.sh) on Darwin due to heapsort definition
X-Send-Pr-Version: 3.95

>Number:         56188
>Category:       port-amiga
>Synopsis:       port-amiga does not cross-build (build.sh) on Darwin due to heapsort definition
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    cjep
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue May 18 18:30:00 +0000 2021
>Closed-Date:    Sun May 30 10:40:43 +0000 2021
>Last-Modified:  Sun May 30 10:40:43 +0000 2021
>Originator:     Chris Pinnock
>Release:        Observed on both NetBSD 9.2 sources and latest current
>Organization:
>Environment:
Darwin MacMini-8795 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

>Description:
The build of the amiga port fails on Darwin in the standalone section.
This appears to be due to the override in the compat headers of the 
function heapsort. 


#    create  amiga-elf2bb/elf2bb.d
/Volumes/TimeMachine/Chris/NetBSD/current/src/../objects/amiga/tooldir.Darwin-20.4.0-x86_64/bin/nbhost-mkdep -f elf2bb.d.tmp  --      -I/Volumes/TimeMachine/Chris/NetBSD/current/src/tools/amiga-elf2bb -no-cpp-precomp -I/Volumes/TimeMachine/Chris/NetBSD/current/src/../objects/amiga/tooldir.Darwin-20.4.0-x86_64/include/compat -I/Volumes/TimeMachine/Chris/NetBSD/current/src/tools/compat -DHAVE_NBTOOL_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -I.     /Volumes/TimeMachine/Chris/NetBSD/current/src/tools/amiga-elf2bb/../../sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c &&  mv -f elf2bb.d.tmp elf2bb.d
#    create  amiga-elf2bb/.depend
rm -f .depend
/Volumes/TimeMachine/Chris/NetBSD/current/src/../objects/amiga/tooldir.Darwin-20.4.0-x86_64/bin/nbhost-mkdep -s .lo\ .ln\ .d -d -f .depend chksum.d elf2bb.d
#   compile  amiga-elf2bb/elf2bb.lo
cc -O  -I/Volumes/TimeMachine/Chris/NetBSD/current/src/tools/amiga-elf2bb -no-cpp-precomp -I/Volumes/TimeMachine/Chris/NetBSD/current/src/../objects/amiga/tooldir.Darwin-20.4.0-x86_64/include/compat -I/Volumes/TimeMachine/Chris/NetBSD/current/src/tools/compat -DHAVE_NBTOOL_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -I. -c -o elf2bb.lo.o    /Volumes/TimeMachine/Chris/NetBSD/current/src/tools/amiga-elf2bb/../../sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c
/Volumes/TimeMachine/Chris/NetBSD/current/src/tools/amiga-elf2bb/../../sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c:373:3: error: implicit declaration of function '__nbcompat_heapsort' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                heapsort(relbuf, r32sz, 4, intcmp);
                ^
/Volumes/TimeMachine/Chris/NetBSD/current/src/tools/compat/compat_defs.h:465:18: note: expanded from macro 'heapsort'
#define heapsort __nbcompat_heapsort
                 ^
/Volumes/TimeMachine/Chris/NetBSD/current/src/tools/amiga-elf2bb/../../sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c:424:50: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
        printf("using %d bytes, %d bytes remaining.\n", delta > 0 ?
                      ~~                                ^~~~~~~~~~~
                      %ld
/Volumes/TimeMachine/Chris/NetBSD/current/src/tools/amiga-elf2bb/../../sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c:425:46: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
            rpo-buffer-tsz-dsz : buffer+bbsize-rpo, delta > 0 ?
                                                    ^~~~~~~~~~~
2 warnings and 1 error generated.

*** Failed target: elf2bb.lo
*** Failed commands:
        ${_MKTARGET_COMPILE}
        ${HOST_COMPILE.c} -o ${.TARGET}.o ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
        ${MV} ${.TARGET}.o ${.TARGET}
*** [elf2bb.lo] Error code 1


>How-To-Repeat:
./build -m amiga -U build 
on a Darwin machine with either NetBSD 9.2 or current sources

>Fix:
Removing the #define in tools/compat/compat_defs.h on line 465 (current) 
redefining heapsort to the nbcompat one allows the build to complete but is unlikely to be the correct answer.

>Release-Note:

>Audit-Trail:
From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/56188 CVS commit: src/sys/arch/amiga/stand/bootblock/elf2bb
Date: Tue, 18 May 2021 20:32:18 +0000

 Module Name:	src
 Committed By:	dholland
 Date:		Tue May 18 20:32:18 UTC 2021

 Modified Files:
 	src/sys/arch/amiga/stand/bootblock/elf2bb: elf2bb.c

 Log Message:
 Print ptrdiff_t with %td, not %d. Appeared in passing in PR 56188.


 To generate a diff of this commit:
 cvs rdiff -u -r1.18 -r1.19 src/sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-amiga/56188: port-amiga does not cross-build (build.sh) on
 Darwin due to heapsort definition
Date: Tue, 18 May 2021 20:32:27 +0000

 On Tue, May 18, 2021 at 06:30:01PM +0000, cjep@netbsd.org wrote:
  > The build of the amiga port fails on Darwin in the standalone section.
  > This appears to be due to the override in the compat headers of the 
  > function heapsort. 
  > [...]
  > 
  > cc -O  -I/Volumes/TimeMachine/Chris/NetBSD/current/src/tools/amiga-elf2bb -no-cpp-precomp -I/Volumes/TimeMachine/Chris/NetBSD/current/src/../objects/amiga/tooldir.Darwin-20.4.0-x86_64/include/compat -I/Volumes/TimeMachine/Chris/NetBSD/current/src/tools/compat -DHAVE_NBTOOL_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -I. -c -o elf2bb.lo.o    /Volumes/TimeMachine/Chris/NetBSD/current/src/tools/amiga-elf2bb/../../sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c
  > /Volumes/TimeMachine/Chris/NetBSD/current/src/tools/amiga-elf2bb/../../sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c:373:3: error: implicit declaration of function '__nbcompat_heapsort' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  >                 heapsort(relbuf, r32sz, 4, intcmp);
  >                 ^
  > /Volumes/TimeMachine/Chris/NetBSD/current/src/tools/compat/compat_defs.h:465:18: note: expanded from macro 'heapsort'
  > #define heapsort __nbcompat_heapsort
  >                  ^

 The most likely cause of this is some unexpected misordering in the
 includes that causes the header with the heapsort declaration in it to
 be included before compat_defs.h, so that the rename doesn't get
 applied to it.

 Not entirely clear from here why this should be or where it's
 happening, but it should be easier to find out given the failed build.


  > /Volumes/TimeMachine/Chris/NetBSD/current/src/tools/amiga-elf2bb/../../sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c:424:50: warning: format specifies type 'int' but the argument has type 'long' [-Wformat]
  >         printf("using %d bytes, %d bytes remaining.\n", delta > 0 ?
  >                       ~~                                ^~~~~~~~~~~
  >                       %ld

 This should be %td (for ptrdiff_t), I'll fix that.


 -- 
 David A. Holland
 dholland@netbsd.org

Responsible-Changed-From-To: port-amiga-maintainer->cjep
Responsible-Changed-By: cjep@NetBSD.org
Responsible-Changed-When: Sat, 29 May 2021 08:03:22 +0000
Responsible-Changed-Why:
I will take this as I may have a solution for it. Checking with someone
who knows the toolchain better


State-Changed-From-To: open->analyzed
State-Changed-By: cjep@NetBSD.org
State-Changed-When: Sat, 29 May 2021 08:03:22 +0000
State-Changed-Why:
Root cause is understood - fix in progress.


From: "Chris Pinnock" <cjep@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/56188 CVS commit: src/tools/compat
Date: Sun, 30 May 2021 10:39:41 +0000

 Module Name:	src
 Committed By:	cjep
 Date:		Sun May 30 10:39:41 UTC 2021

 Modified Files:
 	src/tools/compat: compat_defs.h

 Log Message:
 PR port-amiga/56188

 Include a prototype for __nbcompat_heapsort. The tools for amiga now
 build on Darwin where one Amiga specific tool uses heapsort.

 Despite being a one-liner, ./build.sh -m amiga tools was tested on
 NetBSD, Darwin, FreeBSD & Linux with the change.

 Discussed various options with jdc & thorpej. Perhaps in the future
 we could look at using qsort instead of heapsort as qsort is
 standardised and more likely to be available. We could then remove
 heapsort from the compatibility library.


 To generate a diff of this commit:
 cvs rdiff -u -r1.119 -r1.120 src/tools/compat/compat_defs.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: analyzed->closed
State-Changed-By: cjep@NetBSD.org
State-Changed-When: Sun, 30 May 2021 10:40:43 +0000
State-Changed-Why:
Fixed in current


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.