From patchwork Fri Nov 26 16:57:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 48198 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 243053858400 for ; Fri, 26 Nov 2021 16:58:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 243053858400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637945924; bh=tN0fMYw5d5JsTGd9cFgFB0EAzpY5PWsNfnvy7Jz+UG8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=n7iUspcZUNpz8WtjNji+qj1fRXP5MgEDXmgnM/htx9+BnSWgak8kZOfFOqH6HB9Vi fbVtQXo4L2PZQYbiQ2ZX+mHrZSpCI43bUjKAG+tzcSNyMIyrl59jI+0C9Be7UY2FOB 4i3o3QTuVb+vZOIuQcHE7fk/CIjVnW15uZZ9DjRU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from magnesium.8pit.net (magnesium.8pit.net [45.76.88.171]) by sourceware.org (Postfix) with ESMTP id A48733858D39; Fri, 26 Nov 2021 16:58:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A48733858D39 Received: from localhost (ip5f5ae01d.dynamic.kabel-deutschland.de [95.90.224.29]) by magnesium.8pit.net (OpenSMTPD) with ESMTPSA id 0b74fd2b (TLSv1.3:AEAD-AES256-GCM-SHA384:256:YES); Fri, 26 Nov 2021 17:58:11 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] stddef.h: add support for musl typedef macro guards Date: Fri, 26 Nov 2021 17:57:17 +0100 Message-Id: <20211126165717.9729-1-soeren@soeren-tempel.net> X-Mailer: git-send-email 2.34.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: soeren--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: soeren@soeren-tempel.net Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Sören Tempel The stddef.h header checks/sets various hardcoded toolchain/os specific macro guards to prevent redefining types such as ptrdiff_t, wchar_t, or size_t. However, without this patch, the file does not check/set the typedef macro guards for musl libc. This causes types such as size_t to be defined twice for files which include both musl's stddef.h as well as GCC's ginclude/stddef.h. This is, for example, the case for libgo/sysinfo.c. If libgo/sysinfo.c has multiple typedefs for size_t this confuses -fdump-go-spec and causes size_t not to be included in the generated type definitions thereby causing a gcc-go compilation failure on Alpine Linux Edge (which uses musl libc) with the following error: sysinfo.go:7765:13: error: use of undefined type '_size_t' 7765 | type Size_t _size_t | ^ libcall_posix.go:49:35: error: non-integer len argument in make 49 | b := make([]byte, len) | This commit fixes this issue by ensuring that ptrdiff_t, wchar_t, and size_t are only defined once in the pre-processed libgo/sysinfo.c file by enhancing gcc/ginclude/stddef.h with musl-specific typedef macro guards. gcc/ChangeLog: * ginclude/stddef.h (__DEFINED_ptrdiff_t): Add support for musl libc typedef macro guard. (__DEFINED_size_t): Ditto. (__DEFINED_wchar_t): Ditto. --- gcc/ginclude/stddef.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h index 9d67eac4947..770a6d321b3 100644 --- a/gcc/ginclude/stddef.h +++ b/gcc/ginclude/stddef.h @@ -128,6 +128,7 @@ _TYPE_wchar_t; #ifndef ___int_ptrdiff_t_h #ifndef _GCC_PTRDIFF_T #ifndef _PTRDIFF_T_DECLARED /* DragonFly */ +#ifndef __DEFINED_ptrdiff_t /* musl libc */ #define _PTRDIFF_T #define _T_PTRDIFF_ #define _T_PTRDIFF @@ -137,10 +138,12 @@ _TYPE_wchar_t; #define ___int_ptrdiff_t_h #define _GCC_PTRDIFF_T #define _PTRDIFF_T_DECLARED +#define __DEFINED_ptrdiff_t #ifndef __PTRDIFF_TYPE__ #define __PTRDIFF_TYPE__ long int #endif typedef __PTRDIFF_TYPE__ ptrdiff_t; +#endif /* __DEFINED_ptrdiff_t */ #endif /* _PTRDIFF_T_DECLARED */ #endif /* _GCC_PTRDIFF_T */ #endif /* ___int_ptrdiff_t_h */ @@ -174,6 +177,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t; #ifndef _SIZE_T_DEFINED #ifndef _BSD_SIZE_T_DEFINED_ /* Darwin */ #ifndef _SIZE_T_DECLARED /* FreeBSD 5 */ +#ifndef __DEFINED_size_t /* musl libc */ #ifndef ___int_size_t_h #ifndef _GCC_SIZE_T #ifndef _SIZET_ @@ -191,6 +195,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t; #define _SIZE_T_DEFINED #define _BSD_SIZE_T_DEFINED_ /* Darwin */ #define _SIZE_T_DECLARED /* FreeBSD 5 */ +#define __DEFINED_size_t /* musl libc */ #define ___int_size_t_h #define _GCC_SIZE_T #define _SIZET_ @@ -215,6 +220,7 @@ typedef long ssize_t; #endif /* _SIZET_ */ #endif /* _GCC_SIZE_T */ #endif /* ___int_size_t_h */ +#endif /* __DEFINED_size_t */ #endif /* _SIZE_T_DECLARED */ #endif /* _BSD_SIZE_T_DEFINED_ */ #endif /* _SIZE_T_DEFINED */ @@ -251,6 +257,7 @@ typedef long ssize_t; #ifndef _BSD_WCHAR_T_DEFINED_ /* Darwin */ #ifndef _BSD_RUNE_T_DEFINED_ /* Darwin */ #ifndef _WCHAR_T_DECLARED /* FreeBSD 5 */ +#ifndef __DEFINED_wchar_t /* musl libc */ #ifndef _WCHAR_T_DEFINED_ #ifndef _WCHAR_T_DEFINED #ifndef _WCHAR_T_H @@ -272,6 +279,7 @@ typedef long ssize_t; #define __INT_WCHAR_T_H #define _GCC_WCHAR_T #define _WCHAR_T_DECLARED +#define __DEFINED_wchar_t /* On BSD/386 1.1, at least, machine/ansi.h defines _BSD_WCHAR_T_ instead of _WCHAR_T_, and _BSD_RUNE_T_ (which, unlike the other @@ -326,6 +334,7 @@ typedef __WCHAR_TYPE__ wchar_t; #endif #endif #endif +#endif /* __DEFINED_wchar_t */ #endif /* _WCHAR_T_DECLARED */ #endif /* _BSD_RUNE_T_DEFINED_ */ #endif