From patchwork Sun Apr 24 10:17:45 2022 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: 53148 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 868393858036 for ; Sun, 24 Apr 2022 10:20:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 868393858036 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1650795643; bh=OiuaVXnfAsL5m5pOFr3EgP7eOJm9d1E3C6vGLhS6Xaw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=kf9f0adwcp6pFQmJG7lengUbSmmUxIJmEgP0/durjd6fTzWepWIQGKB/DLWp7KHXD 3ztPLkDgVc+4USOxpw2d9EA5Cf6tdFI/j0K/cGKVj8fMqBF+1vZFWZlkrRac7NhDCz 7uvHYub1FsSAJmiZ2TxPTe4TNuuQCg8Mk0JCyEgk= 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 CBF903858D28; Sun, 24 Apr 2022 10:20:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CBF903858D28 Received: from localhost (ip5f5ae040.dynamic.kabel-deutschland.de [95.90.224.64]) by magnesium.8pit.net (OpenSMTPD) with ESMTPSA id d0775e08 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:YES); Sun, 24 Apr 2022 12:20:09 +0200 (CEST) To: gofrontend-dev@googlegroups.com Subject: [PATCH] libgo: Recognize off64_t / loff_t type definition of musl libc Date: Sun, 24 Apr 2022 12:17:45 +0200 Message-Id: <20220424101745.13252-1-soeren@soeren-tempel.net> X-Mailer: git-send-email 2.35.2 MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 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 Cc: gcc-patches@gcc.gnu.org, iant@golang.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Sören Tempel The libgo code assumes both off64_t and loff_t to be present. For example, for the splice(2) function prototype. Similar to glibc, musl libc supports these types but defines them as macros, not as typedefs. Unfortunately, -fdump-go-spec only recognizes types defined using typedef. To workaround that, this commit adds explicit typedefs for these types if off64_t or loff_t are defined as macros. Furthermore, loff_t is only defined on musl with -D_GNU_SOURCE and requires an include of fcntl.h (this is in accordance with the splice(2) man page). Therefore, the configure script has also been adjusted accordingly. --- libgo/configure | 6 +++++- libgo/configure.ac | 6 +++++- libgo/sysinfo.c | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/libgo/configure b/libgo/configure index ffe17c9b..b83ddfb3 100755 --- a/libgo/configure +++ b/libgo/configure @@ -15546,7 +15546,10 @@ _ACEOF fi -ac_fn_c_check_type "$LINENO" "loff_t" "ac_cv_type_loff_t" "$ac_includes_default" +CFLAGS_hold=$CFLAGS +CFLAGS="$CFLAGS -D_GNU_SOURCE" +ac_fn_c_check_type "$LINENO" "loff_t" "ac_cv_type_loff_t" "#include +" if test "x$ac_cv_type_loff_t" = xyes; then : cat >>confdefs.h <<_ACEOF @@ -15556,6 +15559,7 @@ _ACEOF fi +CFLAGS=$CFLAGS_hold LIBS_hold="$LIBS" LIBS="$LIBS -lm" diff --git a/libgo/configure.ac b/libgo/configure.ac index 7e2b98ba..b8f7d1a0 100644 --- a/libgo/configure.ac +++ b/libgo/configure.ac @@ -601,7 +601,11 @@ AC_STRUCT_DIRENT_D_TYPE AC_CHECK_FUNCS(accept4 dup3 epoll_create1 faccessat fallocate fchmodat fchownat futimesat getxattr inotify_add_watch inotify_init inotify_init1 inotify_rm_watch listxattr mkdirat mknodat open64 openat pipe2 removexattr renameat setxattr sync_file_range splice syscall tee unlinkat unshare utimensat) AC_TYPE_OFF_T -AC_CHECK_TYPES([loff_t]) + +CFLAGS_hold=$CFLAGS +CFLAGS="$CFLAGS -D_GNU_SOURCE" +AC_CHECK_TYPES([loff_t], [], [], [[#include ]]) +CFLAGS=$CFLAGS_hold LIBS_hold="$LIBS" LIBS="$LIBS -lm" diff --git a/libgo/sysinfo.c b/libgo/sysinfo.c index 8ce061e2..22f52e5b 100644 --- a/libgo/sysinfo.c +++ b/libgo/sysinfo.c @@ -343,6 +343,20 @@ enum { #endif }; +// musl libc has both off64_t and loff_t. However, both of these types +// are defined as CPP macros, not as C typedefs. Unfortunately, the GCC +// option -fdump-go-spec only recognizes types defined using typedefs. +#if defined(HAVE_OFF64_T) && defined(off64_t) +typedef off64_t __musl_off64_t; +#undef off64_t +typedef __musl_off64_t off64_t; +#endif +#if defined(HAVE_LOFF_T) && defined(loff_t) +typedef loff_t __musl_loff_t; +#undef loff_t +typedef __musl_loff_t loff_t; +#endif + // SIOCGIFMTU can't be added in the above enum as it might // be signed in some OSes. #ifdef SIOCGIFMTU