public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libgo: Recognize off64_t / loff_t type definition of musl libc
@ 2022-04-24 10:17 soeren
  2022-05-07 11:18 ` Sören Tempel
  2022-05-09 23:33 ` [PATCH] " Ian Lance Taylor
  0 siblings, 2 replies; 17+ messages in thread
From: soeren @ 2022-04-24 10:17 UTC (permalink / raw)
  To: gofrontend-dev; +Cc: iant, gcc-patches

From: Sören Tempel <soeren+git@soeren-tempel.net>

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 <fcntl.h>
+"
 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 <fcntl.h>]])
+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

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2022-06-21 16:53 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-24 10:17 [PATCH] libgo: Recognize off64_t / loff_t type definition of musl libc soeren
2022-05-07 11:18 ` Sören Tempel
2022-05-09 23:33 ` [PATCH] " Ian Lance Taylor
2022-05-12 18:22   ` Sören Tempel
2022-05-12 21:04     ` Ian Lance Taylor
2022-05-18  7:22       ` Sören Tempel
2022-05-31 19:41         ` Sören Tempel
2022-06-17 21:27           ` Ian Lance Taylor
2022-06-18  7:18             ` Andreas Schwab
2022-06-18 15:28               ` Ian Lance Taylor
2022-06-18 15:59                 ` Andreas Schwab
2022-06-20  7:39                   ` Eric Botcazou
2022-06-21  7:34                     ` Sören Tempel
2022-06-21 12:26                       ` Franz Sirl
2022-06-21 15:03                   ` Ian Lance Taylor
2022-06-21 15:16                     ` Andreas Schwab
2022-06-21 16:53                       ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).