aboutsummaryrefslogtreecommitdiffstats
path: root/main/gcc/0041-libgo-Recognize-off64_t-and-loff_t-definitions-of-mu.patch
blob: 35de9a06061930ed6178fd97a9a0eda47caa2b68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
From eab088e3a76ce23cf2365351c59707e2dd0aa599 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
Date: Sun, 28 Nov 2021 00:54:37 +0100
Subject: [PATCH] libgo: Recognize off64_t and loff_t definitions of musl libc

Without this patch, both off64_t and loff_t are not recognized by
-fdump-go-spec which causes a variety Go-related compilation errors on
musl libc since the gcc-go frontend expects both off64_t and loff_t to
be present.

Also make sure that autoconf recognizes support for loff_t on musl, by
compiling the relevant feature test code with -D_GNU_SOURCE and making
it include fcntl.h which defines loff_t on musl.
---
 libgo/configure    |  4 +++-
 libgo/configure.ac |  4 +++-
 libgo/sysinfo.c    | 21 +++++++++++++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/libgo/configure b/libgo/configure
index 70f64c974fd..69d15839e8c 100755
--- a/libgo/configure
+++ b/libgo/configure
@@ -15546,7 +15546,9 @@ _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
diff --git a/libgo/configure.ac b/libgo/configure.ac
index ebab9d9de3e..a3d9d309aba 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -602,7 +602,9 @@ 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" # musl does not define loff_t without this
+AC_CHECK_TYPES([loff_t], [], [], [[#include <fcntl.h>]])
 
 LIBS_hold="$LIBS"
 LIBS="$LIBS -lm"
diff --git a/libgo/sysinfo.c b/libgo/sysinfo.c
index 8ce061e2f5f..b85add15a7b 100644
--- a/libgo/sysinfo.c
+++ b/libgo/sysinfo.c
@@ -343,6 +343,27 @@ 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
+// -fdump-go-spec option, which is responsible for generating type
+// definitions for Go based on this file, only recognizes types defined
+// through typedefs.
+//
+// For this reason, we check here if either off64_t or loff_t are
+// defined as CPP macros and if so, we redefine them using a C typedef.
+#if defined(HAVE_OFF64_T) && defined(off64_t)
+typedef off64_t __musl_off64_t;
+#undef off64_t
+typedef __musl_off64_t off64_t;
+#endif
+
+// See comment regarding musl libc above.
+#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
-- 
2.34.1