From: Sören Tempel <soeren+...@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

Reply via email to