From fc5d3bdd608d8134312f497a1aa49a7165a8ecab Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Tue, 6 Dec 2022 09:04:17 +0100 Subject: [PATCH] cross/gcc-*: upgrade to 12.2.1_git20220924-r5 --- ...ric-errstr.go-implementation-on-musl.patch | 219 +++++++++++++++--- ...t64-type-as-offset-argument-for-mmap.patch | 52 +++-- cross/gcc-aarch64/APKBUILD | 6 +- ...ric-errstr.go-implementation-on-musl.patch | 219 +++++++++++++++--- ...t64-type-as-offset-argument-for-mmap.patch | 52 +++-- cross/gcc-armhf/APKBUILD | 6 +- ...ric-errstr.go-implementation-on-musl.patch | 219 +++++++++++++++--- ...t64-type-as-offset-argument-for-mmap.patch | 52 +++-- cross/gcc-armv7/APKBUILD | 6 +- ...ric-errstr.go-implementation-on-musl.patch | 219 +++++++++++++++--- ...t64-type-as-offset-argument-for-mmap.patch | 52 +++-- cross/gcc-riscv64/APKBUILD | 6 +- 12 files changed, 912 insertions(+), 196 deletions(-) diff --git a/cross/gcc-aarch64/0034-Use-generic-errstr.go-implementation-on-musl.patch b/cross/gcc-aarch64/0034-Use-generic-errstr.go-implementation-on-musl.patch index 85d75df2c..a5ad79774 100644 --- a/cross/gcc-aarch64/0034-Use-generic-errstr.go-implementation-on-musl.patch +++ b/cross/gcc-aarch64/0034-Use-generic-errstr.go-implementation-on-musl.patch @@ -1,45 +1,204 @@ -From 5093aa99f9cdded2e1ddf67b7139da6fac36b0a6 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?S=C3=B6ren=20Tempel?= -Date: Mon, 19 Apr 2021 07:21:41 +0200 -Subject: [PATCH] Use generic errstr.go implementation on musl +From b3840bdcc0eee2a4d099a9af52199944ade7acb9 Mon Sep 17 00:00:00 2001 +From: Ian Lance Taylor +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 -glibc provides two version of strerror_r() depending on a feature test -macro. The first is the XSI-compliant version which returns an int, the -second is GNU-specific and returns a char pointer. +This does the right thing for either glibc or musl on GNU/Linux. -Similarity, gcc's libgo provides two implementations of Errstr() both of -which use strerror_r(). On Linux, it is assumed that the GNU-specific -strerror_r version is used. However, musl only provides the -XSI-compliant version of strerror_r. This patch enables the generic -Errstr() implementation which also uses the XSI-compliant version of -strerror_r. +Based on patch by Sören Tempel. + +Change-Id: If2969e131f0fae456d58b35d839d8abe191fcc59 +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/454176 +Reviewed-by: Cherry Mui +Reviewed-by: Ian Lance Taylor +TryBot-Bypass: Ian Lance Taylor --- - libgo/go/syscall/errstr.go | 1 - - libgo/go/syscall/errstr_glibc.go | 2 +- - 2 files changed, 1 insertion(+), 2 deletions(-) + 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 6c2441d364d..8f7c5538163 100644 +index 6c2441d3..9f688e2a 100644 --- a/libgo/go/syscall/errstr.go +++ b/libgo/go/syscall/errstr.go -@@ -5,7 +5,6 @@ +@@ -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 !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 -index 5b19e6f202d..8dc60172186 100644 +deleted file mode 100644 +index 5b19e6f2..00000000 --- a/libgo/go/syscall/errstr_glibc.go -+++ b/libgo/go/syscall/errstr_glibc.go -@@ -7,7 +7,7 @@ - // 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. - ++++ /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 -+// +build hurd !linux - - package syscall - +- +-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 ++ ++#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/cross/gcc-aarch64/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch b/cross/gcc-aarch64/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch index 4867ab090..5c8599164 100644 --- a/cross/gcc-aarch64/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch +++ b/cross/gcc-aarch64/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch @@ -1,22 +1,26 @@ -From 4b6240d5301ce04b8bbc3e2152915cbc7da80584 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?S=C3=B6ren=20Tempel?= -Date: Wed, 28 Sep 2022 17:30:14 +0200 -Subject: [PATCH] libgo: use _off_t for mmap offset argument +From 5e658f4659c551330ea68f5667e4f951b218f32d Mon Sep 17 00:00:00 2001 +From: Ian Lance Taylor +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 -On glibc-based systems, off_t is a 32-bit type on 32-bit systems and a -64-bit type on 64-bit systems by default. However, on systems using musl -libc off_t is unconditionally a 64-bit type. As such, it is insufficient -to use a uintptr type for the mmap offset parameter. +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. -Presently, the (incorrect) mmap declaration causes a libgo run-time -failure on 32-bit musl systems (fatal error: runtime: cannot allocate -memory). This commit fixes this run-time error. +Based on patch by Sören Tempel. + +Change-Id: Ib6f9d5bcd4734f99a72889e2282b97ec3c8fbd34 +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/445735 +Reviewed-by: Cherry Mui +Reviewed-by: Than McIntosh --- - libgo/go/runtime/mem_gccgo.go | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) + libgo/go/runtime/mem_gccgo.go | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libgo/go/runtime/mem_gccgo.go b/libgo/go/runtime/mem_gccgo.go -index fa3389d8..07bf325a 100644 +index fa3389d8..1e84f4f5 100644 --- a/libgo/go/runtime/mem_gccgo.go +++ b/libgo/go/runtime/mem_gccgo.go @@ -15,7 +15,7 @@ import ( @@ -24,7 +28,7 @@ index fa3389d8..07bf325a 100644 //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 _off_t) 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 @@ -33,7 +37,23 @@ index fa3389d8..07bf325a 100644 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, _off_t(off)) ++ p := sysMmap(addr, n, prot, flags, fd, _libgo_off_t_type(off)) if uintptr(p) == _MAP_FAILED { return nil, errno() } +@@ -47,6 +47,7 @@ func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) (u + + // Don't split the stack as this method may be invoked without a valid G, which + // prevents us from allocating more stack. ++// + //go:nosplit + func sysAlloc(n uintptr, sysStat *sysMemStat) unsafe.Pointer { + p, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, mmapFD, 0) +@@ -165,6 +166,7 @@ func sysHugePage(v unsafe.Pointer, n uintptr) { + + // Don't split the stack as this function may be invoked without a valid G, + // which prevents us from allocating more stack. ++// + //go:nosplit + func sysFree(v unsafe.Pointer, n uintptr, sysStat *sysMemStat) { + sysStat.add(-int64(n)) diff --git a/cross/gcc-aarch64/APKBUILD b/cross/gcc-aarch64/APKBUILD index ec118bc0d..ecef93fc1 100644 --- a/cross/gcc-aarch64/APKBUILD +++ b/cross/gcc-aarch64/APKBUILD @@ -32,7 +32,7 @@ pkgver=${_pkgbase}_git${_pkgsnap} [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-aarch64 -pkgrel=4 +pkgrel=5 pkgdesc="Stage2 cross-compiler for aarch64" url="https://gcc.gnu.org" arch="x86_64" @@ -795,11 +795,11 @@ b40d7e4712c035674c993bbb55475290ec14523b3f0fd05493514bac4e9adaa6641faf815fc40ffc f060687adcd5297124e4000f1ba1e3fd5d7d124da04d948cbd0d4a6c69a90a2b29a4a0dbbe13a83ab6950724f434de012b681bdbcdf53c0100b40fe3d00f2f2f 0028-ada-libgnarl-compatibility-for-musl.patch 5160bae68e20a1966c1f6d655ee98af759e9b9ee842718ae6007d467b418e1cf3b307528a0841477b5259671ce868521b06c0f2e947b7b8f3a398c53dd978252 0029-ada-musl-support-fixes.patch 3c04b26554a78096296ca9542c77a91219bd26044dd2cb2006db4c1944889a97c215900b3828ba7e8c675162406db543605a815bdfbd915bf810663b1b253bdd 0033-gcc-go-link-to-libucontext.patch -699dc3641099da6136dd3689f06c6553c03b3a85acf83a3fce1beb5425065b3e378535ca9e9100a120fdbafc34871d61c063fd5328a49cd87a15a989ed51706d 0034-Use-generic-errstr.go-implementation-on-musl.patch +141c0428f988cbd102000d4db8d4150485f6da5c064469493ea378cd579bed99330658f41fe106c0d07d1c1aa436ec3f864403ed1ba79f791a1d727b42d46910 0034-Use-generic-errstr.go-implementation-on-musl.patch d9ba710f770e053c8f212e821817c188091a829658050b9ab5906388553ec60fec37943ea43c270e92a9014902949f3c98fc4639032d92b8145b375bb29e193e 0035-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch ab90d8fdd977d6cd3da096a1c76d77be3e89a020b2127247771711a32eb608cceed21834ef488ab4b69bb0f408b098fdfb61630819e3d1a1e57d5af67800ee74 0036-configure-fix-detection-of-atomic-builtins-in-libato.patch 8bc6823f0b3c66f7b73d7ddb64ffa6930463285c2e9a14a2bc1882bcc4271144eaa1107d713294699caf9481648163cbf43921a2b8e4ac0d55c78a804bae8a3d 0037-libgo-Recognize-off64_t-and-loff_t-definitions-of-mu.patch -e9699f4721778869eb3a8fef2c679208ef5b98584892f30b0e1cb5dc1669f8158198d7792659b1b56c381baf62247d21990dcced9178547affd5d6bfb2d12548 0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch +f0744c01859e67deed404c97e1870b2876935fdc467e51980373744936574c314d5d21134734c5d515e7f3cd3483ef98045b9bbcd81c568c6038fac96ffb5fa0 0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch d6dc1bfb881a313d167aaa5658790b0f55eea4336c408cfc6613dd5783440dafd0d37c43031a5f3e69be40f632e38371cd4fb6e5f0494ac4ea4d7d5025d2ae02 0041-go-gospec-forcibly-disable-fsplit-stack-support.patch 684c6a6d52512b973429b6e709966439ac1e174f9e79a33d4a638b452245b457b34752b4b4034ba983f6a712f86522e7adf715bab00a6603f64a12139c5b1e39 0042-gcc-go-fix-build-error-with-SYS_SECCOMP.patch 25014dfa99d96ee70ce0ad22e9f7974f0a51cc50b3b9c2db49df50774c8cd29e497ceed120486bee50be83bfb07f2009ed310eb9b0543f2795bd7359b87eadd2 0043-libstdc-do-not-throw-exceptions-for-non-C-locales-on.patch diff --git a/cross/gcc-armhf/0034-Use-generic-errstr.go-implementation-on-musl.patch b/cross/gcc-armhf/0034-Use-generic-errstr.go-implementation-on-musl.patch index 85d75df2c..a5ad79774 100644 --- a/cross/gcc-armhf/0034-Use-generic-errstr.go-implementation-on-musl.patch +++ b/cross/gcc-armhf/0034-Use-generic-errstr.go-implementation-on-musl.patch @@ -1,45 +1,204 @@ -From 5093aa99f9cdded2e1ddf67b7139da6fac36b0a6 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?S=C3=B6ren=20Tempel?= -Date: Mon, 19 Apr 2021 07:21:41 +0200 -Subject: [PATCH] Use generic errstr.go implementation on musl +From b3840bdcc0eee2a4d099a9af52199944ade7acb9 Mon Sep 17 00:00:00 2001 +From: Ian Lance Taylor +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 -glibc provides two version of strerror_r() depending on a feature test -macro. The first is the XSI-compliant version which returns an int, the -second is GNU-specific and returns a char pointer. +This does the right thing for either glibc or musl on GNU/Linux. -Similarity, gcc's libgo provides two implementations of Errstr() both of -which use strerror_r(). On Linux, it is assumed that the GNU-specific -strerror_r version is used. However, musl only provides the -XSI-compliant version of strerror_r. This patch enables the generic -Errstr() implementation which also uses the XSI-compliant version of -strerror_r. +Based on patch by Sören Tempel. + +Change-Id: If2969e131f0fae456d58b35d839d8abe191fcc59 +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/454176 +Reviewed-by: Cherry Mui +Reviewed-by: Ian Lance Taylor +TryBot-Bypass: Ian Lance Taylor --- - libgo/go/syscall/errstr.go | 1 - - libgo/go/syscall/errstr_glibc.go | 2 +- - 2 files changed, 1 insertion(+), 2 deletions(-) + 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 6c2441d364d..8f7c5538163 100644 +index 6c2441d3..9f688e2a 100644 --- a/libgo/go/syscall/errstr.go +++ b/libgo/go/syscall/errstr.go -@@ -5,7 +5,6 @@ +@@ -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 !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 -index 5b19e6f202d..8dc60172186 100644 +deleted file mode 100644 +index 5b19e6f2..00000000 --- a/libgo/go/syscall/errstr_glibc.go -+++ b/libgo/go/syscall/errstr_glibc.go -@@ -7,7 +7,7 @@ - // 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. - ++++ /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 -+// +build hurd !linux - - package syscall - +- +-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 ++ ++#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/cross/gcc-armhf/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch b/cross/gcc-armhf/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch index 4867ab090..5c8599164 100644 --- a/cross/gcc-armhf/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch +++ b/cross/gcc-armhf/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch @@ -1,22 +1,26 @@ -From 4b6240d5301ce04b8bbc3e2152915cbc7da80584 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?S=C3=B6ren=20Tempel?= -Date: Wed, 28 Sep 2022 17:30:14 +0200 -Subject: [PATCH] libgo: use _off_t for mmap offset argument +From 5e658f4659c551330ea68f5667e4f951b218f32d Mon Sep 17 00:00:00 2001 +From: Ian Lance Taylor +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 -On glibc-based systems, off_t is a 32-bit type on 32-bit systems and a -64-bit type on 64-bit systems by default. However, on systems using musl -libc off_t is unconditionally a 64-bit type. As such, it is insufficient -to use a uintptr type for the mmap offset parameter. +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. -Presently, the (incorrect) mmap declaration causes a libgo run-time -failure on 32-bit musl systems (fatal error: runtime: cannot allocate -memory). This commit fixes this run-time error. +Based on patch by Sören Tempel. + +Change-Id: Ib6f9d5bcd4734f99a72889e2282b97ec3c8fbd34 +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/445735 +Reviewed-by: Cherry Mui +Reviewed-by: Than McIntosh --- - libgo/go/runtime/mem_gccgo.go | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) + libgo/go/runtime/mem_gccgo.go | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libgo/go/runtime/mem_gccgo.go b/libgo/go/runtime/mem_gccgo.go -index fa3389d8..07bf325a 100644 +index fa3389d8..1e84f4f5 100644 --- a/libgo/go/runtime/mem_gccgo.go +++ b/libgo/go/runtime/mem_gccgo.go @@ -15,7 +15,7 @@ import ( @@ -24,7 +28,7 @@ index fa3389d8..07bf325a 100644 //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 _off_t) 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 @@ -33,7 +37,23 @@ index fa3389d8..07bf325a 100644 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, _off_t(off)) ++ p := sysMmap(addr, n, prot, flags, fd, _libgo_off_t_type(off)) if uintptr(p) == _MAP_FAILED { return nil, errno() } +@@ -47,6 +47,7 @@ func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) (u + + // Don't split the stack as this method may be invoked without a valid G, which + // prevents us from allocating more stack. ++// + //go:nosplit + func sysAlloc(n uintptr, sysStat *sysMemStat) unsafe.Pointer { + p, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, mmapFD, 0) +@@ -165,6 +166,7 @@ func sysHugePage(v unsafe.Pointer, n uintptr) { + + // Don't split the stack as this function may be invoked without a valid G, + // which prevents us from allocating more stack. ++// + //go:nosplit + func sysFree(v unsafe.Pointer, n uintptr, sysStat *sysMemStat) { + sysStat.add(-int64(n)) diff --git a/cross/gcc-armhf/APKBUILD b/cross/gcc-armhf/APKBUILD index b45a32157..cffa74d62 100644 --- a/cross/gcc-armhf/APKBUILD +++ b/cross/gcc-armhf/APKBUILD @@ -32,7 +32,7 @@ pkgver=${_pkgbase}_git${_pkgsnap} [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-armhf -pkgrel=4 +pkgrel=5 pkgdesc="Stage2 cross-compiler for armhf" url="https://gcc.gnu.org" arch="x86_64" @@ -795,11 +795,11 @@ b40d7e4712c035674c993bbb55475290ec14523b3f0fd05493514bac4e9adaa6641faf815fc40ffc f060687adcd5297124e4000f1ba1e3fd5d7d124da04d948cbd0d4a6c69a90a2b29a4a0dbbe13a83ab6950724f434de012b681bdbcdf53c0100b40fe3d00f2f2f 0028-ada-libgnarl-compatibility-for-musl.patch 5160bae68e20a1966c1f6d655ee98af759e9b9ee842718ae6007d467b418e1cf3b307528a0841477b5259671ce868521b06c0f2e947b7b8f3a398c53dd978252 0029-ada-musl-support-fixes.patch 3c04b26554a78096296ca9542c77a91219bd26044dd2cb2006db4c1944889a97c215900b3828ba7e8c675162406db543605a815bdfbd915bf810663b1b253bdd 0033-gcc-go-link-to-libucontext.patch -699dc3641099da6136dd3689f06c6553c03b3a85acf83a3fce1beb5425065b3e378535ca9e9100a120fdbafc34871d61c063fd5328a49cd87a15a989ed51706d 0034-Use-generic-errstr.go-implementation-on-musl.patch +141c0428f988cbd102000d4db8d4150485f6da5c064469493ea378cd579bed99330658f41fe106c0d07d1c1aa436ec3f864403ed1ba79f791a1d727b42d46910 0034-Use-generic-errstr.go-implementation-on-musl.patch d9ba710f770e053c8f212e821817c188091a829658050b9ab5906388553ec60fec37943ea43c270e92a9014902949f3c98fc4639032d92b8145b375bb29e193e 0035-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch ab90d8fdd977d6cd3da096a1c76d77be3e89a020b2127247771711a32eb608cceed21834ef488ab4b69bb0f408b098fdfb61630819e3d1a1e57d5af67800ee74 0036-configure-fix-detection-of-atomic-builtins-in-libato.patch 8bc6823f0b3c66f7b73d7ddb64ffa6930463285c2e9a14a2bc1882bcc4271144eaa1107d713294699caf9481648163cbf43921a2b8e4ac0d55c78a804bae8a3d 0037-libgo-Recognize-off64_t-and-loff_t-definitions-of-mu.patch -e9699f4721778869eb3a8fef2c679208ef5b98584892f30b0e1cb5dc1669f8158198d7792659b1b56c381baf62247d21990dcced9178547affd5d6bfb2d12548 0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch +f0744c01859e67deed404c97e1870b2876935fdc467e51980373744936574c314d5d21134734c5d515e7f3cd3483ef98045b9bbcd81c568c6038fac96ffb5fa0 0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch d6dc1bfb881a313d167aaa5658790b0f55eea4336c408cfc6613dd5783440dafd0d37c43031a5f3e69be40f632e38371cd4fb6e5f0494ac4ea4d7d5025d2ae02 0041-go-gospec-forcibly-disable-fsplit-stack-support.patch 684c6a6d52512b973429b6e709966439ac1e174f9e79a33d4a638b452245b457b34752b4b4034ba983f6a712f86522e7adf715bab00a6603f64a12139c5b1e39 0042-gcc-go-fix-build-error-with-SYS_SECCOMP.patch 25014dfa99d96ee70ce0ad22e9f7974f0a51cc50b3b9c2db49df50774c8cd29e497ceed120486bee50be83bfb07f2009ed310eb9b0543f2795bd7359b87eadd2 0043-libstdc-do-not-throw-exceptions-for-non-C-locales-on.patch diff --git a/cross/gcc-armv7/0034-Use-generic-errstr.go-implementation-on-musl.patch b/cross/gcc-armv7/0034-Use-generic-errstr.go-implementation-on-musl.patch index 85d75df2c..a5ad79774 100644 --- a/cross/gcc-armv7/0034-Use-generic-errstr.go-implementation-on-musl.patch +++ b/cross/gcc-armv7/0034-Use-generic-errstr.go-implementation-on-musl.patch @@ -1,45 +1,204 @@ -From 5093aa99f9cdded2e1ddf67b7139da6fac36b0a6 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?S=C3=B6ren=20Tempel?= -Date: Mon, 19 Apr 2021 07:21:41 +0200 -Subject: [PATCH] Use generic errstr.go implementation on musl +From b3840bdcc0eee2a4d099a9af52199944ade7acb9 Mon Sep 17 00:00:00 2001 +From: Ian Lance Taylor +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 -glibc provides two version of strerror_r() depending on a feature test -macro. The first is the XSI-compliant version which returns an int, the -second is GNU-specific and returns a char pointer. +This does the right thing for either glibc or musl on GNU/Linux. -Similarity, gcc's libgo provides two implementations of Errstr() both of -which use strerror_r(). On Linux, it is assumed that the GNU-specific -strerror_r version is used. However, musl only provides the -XSI-compliant version of strerror_r. This patch enables the generic -Errstr() implementation which also uses the XSI-compliant version of -strerror_r. +Based on patch by Sören Tempel. + +Change-Id: If2969e131f0fae456d58b35d839d8abe191fcc59 +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/454176 +Reviewed-by: Cherry Mui +Reviewed-by: Ian Lance Taylor +TryBot-Bypass: Ian Lance Taylor --- - libgo/go/syscall/errstr.go | 1 - - libgo/go/syscall/errstr_glibc.go | 2 +- - 2 files changed, 1 insertion(+), 2 deletions(-) + 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 6c2441d364d..8f7c5538163 100644 +index 6c2441d3..9f688e2a 100644 --- a/libgo/go/syscall/errstr.go +++ b/libgo/go/syscall/errstr.go -@@ -5,7 +5,6 @@ +@@ -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 !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 -index 5b19e6f202d..8dc60172186 100644 +deleted file mode 100644 +index 5b19e6f2..00000000 --- a/libgo/go/syscall/errstr_glibc.go -+++ b/libgo/go/syscall/errstr_glibc.go -@@ -7,7 +7,7 @@ - // 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. - ++++ /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 -+// +build hurd !linux - - package syscall - +- +-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 ++ ++#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/cross/gcc-armv7/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch b/cross/gcc-armv7/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch index 4867ab090..5c8599164 100644 --- a/cross/gcc-armv7/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch +++ b/cross/gcc-armv7/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch @@ -1,22 +1,26 @@ -From 4b6240d5301ce04b8bbc3e2152915cbc7da80584 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?S=C3=B6ren=20Tempel?= -Date: Wed, 28 Sep 2022 17:30:14 +0200 -Subject: [PATCH] libgo: use _off_t for mmap offset argument +From 5e658f4659c551330ea68f5667e4f951b218f32d Mon Sep 17 00:00:00 2001 +From: Ian Lance Taylor +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 -On glibc-based systems, off_t is a 32-bit type on 32-bit systems and a -64-bit type on 64-bit systems by default. However, on systems using musl -libc off_t is unconditionally a 64-bit type. As such, it is insufficient -to use a uintptr type for the mmap offset parameter. +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. -Presently, the (incorrect) mmap declaration causes a libgo run-time -failure on 32-bit musl systems (fatal error: runtime: cannot allocate -memory). This commit fixes this run-time error. +Based on patch by Sören Tempel. + +Change-Id: Ib6f9d5bcd4734f99a72889e2282b97ec3c8fbd34 +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/445735 +Reviewed-by: Cherry Mui +Reviewed-by: Than McIntosh --- - libgo/go/runtime/mem_gccgo.go | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) + libgo/go/runtime/mem_gccgo.go | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libgo/go/runtime/mem_gccgo.go b/libgo/go/runtime/mem_gccgo.go -index fa3389d8..07bf325a 100644 +index fa3389d8..1e84f4f5 100644 --- a/libgo/go/runtime/mem_gccgo.go +++ b/libgo/go/runtime/mem_gccgo.go @@ -15,7 +15,7 @@ import ( @@ -24,7 +28,7 @@ index fa3389d8..07bf325a 100644 //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 _off_t) 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 @@ -33,7 +37,23 @@ index fa3389d8..07bf325a 100644 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, _off_t(off)) ++ p := sysMmap(addr, n, prot, flags, fd, _libgo_off_t_type(off)) if uintptr(p) == _MAP_FAILED { return nil, errno() } +@@ -47,6 +47,7 @@ func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) (u + + // Don't split the stack as this method may be invoked without a valid G, which + // prevents us from allocating more stack. ++// + //go:nosplit + func sysAlloc(n uintptr, sysStat *sysMemStat) unsafe.Pointer { + p, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, mmapFD, 0) +@@ -165,6 +166,7 @@ func sysHugePage(v unsafe.Pointer, n uintptr) { + + // Don't split the stack as this function may be invoked without a valid G, + // which prevents us from allocating more stack. ++// + //go:nosplit + func sysFree(v unsafe.Pointer, n uintptr, sysStat *sysMemStat) { + sysStat.add(-int64(n)) diff --git a/cross/gcc-armv7/APKBUILD b/cross/gcc-armv7/APKBUILD index a1ae2702a..931155d6f 100644 --- a/cross/gcc-armv7/APKBUILD +++ b/cross/gcc-armv7/APKBUILD @@ -32,7 +32,7 @@ pkgver=${_pkgbase}_git${_pkgsnap} [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-armv7 -pkgrel=4 +pkgrel=5 pkgdesc="Stage2 cross-compiler for armv7" url="https://gcc.gnu.org" arch="x86_64" @@ -795,11 +795,11 @@ b40d7e4712c035674c993bbb55475290ec14523b3f0fd05493514bac4e9adaa6641faf815fc40ffc f060687adcd5297124e4000f1ba1e3fd5d7d124da04d948cbd0d4a6c69a90a2b29a4a0dbbe13a83ab6950724f434de012b681bdbcdf53c0100b40fe3d00f2f2f 0028-ada-libgnarl-compatibility-for-musl.patch 5160bae68e20a1966c1f6d655ee98af759e9b9ee842718ae6007d467b418e1cf3b307528a0841477b5259671ce868521b06c0f2e947b7b8f3a398c53dd978252 0029-ada-musl-support-fixes.patch 3c04b26554a78096296ca9542c77a91219bd26044dd2cb2006db4c1944889a97c215900b3828ba7e8c675162406db543605a815bdfbd915bf810663b1b253bdd 0033-gcc-go-link-to-libucontext.patch -699dc3641099da6136dd3689f06c6553c03b3a85acf83a3fce1beb5425065b3e378535ca9e9100a120fdbafc34871d61c063fd5328a49cd87a15a989ed51706d 0034-Use-generic-errstr.go-implementation-on-musl.patch +141c0428f988cbd102000d4db8d4150485f6da5c064469493ea378cd579bed99330658f41fe106c0d07d1c1aa436ec3f864403ed1ba79f791a1d727b42d46910 0034-Use-generic-errstr.go-implementation-on-musl.patch d9ba710f770e053c8f212e821817c188091a829658050b9ab5906388553ec60fec37943ea43c270e92a9014902949f3c98fc4639032d92b8145b375bb29e193e 0035-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch ab90d8fdd977d6cd3da096a1c76d77be3e89a020b2127247771711a32eb608cceed21834ef488ab4b69bb0f408b098fdfb61630819e3d1a1e57d5af67800ee74 0036-configure-fix-detection-of-atomic-builtins-in-libato.patch 8bc6823f0b3c66f7b73d7ddb64ffa6930463285c2e9a14a2bc1882bcc4271144eaa1107d713294699caf9481648163cbf43921a2b8e4ac0d55c78a804bae8a3d 0037-libgo-Recognize-off64_t-and-loff_t-definitions-of-mu.patch -e9699f4721778869eb3a8fef2c679208ef5b98584892f30b0e1cb5dc1669f8158198d7792659b1b56c381baf62247d21990dcced9178547affd5d6bfb2d12548 0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch +f0744c01859e67deed404c97e1870b2876935fdc467e51980373744936574c314d5d21134734c5d515e7f3cd3483ef98045b9bbcd81c568c6038fac96ffb5fa0 0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch d6dc1bfb881a313d167aaa5658790b0f55eea4336c408cfc6613dd5783440dafd0d37c43031a5f3e69be40f632e38371cd4fb6e5f0494ac4ea4d7d5025d2ae02 0041-go-gospec-forcibly-disable-fsplit-stack-support.patch 684c6a6d52512b973429b6e709966439ac1e174f9e79a33d4a638b452245b457b34752b4b4034ba983f6a712f86522e7adf715bab00a6603f64a12139c5b1e39 0042-gcc-go-fix-build-error-with-SYS_SECCOMP.patch 25014dfa99d96ee70ce0ad22e9f7974f0a51cc50b3b9c2db49df50774c8cd29e497ceed120486bee50be83bfb07f2009ed310eb9b0543f2795bd7359b87eadd2 0043-libstdc-do-not-throw-exceptions-for-non-C-locales-on.patch diff --git a/cross/gcc-riscv64/0034-Use-generic-errstr.go-implementation-on-musl.patch b/cross/gcc-riscv64/0034-Use-generic-errstr.go-implementation-on-musl.patch index 85d75df2c..a5ad79774 100644 --- a/cross/gcc-riscv64/0034-Use-generic-errstr.go-implementation-on-musl.patch +++ b/cross/gcc-riscv64/0034-Use-generic-errstr.go-implementation-on-musl.patch @@ -1,45 +1,204 @@ -From 5093aa99f9cdded2e1ddf67b7139da6fac36b0a6 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?S=C3=B6ren=20Tempel?= -Date: Mon, 19 Apr 2021 07:21:41 +0200 -Subject: [PATCH] Use generic errstr.go implementation on musl +From b3840bdcc0eee2a4d099a9af52199944ade7acb9 Mon Sep 17 00:00:00 2001 +From: Ian Lance Taylor +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 -glibc provides two version of strerror_r() depending on a feature test -macro. The first is the XSI-compliant version which returns an int, the -second is GNU-specific and returns a char pointer. +This does the right thing for either glibc or musl on GNU/Linux. -Similarity, gcc's libgo provides two implementations of Errstr() both of -which use strerror_r(). On Linux, it is assumed that the GNU-specific -strerror_r version is used. However, musl only provides the -XSI-compliant version of strerror_r. This patch enables the generic -Errstr() implementation which also uses the XSI-compliant version of -strerror_r. +Based on patch by Sören Tempel. + +Change-Id: If2969e131f0fae456d58b35d839d8abe191fcc59 +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/454176 +Reviewed-by: Cherry Mui +Reviewed-by: Ian Lance Taylor +TryBot-Bypass: Ian Lance Taylor --- - libgo/go/syscall/errstr.go | 1 - - libgo/go/syscall/errstr_glibc.go | 2 +- - 2 files changed, 1 insertion(+), 2 deletions(-) + 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 6c2441d364d..8f7c5538163 100644 +index 6c2441d3..9f688e2a 100644 --- a/libgo/go/syscall/errstr.go +++ b/libgo/go/syscall/errstr.go -@@ -5,7 +5,6 @@ +@@ -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 !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 -index 5b19e6f202d..8dc60172186 100644 +deleted file mode 100644 +index 5b19e6f2..00000000 --- a/libgo/go/syscall/errstr_glibc.go -+++ b/libgo/go/syscall/errstr_glibc.go -@@ -7,7 +7,7 @@ - // 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. - ++++ /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 -+// +build hurd !linux - - package syscall - +- +-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 ++ ++#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/cross/gcc-riscv64/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch b/cross/gcc-riscv64/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch index 4867ab090..5c8599164 100644 --- a/cross/gcc-riscv64/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch +++ b/cross/gcc-riscv64/0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch @@ -1,22 +1,26 @@ -From 4b6240d5301ce04b8bbc3e2152915cbc7da80584 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?S=C3=B6ren=20Tempel?= -Date: Wed, 28 Sep 2022 17:30:14 +0200 -Subject: [PATCH] libgo: use _off_t for mmap offset argument +From 5e658f4659c551330ea68f5667e4f951b218f32d Mon Sep 17 00:00:00 2001 +From: Ian Lance Taylor +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 -On glibc-based systems, off_t is a 32-bit type on 32-bit systems and a -64-bit type on 64-bit systems by default. However, on systems using musl -libc off_t is unconditionally a 64-bit type. As such, it is insufficient -to use a uintptr type for the mmap offset parameter. +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. -Presently, the (incorrect) mmap declaration causes a libgo run-time -failure on 32-bit musl systems (fatal error: runtime: cannot allocate -memory). This commit fixes this run-time error. +Based on patch by Sören Tempel. + +Change-Id: Ib6f9d5bcd4734f99a72889e2282b97ec3c8fbd34 +Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/445735 +Reviewed-by: Cherry Mui +Reviewed-by: Than McIntosh --- - libgo/go/runtime/mem_gccgo.go | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) + libgo/go/runtime/mem_gccgo.go | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libgo/go/runtime/mem_gccgo.go b/libgo/go/runtime/mem_gccgo.go -index fa3389d8..07bf325a 100644 +index fa3389d8..1e84f4f5 100644 --- a/libgo/go/runtime/mem_gccgo.go +++ b/libgo/go/runtime/mem_gccgo.go @@ -15,7 +15,7 @@ import ( @@ -24,7 +28,7 @@ index fa3389d8..07bf325a 100644 //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 _off_t) 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 @@ -33,7 +37,23 @@ index fa3389d8..07bf325a 100644 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, _off_t(off)) ++ p := sysMmap(addr, n, prot, flags, fd, _libgo_off_t_type(off)) if uintptr(p) == _MAP_FAILED { return nil, errno() } +@@ -47,6 +47,7 @@ func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) (u + + // Don't split the stack as this method may be invoked without a valid G, which + // prevents us from allocating more stack. ++// + //go:nosplit + func sysAlloc(n uintptr, sysStat *sysMemStat) unsafe.Pointer { + p, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, mmapFD, 0) +@@ -165,6 +166,7 @@ func sysHugePage(v unsafe.Pointer, n uintptr) { + + // Don't split the stack as this function may be invoked without a valid G, + // which prevents us from allocating more stack. ++// + //go:nosplit + func sysFree(v unsafe.Pointer, n uintptr, sysStat *sysMemStat) { + sysStat.add(-int64(n)) diff --git a/cross/gcc-riscv64/APKBUILD b/cross/gcc-riscv64/APKBUILD index 7fa7a8c89..7ebf0f62a 100644 --- a/cross/gcc-riscv64/APKBUILD +++ b/cross/gcc-riscv64/APKBUILD @@ -32,7 +32,7 @@ pkgver=${_pkgbase}_git${_pkgsnap} [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-riscv64 -pkgrel=4 +pkgrel=5 pkgdesc="Stage2 cross-compiler for riscv64" url="https://gcc.gnu.org" arch="x86_64" @@ -795,11 +795,11 @@ b40d7e4712c035674c993bbb55475290ec14523b3f0fd05493514bac4e9adaa6641faf815fc40ffc f060687adcd5297124e4000f1ba1e3fd5d7d124da04d948cbd0d4a6c69a90a2b29a4a0dbbe13a83ab6950724f434de012b681bdbcdf53c0100b40fe3d00f2f2f 0028-ada-libgnarl-compatibility-for-musl.patch 5160bae68e20a1966c1f6d655ee98af759e9b9ee842718ae6007d467b418e1cf3b307528a0841477b5259671ce868521b06c0f2e947b7b8f3a398c53dd978252 0029-ada-musl-support-fixes.patch 3c04b26554a78096296ca9542c77a91219bd26044dd2cb2006db4c1944889a97c215900b3828ba7e8c675162406db543605a815bdfbd915bf810663b1b253bdd 0033-gcc-go-link-to-libucontext.patch -699dc3641099da6136dd3689f06c6553c03b3a85acf83a3fce1beb5425065b3e378535ca9e9100a120fdbafc34871d61c063fd5328a49cd87a15a989ed51706d 0034-Use-generic-errstr.go-implementation-on-musl.patch +141c0428f988cbd102000d4db8d4150485f6da5c064469493ea378cd579bed99330658f41fe106c0d07d1c1aa436ec3f864403ed1ba79f791a1d727b42d46910 0034-Use-generic-errstr.go-implementation-on-musl.patch d9ba710f770e053c8f212e821817c188091a829658050b9ab5906388553ec60fec37943ea43c270e92a9014902949f3c98fc4639032d92b8145b375bb29e193e 0035-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch ab90d8fdd977d6cd3da096a1c76d77be3e89a020b2127247771711a32eb608cceed21834ef488ab4b69bb0f408b098fdfb61630819e3d1a1e57d5af67800ee74 0036-configure-fix-detection-of-atomic-builtins-in-libato.patch 8bc6823f0b3c66f7b73d7ddb64ffa6930463285c2e9a14a2bc1882bcc4271144eaa1107d713294699caf9481648163cbf43921a2b8e4ac0d55c78a804bae8a3d 0037-libgo-Recognize-off64_t-and-loff_t-definitions-of-mu.patch -e9699f4721778869eb3a8fef2c679208ef5b98584892f30b0e1cb5dc1669f8158198d7792659b1b56c381baf62247d21990dcced9178547affd5d6bfb2d12548 0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch +f0744c01859e67deed404c97e1870b2876935fdc467e51980373744936574c314d5d21134734c5d515e7f3cd3483ef98045b9bbcd81c568c6038fac96ffb5fa0 0039-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch d6dc1bfb881a313d167aaa5658790b0f55eea4336c408cfc6613dd5783440dafd0d37c43031a5f3e69be40f632e38371cd4fb6e5f0494ac4ea4d7d5025d2ae02 0041-go-gospec-forcibly-disable-fsplit-stack-support.patch 684c6a6d52512b973429b6e709966439ac1e174f9e79a33d4a638b452245b457b34752b4b4034ba983f6a712f86522e7adf715bab00a6603f64a12139c5b1e39 0042-gcc-go-fix-build-error-with-SYS_SECCOMP.patch 25014dfa99d96ee70ce0ad22e9f7974f0a51cc50b3b9c2db49df50774c8cd29e497ceed120486bee50be83bfb07f2009ed310eb9b0543f2795bd7359b87eadd2 0043-libstdc-do-not-throw-exceptions-for-non-C-locales-on.patch