diff options
author | Ismael Luceno | 2022-12-11 05:45:20 +0100 |
---|---|---|
committer | Ismael Luceno | 2022-12-12 08:55:42 +0100 |
commit | c1a43ce5bfd357c2a707d9c7eb8c5ae64b14b4b2 (patch) | |
tree | 62a57c5015e0cc4e4f943acca6ab77f7d6f61c7a /gnu | |
parent | 14dd9723dea37d6312f00bcb2d8942a587c0b8cd (diff) |
gcc: Fix libgo for musl
Diffstat (limited to 'gnu')
9 files changed, 765 insertions, 0 deletions
diff --git a/gnu/gcc/HISTORY b/gnu/gcc/HISTORY index fb25f51c30..1326093281 100644 --- a/gnu/gcc/HISTORY +++ b/gnu/gcc/HISTORY @@ -1,3 +1,14 @@ +2022-12-12 Ismael Luceno <ismael@sourcemage.org> + * patches/0001-libgo-Add-support-for-libucontext.patch, + patches/0034-Use-generic-errstr.go-implementation-on-musl.patch, + patches/0037-libgo-Recognize-off64_t-and-loff_t-definitions-of-mu.patch, + patches/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch, + patches/0041-go-gospec-forcibly-disable-fsplit-stack-support.patch, + patches/0042-gcc-go-fix-build-error-with-SYS_SECCOMP.patch, + patches/0049-libgo-adjust-name-of-union-in-sigevent-struct.patch, + patches/0051-libgo-Explicitly-define-SYS_timer_settime-for-32-bit.patch: + fixed libgo for musl + 2022-09-23 Ismael Luceno <ismael@sourcemage.org> * patches/0001-libgo-make-match.sh-POSIX-shell-compatible.patch: fixed bashism in libgo/match.sh diff --git a/gnu/gcc/patches/0001-libgo-Add-support-for-libucontext.patch b/gnu/gcc/patches/0001-libgo-Add-support-for-libucontext.patch new file mode 100644 index 0000000000..76e9e67559 --- /dev/null +++ b/gnu/gcc/patches/0001-libgo-Add-support-for-libucontext.patch @@ -0,0 +1,52 @@ +From 0631e2b9453b33c42e12a14c11e8257d470016c5 Mon Sep 17 00:00:00 2001 +From: Ismael Luceno <ismael@sourcemage.org> +Date: Sun, 11 Dec 2022 23:55:56 +0100 +Subject: [PATCH] libgo: Add support for libucontext + +Test and link to libucontext if detected; additionally: undefine +SETCONTEXT_CLOBBERS_TLS in runtime/proc.c to prevent the use of +makecontext/swapcontext, not supported by libucontext. + +[ismael@iodev.co.uk: Fixed to work with glibc too, tests for libucontext + properly; improved commit message] + +Based on a patch by Sören Tempel <soeren+git@soeren-tempel.net>. + +Upstream-Status: Pending +Origin: Unknown +Signed-off-by: Ismael Luceno <ismael@sourcemage.org> +--- + Makefile.in | 2 ++ + libgo/runtime/proc.c | 6 ++++++ + 2 files changed, 8 insertions(+) + +diff --git a/Makefile.in b/Makefile.in +index 593495e1650..c3e5d489bc0 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -52801,6 +52801,8 @@ configure-target-libgo: + esac; \ + module_srcdir=libgo; \ + rm -f no-such-file || : ; \ ++ LIBS="`printf 'int main(){return 0;}' | $(CC) -x c -o /dev/null \ ++ - -lucontext && printf -lucontext` $$LIBS" \ + CONFIG_SITE=no-such-file $(SHELL) \ + $$s/$$module_srcdir/configure \ + --srcdir=$${topdir}/$$module_srcdir \ +diff --git a/libgo/runtime/proc.c b/libgo/runtime/proc.c +index 3a30748d329..a987678fa84 100644 +--- a/libgo/runtime/proc.c ++++ b/libgo/runtime/proc.c +@@ -66,6 +66,12 @@ static void gscanstack(G*); + + __thread G *g __asm__(GOSYM_PREFIX "runtime.g"); + ++/* libucontext does not seem to support tlsbase, undef the macro ++ * here to make sure we define initcontext and fixcontext as dummies. */ ++#if !defined(__GLIBC__) && defined(__linux__) ++#undef SETCONTEXT_CLOBBERS_TLS ++#endif ++ + #ifndef SETCONTEXT_CLOBBERS_TLS + + static inline void diff --git a/gnu/gcc/patches/0034-Use-generic-errstr.go-implementation-on-musl.patch b/gnu/gcc/patches/0034-Use-generic-errstr.go-implementation-on-musl.patch new file mode 100644 index 0000000000..a5ad797743 --- /dev/null +++ b/gnu/gcc/patches/0034-Use-generic-errstr.go-implementation-on-musl.patch @@ -0,0 +1,204 @@ +From b3840bdcc0eee2a4d099a9af52199944ade7acb9 Mon Sep 17 00:00:00 2001 +From: Ian Lance Taylor <iant@golang.org> +Date: Tue, 29 Nov 2022 17:28:44 -0800 +Subject: [PATCH] syscall, runtime: always call XSI strerror_r +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This does the right thing for either glibc or musl on GNU/Linux. + +Based on patch by Sören Tempel. + +Change-Id: If2969e131f0fae456d58b35d839d8abe191fcc59 +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/454176 +Reviewed-by: Cherry Mui <cherryyz@google.com> +Reviewed-by: Ian Lance Taylor <iant@google.com> +TryBot-Bypass: Ian Lance Taylor <iant@google.com> +--- + libgo/Makefile.am | 1 + + libgo/Makefile.in | 6 +++++- + libgo/go/syscall/errstr.go | 22 ++++++++----------- + libgo/go/syscall/errstr_glibc.go | 33 ---------------------------- + libgo/runtime/go-strerror.c | 37 ++++++++++++++++++++++++++++++++ + 5 files changed, 52 insertions(+), 47 deletions(-) + delete mode 100644 libgo/go/syscall/errstr_glibc.go + create mode 100644 libgo/runtime/go-strerror.c + +diff --git a/libgo/Makefile.am b/libgo/Makefile.am +index e0a1eec5..df568743 100644 +--- a/libgo/Makefile.am ++++ b/libgo/Makefile.am +@@ -465,6 +465,7 @@ runtime_files = \ + runtime/go-nanotime.c \ + runtime/go-now.c \ + runtime/go-nosys.c \ ++ runtime/go-strerror.c \ + runtime/go-reflect-call.c \ + runtime/go-setenv.c \ + runtime/go-signal.c \ +diff --git a/libgo/Makefile.in b/libgo/Makefile.in +index 7bef5df9..f2f3f0fc 100644 +--- a/libgo/Makefile.in ++++ b/libgo/Makefile.in +@@ -247,7 +247,7 @@ am__objects_4 = runtime/aeshash.lo runtime/go-assert.lo \ + runtime/go-fieldtrack.lo runtime/go-matherr.lo \ + runtime/go-memclr.lo runtime/go-memmove.lo \ + runtime/go-memequal.lo runtime/go-nanotime.lo \ +- runtime/go-now.lo runtime/go-nosys.lo \ ++ runtime/go-now.lo runtime/go-nosys.lo runtime/go-strerror.lo \ + runtime/go-reflect-call.lo runtime/go-setenv.lo \ + runtime/go-signal.lo runtime/go-unsafe-pointer.lo \ + runtime/go-unsetenv.lo runtime/go-unwind.lo \ +@@ -917,6 +917,7 @@ runtime_files = \ + runtime/go-nanotime.c \ + runtime/go-now.c \ + runtime/go-nosys.c \ ++ runtime/go-strerror.c \ + runtime/go-reflect-call.c \ + runtime/go-setenv.c \ + runtime/go-signal.c \ +@@ -1390,6 +1391,8 @@ runtime/go-now.lo: runtime/$(am__dirstamp) \ + runtime/$(DEPDIR)/$(am__dirstamp) + runtime/go-nosys.lo: runtime/$(am__dirstamp) \ + runtime/$(DEPDIR)/$(am__dirstamp) ++runtime/go-strerror.lo: runtime/$(am__dirstamp) \ ++ runtime/$(DEPDIR)/$(am__dirstamp) + runtime/go-reflect-call.lo: runtime/$(am__dirstamp) \ + runtime/$(DEPDIR)/$(am__dirstamp) + runtime/go-setenv.lo: runtime/$(am__dirstamp) \ +@@ -1457,6 +1460,7 @@ distclean-compile: + @AMDEP_TRUE@@am__include@ @am__quote@runtime/$(DEPDIR)/go-reflect-call.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@runtime/$(DEPDIR)/go-setenv.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@runtime/$(DEPDIR)/go-signal.Plo@am__quote@ ++@AMDEP_TRUE@@am__include@ @am__quote@runtime/$(DEPDIR)/go-strerror.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@runtime/$(DEPDIR)/go-unsafe-pointer.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@runtime/$(DEPDIR)/go-unsetenv.Plo@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@runtime/$(DEPDIR)/go-unwind.Plo@am__quote@ +diff --git a/libgo/go/syscall/errstr.go b/libgo/go/syscall/errstr.go +index 6c2441d3..9f688e2a 100644 +--- a/libgo/go/syscall/errstr.go ++++ b/libgo/go/syscall/errstr.go +@@ -4,23 +4,19 @@ + // Use of this source code is governed by a BSD-style + // license that can be found in the LICENSE file. + +-// +build !hurd +-// +build !linux +- + package syscall + +-//sysnb strerror_r(errnum int, buf []byte) (err Errno) +-//strerror_r(errnum _C_int, buf *byte, buflen Size_t) _C_int ++import "internal/bytealg" ++ ++//extern go_strerror ++func go_strerror(_C_int, *byte, Size_t) _C_int + + func Errstr(errnum int) string { +- for len := 128; ; len *= 2 { +- b := make([]byte, len) +- errno := strerror_r(errnum, b) ++ for size := 128; ; size *= 2 { ++ b := make([]byte, size) ++ errno := go_strerror(_C_int(errnum), &b[0], Size_t(len(b))) + if errno == 0 { +- i := 0 +- for b[i] != 0 { +- i++ +- } ++ i := bytealg.IndexByte(b, 0) + // Lowercase first letter: Bad -> bad, but + // STREAM -> STREAM. + if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] && b[1] <= 'z' { +@@ -29,7 +25,7 @@ func Errstr(errnum int) string { + return string(b[:i]) + } + if errno != ERANGE { +- return "errstr failure" ++ return "strerror_r failure" + } + } + } +diff --git a/libgo/go/syscall/errstr_glibc.go b/libgo/go/syscall/errstr_glibc.go +deleted file mode 100644 +index 5b19e6f2..00000000 +--- a/libgo/go/syscall/errstr_glibc.go ++++ /dev/null +@@ -1,33 +0,0 @@ +-// errstr_glibc.go -- GNU/Linux and GNU/Hurd specific error strings. +- +-// Copyright 2010 The Go Authors. All rights reserved. +-// Use of this source code is governed by a BSD-style +-// license that can be found in the LICENSE file. +- +-// We use this rather than errstr.go because on GNU/Linux sterror_r +-// returns a pointer to the error message, and may not use buf at all. +- +-// +build hurd linux +- +-package syscall +- +-import "unsafe" +- +-//sysnb strerror_r(errnum int, b []byte) (errstr *byte) +-//strerror_r(errnum _C_int, b *byte, len Size_t) *byte +- +-func Errstr(errnum int) string { +- a := make([]byte, 128) +- p := strerror_r(errnum, a) +- b := (*[1000]byte)(unsafe.Pointer(p)) +- i := 0 +- for b[i] != 0 { +- i++ +- } +- // Lowercase first letter: Bad -> bad, but STREAM -> STREAM. +- if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] && b[1] <= 'z' { +- c := b[0] + 'a' - 'A' +- return string(c) + string(b[1:i]) +- } +- return string(b[:i]) +-} +diff --git a/libgo/runtime/go-strerror.c b/libgo/runtime/go-strerror.c +new file mode 100644 +index 00000000..13d1d91d +--- /dev/null ++++ b/libgo/runtime/go-strerror.c +@@ -0,0 +1,37 @@ ++/* go-strerror.c -- wrapper around XSI-compliant strerror_r. ++ ++ Copyright 2022 The Go Authors. All rights reserved. ++ Use of this source code is governed by a BSD-style ++ license that can be found in the LICENSE file. */ ++ ++/* There are two version of strerror_r on GNU/Linux: a GNU-specific ++ and an XSI-compliant version. The former version is only available ++ on glibc. Since glibc 2.13, the XSI-compliant version is also ++ provided by glibc if _GNU_SOURCE is not defined. Since the ++ entirety of gofrontend is compiled with _GNU_SOURCE, this file ++ exists to selectively undefine it and provides an alias to the ++ XSI-compliant version of strerror_r(3). */ ++ ++#ifdef __linux__ ++ ++/* Force selection of XSI-compliant strerror_r by glibc. */ ++#undef XOPEN_SOURCE ++#define XOPEN_SOURCE 600 ++#undef _POSIX_C_SOURCE ++#define _POSIX_C_SOURCE 200112L ++#undef _GNU_SOURCE ++ ++#endif /* __linux__ */ ++ ++#include <string.h> ++ ++#ifndef HAVE_STRERROR_R ++// Provided by go-nosys.c if not provided by libc itself. ++extern int strerror_r (int, char *, size_t); ++#endif ++ ++int ++go_strerror (int errnum, char *buf, size_t buflen) ++{ ++ return strerror_r (errnum, buf, buflen); ++} diff --git a/gnu/gcc/patches/0037-libgo-Recognize-off64_t-and-loff_t-definitions-of-mu.patch b/gnu/gcc/patches/0037-libgo-Recognize-off64_t-and-loff_t-definitions-of-mu.patch new file mode 100644 index 0000000000..e0423d47b0 --- /dev/null +++ b/gnu/gcc/patches/0037-libgo-Recognize-off64_t-and-loff_t-definitions-of-mu.patch @@ -0,0 +1,199 @@ +From 3b9243b891cc06373639a23ed5717b0d1c2d8ea6 Mon Sep 17 00:00:00 2001 +From: Ian Lance Taylor <iant@golang.org> +Date: Tue, 14 Jun 2022 06:13:43 -0700 +Subject: [PATCH] libgo: permit loff_t and off_t to be macros +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +They are macros in musl libc, rather than typedefs, and -fgo-dump-spec +doesn't handle that case. + +Based on patch by Sören Tempel. + +Change-Id: Ic9a608fd964a6f78e754aa8e3100aff06ab3dade +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/412075 +Reviewed-by: Ian Lance Taylor <iant@google.com> +Reviewed-by: Cherry Mui <cherryyz@google.com> + +libgo: #include <sys/types.h> when checking for loff_t + +Fixes https://gcc.gnu.org/PR106033 +Fixes golang/go#53469 + +Change-Id: I060021b7bb9334949b567442448abb6822fd6d35 +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/413214 +Reviewed-by: Cherry Mui <cherryyz@google.com> +Reviewed-by: Than McIntosh <thanm@google.com> +--- + libgo/config.h.in | 3 +++ + libgo/configure | 12 ++++++++++-- + libgo/configure.ac | 11 +++++++++-- + libgo/go/syscall/libcall_linux.go | 17 +++++++++-------- + libgo/mksysinfo.sh | 6 +----- + libgo/sysinfo.c | 15 ++++++++++++++- + 6 files changed, 46 insertions(+), 18 deletions(-) + +diff --git a/libgo/config.h.in b/libgo/config.h.in +index 25b8ab8f9ee..2c3c7469675 100644 +--- a/libgo/config.h.in ++++ b/libgo/config.h.in +@@ -70,6 +70,9 @@ + /* Define to 1 if you have the `fchownat' function. */ + #undef HAVE_FCHOWNAT + ++/* Define to 1 if you have the <fcntl.h> header file. */ ++#undef HAVE_FCNTL_H ++ + /* Define to 1 if you have the `futimesat' function. */ + #undef HAVE_FUTIMESAT + +diff --git a/libgo/configure b/libgo/configure +index ffe17c9be55..61a49947eb9 100755 +--- a/libgo/configure ++++ b/libgo/configure +@@ -15249,7 +15249,7 @@ $as_echo "#define HAVE_GETIPINFO 1" >>confdefs.h + fi + + +-for ac_header in port.h sched.h semaphore.h sys/file.h sys/mman.h syscall.h sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h sys/sysctl.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h net/if.h net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h linux/fs.h linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h netinet/ip_mroute.h netinet/if_ether.h lwp.h ++for ac_header in fcntl.h port.h sched.h semaphore.h sys/file.h sys/mman.h syscall.h sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h sys/sysctl.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h net/if.h net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h linux/fs.h linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h netinet/ip_mroute.h netinet/if_ether.h lwp.h + do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` + ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" +@@ -15546,7 +15546,14 @@ _ACEOF + + fi + +-ac_fn_c_check_type "$LINENO" "loff_t" "ac_cv_type_loff_t" "$ac_includes_default" ++ ++CFLAGS_hold="$CFLAGS" ++CFLAGS="$OSCFLAGS $CFLAGS" ++ac_fn_c_check_type "$LINENO" "loff_t" "ac_cv_type_loff_t" " ++#include <sys/types.h> ++#include <fcntl.h> ++ ++" + if test "x$ac_cv_type_loff_t" = xyes; then : + + cat >>confdefs.h <<_ACEOF +@@ -15556,6 +15563,7 @@ _ACEOF + + fi + ++CFLAGS="$CFLAGS_hold" + + LIBS_hold="$LIBS" + LIBS="$LIBS -lm" +diff --git a/libgo/configure.ac b/libgo/configure.ac +index 7e2b98ba67c..274fcfc35c7 100644 +--- a/libgo/configure.ac ++++ b/libgo/configure.ac +@@ -579,7 +579,7 @@ AC_C_BIGENDIAN + + GCC_CHECK_UNWIND_GETIPINFO + +-AC_CHECK_HEADERS(port.h sched.h semaphore.h sys/file.h sys/mman.h syscall.h sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h sys/sysctl.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h net/if.h net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h linux/fs.h linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h netinet/ip_mroute.h netinet/if_ether.h lwp.h) ++AC_CHECK_HEADERS(fcntl.h port.h sched.h semaphore.h sys/file.h sys/mman.h syscall.h sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h sys/sysctl.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h net/if.h net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h linux/fs.h linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h netinet/ip_mroute.h netinet/if_ether.h lwp.h) + + AC_CHECK_HEADERS([netinet/icmp6.h], [], [], + [#include <netinet/in.h> +@@ -601,7 +601,14 @@ 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="$OSCFLAGS $CFLAGS" ++AC_CHECK_TYPES([loff_t], [], [], [[ ++#include <sys/types.h> ++#include <fcntl.h> ++]]) ++CFLAGS="$CFLAGS_hold" + + LIBS_hold="$LIBS" + LIBS="$LIBS -lm" +diff --git a/libgo/go/syscall/libcall_linux.go b/libgo/go/syscall/libcall_linux.go +index 96974bd3269..65eb1a745f7 100644 +--- a/libgo/go/syscall/libcall_linux.go ++++ b/libgo/go/syscall/libcall_linux.go +@@ -209,19 +209,20 @@ func Gettid() (tid int) { + //sys Setxattr(path string, attr string, data []byte, flags int) (err error) + //setxattr(path *byte, name *byte, value *byte, size Size_t, flags _C_int) _C_int + +-//sys splice(rfd int, roff *_loff_t, wfd int, woff *_loff_t, len int, flags int) (n int64, err error) +-//splice(rfd _C_int, roff *_loff_t, wfd _C_int, woff *_loff_t, len Size_t, flags _C_uint) Ssize_t ++//sys splice(rfd int, roff *_libgo_loff_t_type, wfd int, woff *_libgo_loff_t_type, len int, flags int) (n int64, err error) ++//splice(rfd _C_int, roff *_libgo_loff_t_type, wfd _C_int, woff *_libgo_loff_t_type, len Size_t, flags _C_uint) Ssize_t ++ + func Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error) { +- var lroff _loff_t +- var plroff *_loff_t ++ var lroff _libgo_loff_t_type ++ var plroff *_libgo_loff_t_type + if roff != nil { +- lroff = _loff_t(*roff) ++ lroff = _libgo_loff_t_type(*roff) + plroff = &lroff + } +- var lwoff _loff_t +- var plwoff *_loff_t ++ var lwoff _libgo_loff_t_type ++ var plwoff *_libgo_loff_t_type + if woff != nil { +- lwoff = _loff_t(*woff) ++ lwoff = _libgo_loff_t_type(*woff) + plwoff = &lwoff + } + n, err = splice(rfd, plroff, wfd, plwoff, len, flags) +diff --git a/libgo/mksysinfo.sh b/libgo/mksysinfo.sh +index 0c52ea5d71a..5aa309155c3 100755 +--- a/libgo/mksysinfo.sh ++++ b/libgo/mksysinfo.sh +@@ -403,11 +403,7 @@ fi + # Some basic types. + echo 'type Size_t _size_t' >> ${OUT} + echo "type Ssize_t _ssize_t" >> ${OUT} +-if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then +- echo "type Offset_t _off64_t" >> ${OUT} +-else +- echo "type Offset_t _off_t" >> ${OUT} +-fi ++echo "type Offset_t _libgo_off_t_type" >> ${OUT} + echo "type Mode_t _mode_t" >> ${OUT} + echo "type Pid_t _pid_t" >> ${OUT} + echo "type Uid_t _uid_t" >> ${OUT} +diff --git a/libgo/sysinfo.c b/libgo/sysinfo.c +index 336a5983750..fc0210992fa 100644 +--- a/libgo/sysinfo.c ++++ b/libgo/sysinfo.c +@@ -354,6 +354,18 @@ enum { + }; + #endif + ++#if defined(HAVE_LOFF_T) ++// loff_t can be defined as a macro; for -fgo-dump-spec make sure we ++// see a typedef. ++typedef loff_t libgo_loff_t_type; ++#endif ++ ++#if defined(HAVE_OFF64_T) ++typedef off64_t libgo_off_t_type; ++#else ++typedef off_t libgo_off_t_type; ++#endif ++ + // The following section introduces explicit references to types and + // constants of interest to support bootstrapping libgo using a + // compiler that doesn't support -fdump-go-spec (e.g., clang), via +@@ -534,7 +546,8 @@ SREF(timex); + // From sys/types.h + TREF(pid_t); + TREF(off_t); +-TREF(loff_t); ++TREF(libgo_loff_t_type); ++TREF(libgo_off_t_type); + TREF(size_t); + TREF(ssize_t); + TREF(mode_t); diff --git a/gnu/gcc/patches/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch b/gnu/gcc/patches/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch new file mode 100644 index 0000000000..94bb9fc916 --- /dev/null +++ b/gnu/gcc/patches/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch @@ -0,0 +1,43 @@ +From 5e658f4659c551330ea68f5667e4f951b218f32d Mon Sep 17 00:00:00 2001 +From: Ian Lance Taylor <iant@golang.org> +Date: Wed, 26 Oct 2022 17:23:42 -0700 +Subject: [PATCH] runtime: use _libgo_off_t_type when calling C mmap +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The last argument to the C mmap function is type off_t, not uintptr. +On some 32-bit systems, off_t is larger than uintptr. + +Based on patch by Sören Tempel. + +Change-Id: Ib6f9d5bcd4734f99a72889e2282b97ec3c8fbd34 +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/445735 +Reviewed-by: Cherry Mui <cherryyz@google.com> +Reviewed-by: Than McIntosh <thanm@google.com> +--- + libgo/go/runtime/mem_gccgo.go | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/libgo/go/runtime/mem_gccgo.go b/libgo/go/runtime/mem_gccgo.go +index fa3389d8..1e84f4f5 100644 +--- a/libgo/go/runtime/mem_gccgo.go ++++ b/libgo/go/runtime/mem_gccgo.go +@@ -15,7 +15,7 @@ import ( + //go:linkname sysFree + + //extern mmap +-func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) unsafe.Pointer ++func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off _libgo_off_t_type) unsafe.Pointer + + //extern munmap + func munmap(addr unsafe.Pointer, length uintptr) int32 +@@ -38,7 +38,7 @@ func init() { + } + + func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) (unsafe.Pointer, int) { +- p := sysMmap(addr, n, prot, flags, fd, off) ++ p := sysMmap(addr, n, prot, flags, fd, _libgo_off_t_type(off)) + if uintptr(p) == _MAP_FAILED { + return nil, errno() + } diff --git a/gnu/gcc/patches/0041-go-gospec-forcibly-disable-fsplit-stack-support.patch b/gnu/gcc/patches/0041-go-gospec-forcibly-disable-fsplit-stack-support.patch new file mode 100644 index 0000000000..5cebe745bf --- /dev/null +++ b/gnu/gcc/patches/0041-go-gospec-forcibly-disable-fsplit-stack-support.patch @@ -0,0 +1,71 @@ +From c86b726c048eddc1be320c0bf64a897658bee13d Mon Sep 17 00:00:00 2001 +From: Uros Bizjak <ubizjak@gmail.com> +Date: Wed, 18 May 2022 20:03:26 +0200 +Subject: [PATCH] x86: Fix -fsplit-stack feature detection via + TARGET_CAN_SPLIT_STACK +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Since commit c163647ffbc9a20c8feb6e079dbecccfe016c82e -fsplit-stack +is only supported on glibc targets. However, this original commit +required some fixups. As part of the fixup, the changes to the +gnu-user-common.h and gnu.h were partially reverted in commit +60953a23d57b13a672f751bec0c6eefc059eb1ab thus causing TARGET_CAN_SPLIT_STACK +to be defined for non-glibc targets even though -fsplit-stack is +actually not supported and attempting to use it causes a runtime error. + +This causes gcc internal code, such as ./gcc/go/gospec.c to not +correctly detect that -fsplit-stack is not supported and thus causes +gccgo to fail compilation on non-glibc targets. + +This commit ensures that TARGET_CAN_SPLIT_STACK is only set if the +default libc is glibc. It is presently unclear to me if there is a +better way to detect glibc at pre-processor time. + +The proposed changes have been tested on x86 and x86_64 Alpine Linux +(which uses musl libc) and fix compilation of gccgo for this target. + +Signed-off-by: Sören Tempel <soeren@soeren-tempel.net> + +gcc/ChangeLog: + + * config/i386/gnu-user-common.h (defined): Only define + TARGET_CAN_SPLIT_STACK for glibc targets. + * config/i386/gnu.h (defined): Ditto. +--- + gcc/config/i386/gnu-user-common.h | 5 +++-- + gcc/config/i386/gnu.h | 5 +++-- + 2 files changed, 6 insertions(+), 4 deletions(-) + +diff --git a/gcc/config/i386/gnu-user-common.h b/gcc/config/i386/gnu-user-common.h +index 23b54c5be52..cab9be2bfb7 100644 +--- a/gcc/config/i386/gnu-user-common.h ++++ b/gcc/config/i386/gnu-user-common.h +@@ -66,7 +66,8 @@ along with GCC; see the file COPYING3. If not see + #define STACK_CHECK_STATIC_BUILTIN 1 + + /* We only build the -fsplit-stack support in libgcc if the +- assembler has full support for the CFI directives. */ +-#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE ++ assembler has full support for the CFI directives. Also ++ we only support -fsplit-stack on glibc targets. */ ++#if (DEFAULT_LIBC == LIBC_GLIBC) && HAVE_GAS_CFI_PERSONALITY_DIRECTIVE + #define TARGET_CAN_SPLIT_STACK + #endif +diff --git a/gcc/config/i386/gnu.h b/gcc/config/i386/gnu.h +index 401e60c9a02..fb8d69a97d8 100644 +--- a/gcc/config/i386/gnu.h ++++ b/gcc/config/i386/gnu.h +@@ -41,8 +41,9 @@ along with GCC. If not, see <http://www.gnu.org/licenses/>. + #define TARGET_THREAD_SSP_OFFSET 0x14 + + /* We only build the -fsplit-stack support in libgcc if the +- assembler has full support for the CFI directives. */ +-#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE ++ assembler has full support for the CFI directives. Also ++ we only support -fsplit-stack on glibc targets. */ ++#if (DEFAULT_LIBC == LIBC_GLIBC) && HAVE_GAS_CFI_PERSONALITY_DIRECTIVE + #define TARGET_CAN_SPLIT_STACK + #endif + /* We steal the last transactional memory word. */ diff --git a/gnu/gcc/patches/0042-gcc-go-fix-build-error-with-SYS_SECCOMP.patch b/gnu/gcc/patches/0042-gcc-go-fix-build-error-with-SYS_SECCOMP.patch new file mode 100644 index 0000000000..db38df3b01 --- /dev/null +++ b/gnu/gcc/patches/0042-gcc-go-fix-build-error-with-SYS_SECCOMP.patch @@ -0,0 +1,41 @@ +From 548720bca6bff21ebc9aba22249d9ce45bbd90c7 Mon Sep 17 00:00:00 2001 +From: Ian Lance Taylor <iant@golang.org> +Date: Wed, 29 Jun 2022 15:32:04 -0700 +Subject: [PATCH] libgo: handle stat st_atim32 field and SYS_SECCOMP +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Patches for musl support, from Sören Tempel. + +Fixes https://gcc.gnu.org/PR105225 + +Change-Id: If396877d4a4c7d27962226d7a6e3bb91b1344413 +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/415294 +Reviewed-by: Than McIntosh <thanm@google.com> +Reviewed-by: Ian Lance Taylor <iant@google.com> +--- + libgo/mksysinfo.sh | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/libgo/mksysinfo.sh b/libgo/mksysinfo.sh +index 5aa30915..ea1fa17d 100755 +--- a/libgo/mksysinfo.sh ++++ b/libgo/mksysinfo.sh +@@ -127,6 +127,7 @@ fi + + # The syscall numbers. We force the names to upper case. + grep '^const _SYS_' gen-sysinfo.go | \ ++ grep -v '^const _SYS_SECCOMP = ' | \ + sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \ + while read sys; do + sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ` +@@ -506,7 +507,7 @@ fi + + # For historical reasons Go uses the suffix "timespec" instead of "tim" for + # stat_t's time fields on NetBSD. +-st_times='-e s/st_atim/Atim/ -e s/st_mtim/Mtim/ -e s/st_ctim/Ctim/' ++st_times='-e s/st_atim/Atim/g -e s/st_mtim/Mtim/g -e s/st_ctim/Ctim/g' + if test "${GOOS}" = "netbsd"; then + st_times='-e s/st_atim/Atimespec/ -e s/st_mtim/Mtimespec/ -e s/st_ctim/Ctimespec/' + fi diff --git a/gnu/gcc/patches/0049-libgo-adjust-name-of-union-in-sigevent-struct.patch b/gnu/gcc/patches/0049-libgo-adjust-name-of-union-in-sigevent-struct.patch new file mode 100644 index 0000000000..0f949be3af --- /dev/null +++ b/gnu/gcc/patches/0049-libgo-adjust-name-of-union-in-sigevent-struct.patch @@ -0,0 +1,108 @@ +From 8f1a91aeff400d572857895b7f5e863ec5a4d93e Mon Sep 17 00:00:00 2001 +From: Ian Lance Taylor <iant@golang.org> +Date: Mon, 26 Sep 2022 15:03:53 -0400 +Subject: [PATCH] runtime: portable access to sigev_notify_thread_id +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Previously, libgo relied on the _sigev_un implementation-specific +field in struct sigevent, which is only available on glibc. +This patch uses the sigev_notify_thread_id macro instead which is +mandated by timer_create(2). In theory, this should work with any libc +implementation for Linux. Unfortunately, there is an open glibc bug +as glibc does not define this macro. For this reason, a glibc-specific +workaround is required. Other libcs (such as musl) define the macro +and don't require the workaround. + +See https://sourceware.org/bugzilla/show_bug.cgi?id=27417 + +This makes libgo compatible with musl libc. + +Based on patch by Sören Tempel. + +Change-Id: I0924a53d5212730ebc395ecf9199f85967be8cc6 +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/434755 +Reviewed-by: Cherry Mui <cherryyz@google.com> +Reviewed-by: Than McIntosh <thanm@google.com> +--- + libgo/go/runtime/os_linux.go | 12 +++++++++++- + libgo/runtime/go-signal.c | 18 ++++++++++++++++++ + 2 files changed, 29 insertions(+), 1 deletion(-) + +diff --git a/libgo/go/runtime/os_linux.go b/libgo/go/runtime/os_linux.go +index 96fb1788..2b2d827c 100644 +--- a/libgo/go/runtime/os_linux.go ++++ b/libgo/go/runtime/os_linux.go +@@ -22,6 +22,12 @@ type mOS struct { + profileTimerValid uint32 + } + ++// setSigeventTID is written in C to set the sigev_notify_thread_id ++// field of a sigevent struct. ++// ++//go:noescape ++func setSigeventTID(*_sigevent, int32) ++ + func getProcID() uint64 { + return uint64(gettid()) + } +@@ -52,9 +58,12 @@ const ( + ) + + // Atomically, ++// + // if(*addr == val) sleep ++// + // Might be woken up spuriously; that's allowed. + // Don't sleep longer than ns; ns < 0 means forever. ++// + //go:nosplit + func futexsleep(addr *uint32, val uint32, ns int64) { + // Some Linux kernels have a bug where futex of +@@ -73,6 +82,7 @@ func futexsleep(addr *uint32, val uint32, ns int64) { + } + + // If any procs are sleeping on addr, wake up at most cnt. ++// + //go:nosplit + func futexwakeup(addr *uint32, cnt uint32) { + ret := futex(unsafe.Pointer(addr), _FUTEX_WAKE_PRIVATE, cnt, nil, nil, 0) +@@ -365,7 +375,7 @@ func setThreadCPUProfiler(hz int32) { + var sevp _sigevent + sevp.sigev_notify = _SIGEV_THREAD_ID + sevp.sigev_signo = _SIGPROF +- *((*int32)(unsafe.Pointer(&sevp._sigev_un))) = int32(mp.procid) ++ setSigeventTID(&sevp, int32(mp.procid)) + ret := timer_create(_CLOCK_THREAD_CPUTIME_ID, &sevp, &timerid) + if ret != 0 { + // If we cannot create a timer for this M, leave profileTimerValid false +diff --git a/libgo/runtime/go-signal.c b/libgo/runtime/go-signal.c +index 528d9b6d..aa1b6305 100644 +--- a/libgo/runtime/go-signal.c ++++ b/libgo/runtime/go-signal.c +@@ -183,6 +183,24 @@ setSigactionHandler(struct sigaction* sa, uintptr handler) + sa->sa_sigaction = (void*)(handler); + } + ++#ifdef __linux__ ++ ++// Workaround for https://sourceware.org/bugzilla/show_bug.cgi?id=27417 ++#ifndef sigev_notify_thread_id ++ #define sigev_notify_thread_id _sigev_un._tid ++#endif ++ ++void setSigeventTID(struct sigevent*, int32_t) ++ __asm__ (GOSYM_PREFIX "runtime.setSigeventTID"); ++ ++void ++setSigeventTID(struct sigevent *sev, int32_t v) ++{ ++ sev->sigev_notify_thread_id = v; ++} ++ ++#endif // defined(__linux__) ++ + // C code to fetch values from the siginfo_t and ucontext_t pointers + // passed to a signal handler. + diff --git a/gnu/gcc/patches/0051-libgo-Explicitly-define-SYS_timer_settime-for-32-bit.patch b/gnu/gcc/patches/0051-libgo-Explicitly-define-SYS_timer_settime-for-32-bit.patch new file mode 100644 index 0000000000..f2f019119e --- /dev/null +++ b/gnu/gcc/patches/0051-libgo-Explicitly-define-SYS_timer_settime-for-32-bit.patch @@ -0,0 +1,36 @@ +From d53e8a0e94e34dc609e34dd5e404debda2640cfb Mon Sep 17 00:00:00 2001 +From: Ian Lance Taylor <iant@golang.org> +Date: Sat, 30 Jul 2022 07:29:28 -0700 +Subject: [PATCH] libgo: use SYS_timer_settime32 +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Musl defines SYS_timer_settime32, not SYS_timer_settime, on 32-bit systems. + +Based on patch by Sören Tempel. + +Change-Id: I1f3485028d132ceca1aba595325af24b4d72b894 +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/420222 +Reviewed-by: Ian Lance Taylor <iant@google.com> +Reviewed-by: Cherry Mui <cherryyz@google.com> +--- + libgo/sysinfo.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/libgo/sysinfo.c b/libgo/sysinfo.c +index fc021099..180f5c31 100644 +--- a/libgo/sysinfo.c ++++ b/libgo/sysinfo.c +@@ -354,6 +354,11 @@ enum { + }; + #endif + ++#if !defined(SYS_timer_settime) && defined(SYS_timer_settime32) ++// musl defines SYS_timer_settim32 on 32-bit systems. ++#define SYS_timer_settime SYS_timer_settime32 ++#endif ++ + #if defined(HAVE_LOFF_T) + // loff_t can be defined as a macro; for -fgo-dump-spec make sure we + // see a typedef. |