NetBSD Problem Report #58271

From www@netbsd.org  Tue May 21 00:55:53 2024
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))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id EB7581A9265
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 21 May 2024 00:55:52 +0000 (UTC)
Message-Id: <20240521005551.6DFB01A9266@mollari.NetBSD.org>
Date: Tue, 21 May 2024 00:55:51 +0000 (UTC)
From: tmcintos@eskimo.com
Reply-To: tmcintos@eskimo.com
To: gnats-bugs@NetBSD.org
Subject: external/gpl3/gcc/dist/gcc/system.h: Early inclusion of "safe-type.h" causes toolchain build failure on macOS 14.5
X-Send-Pr-Version: www-1.0

>Number:         58271
>Category:       toolchain
>Synopsis:       external/gpl3/gcc/dist/gcc/system.h: Early inclusion of "safe-type.h" causes toolchain build failure on macOS 14.5
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue May 21 01:00:00 +0000 2024
>Last-Modified:  Wed Jul 24 22:25:01 +0000 2024
>Originator:     Timothy McIntosh
>Release:        netbsd-10
>Organization:
>Environment:
% uname -a
Darwin m2.astro.net 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:19:05 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8112 arm64

% clang --version
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

% xcodebuild -version -sdk macosx
MacOSX14.5.sdk - macOS 14.5 (macosx14.5)
SDKVersion: 14.5
Path: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk
PlatformVersion: 14.5
PlatformPath: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform
BuildID: A011F280-02DD-11EF-ADB6-B65E12B1A625
ProductBuildVersion: 23F73
ProductCopyright: 1983-2024 Apple Inc.
ProductName: macOS
ProductUserVisibleVersion: 14.5
ProductVersion: 14.5
iOSSupportVersion: 17.5

>Description:
I was attempting to build a toolchain for NetBSD/sgimips from the netbsd-10 branch pulled from git today, using the following build command:

./build.sh -U -u -j8 -m sgimips -O ../sgimips tools

This failed during building of gcov.c with errors in clang's `usr/include/c++/v1/__locale` file (pulled in via system.h's inclusion of <map>), at line 550 and later...

    _LIBCPP_INLINE_VISIBILITY
    char_type toupper(char_type __c) const
    {
        return do_toupper(__c);
    }

...due to a bad interaction with the macros (including toupper(c)) defined at the end of safe-ctype.h.

I was able to work around this problem by moving inclusion of "safe-ctype.h" to the end of `system.h`, as shown in the patch below, which minimizes the exposure of system headers to the nonstandard macro definitions in safe-ctype.h.

In general, it seems unsafe to redefine reserved identifiers as is done in safe-ctype.h.
>How-To-Repeat:
Run the following on macOS 14.5 with Xcode version & SDK documented above:

git clone --branch netbsd-10 --depth 1 https://github.com/NetBSD/src.git src
cd src
./build.sh -U -u -j8 -m sgimips -O ../sgimips tools

>Fix:
diff --git a/external/gpl3/gcc/dist/gcc/system.h b/external/gpl3/gcc/dist/gcc/system.h
index 239496698..1077282ba 100644
--- a/external/gpl3/gcc/dist/gcc/system.h
+++ b/external/gpl3/gcc/dist/gcc/system.h
@@ -209,11 +209,6 @@ extern int fprintf_unlocked (FILE *, const char *, ...);
 #endif
 #endif

-/* There are an extraordinary number of issues with <ctype.h>.
-   The last straw is that it varies with the locale.  Use libiberty's
-   replacement instead.  */
-#include "safe-ctype.h"
-
 #include <sys/types.h>

 #include <errno.h>
@@ -1213,6 +1208,11 @@ helper_const_non_const_cast (const char *p)
 /* Get definitions of HOST_WIDE_INT.  */
 #include "hwint.h"

+/* There are an extraordinary number of issues with <ctype.h>.
+   The last straw is that it varies with the locale.  Use libiberty's
+   replacement instead.  */
+#include "safe-ctype.h"
+
 typedef int sort_r_cmp_fn (const void *, const void *, void *);
 void qsort_chk (void *, size_t, size_t, sort_r_cmp_fn *, void *);
 void gcc_sort_r (void *, size_t, size_t, sort_r_cmp_fn *, void *);

>Audit-Trail:
From: "David H. Gutteridge" <david@gutteridge.ca>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: toolchain/58271: external/gpl3/gcc/dist/gcc/system.h: Early
 inclusion of "safe-type.h" causes toolchain build failure on macOS 14.5
Date: Tue, 23 Jul 2024 21:58:46 -0400

 This seems related to another macOS build failure (in that case,
 an ARM cross-compiler GCC in pkgsrc):

 http://mail-index.netbsd.org/pkgsrc-users/2024/04/11/msg039348.html

 Unfortunately, I don't have any such hardware to test with, but maybe
 someone else who does can handle these issues in general.

 Dave

From: matthew green <mrg@eterna23.net>
To: gnats-bugs@netbsd.org
Cc: toolchain-manager@netbsd.org, gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org, tmcintos@eskimo.com
Subject: re: toolchain/58271: external/gpl3/gcc/dist/gcc/system.h: Early inclusion of "safe-type.h" causes toolchain build failure on macOS 14.5
Date: Thu, 25 Jul 2024 08:23:52 +1000

 i was wondering about this change, what has upstream done for this problem,
 because this won't be just a netbsd tools issue will it?


 .mrg.

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-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.