Mon Apr 20 14:25:52 2020 UTC ()
gcc9: start fixing gccgo build under NetBSD.

This fixes the build of the "runtime" package, now the compilation is
stuck in the "syscall" package instead.

Submitted upstream as https://go-review.googlesource.com/c/gofrontend/+/228918/.
Upstream bug report at https://github.com/golang/go/issues/38538.


(bsiegert)
diff -r1.17 -r1.18 pkgsrc/lang/gcc9/Makefile
diff -r1.3 -r1.4 pkgsrc/lang/gcc9/distinfo
diff -r0 -r1.1 pkgsrc/lang/gcc9/patches/patch-libgo_go_runtime_os__netbsd.go
diff -r0 -r1.1 pkgsrc/lang/gcc9/patches/patch-libgo_go_runtime_signal__gccgo.go
diff -r0 -r1.1 pkgsrc/lang/gcc9/patches/patch-libgo_go_runtime_stubs.go
diff -r0 -r1.1 pkgsrc/lang/gcc9/patches/patch-libgo_runtime_go-signal.c

cvs diff -r1.17 -r1.18 pkgsrc/lang/gcc9/Makefile (expand / switch to unified diff)

--- pkgsrc/lang/gcc9/Makefile 2020/04/08 16:35:59 1.17
+++ pkgsrc/lang/gcc9/Makefile 2020/04/20 14:25:52 1.18
@@ -1,16 +1,17 @@ @@ -1,16 +1,17 @@
1# $NetBSD: Makefile,v 1.17 2020/04/08 16:35:59 wiz Exp $ 1# $NetBSD: Makefile,v 1.18 2020/04/20 14:25:52 bsiegert Exp $
2 2
3GCC9_VERSION= 9.3.0 3GCC9_VERSION= 9.3.0
 4PKGREVISION= 1
4 5
5DISTNAME= gcc-${GCC9_VERSION} 6DISTNAME= gcc-${GCC9_VERSION}
6PKGNAME= gcc9-${GCC9_VERSION} 7PKGNAME= gcc9-${GCC9_VERSION}
7CATEGORIES= lang 8CATEGORIES= lang
8MASTER_SITES= ${MASTER_SITE_GNU:=gcc/gcc-${GCC9_VERSION}/} 9MASTER_SITES= ${MASTER_SITE_GNU:=gcc/gcc-${GCC9_VERSION}/}
9EXTRACT_SUFX= .tar.xz 10EXTRACT_SUFX= .tar.xz
10 11
11MAINTAINER= pkgsrc-users@NetBSD.org 12MAINTAINER= pkgsrc-users@NetBSD.org
12HOMEPAGE= https://gcc.gnu.org/ 13HOMEPAGE= https://gcc.gnu.org/
13COMMENT= The GNU Compiler Collection (GCC) - Release 9 Series 14COMMENT= The GNU Compiler Collection (GCC) - Release 9 Series
14LICENSE= gnu-gpl-v2 AND gnu-gpl-v3 AND gnu-lgpl-v2 AND gnu-lgpl-v3 15LICENSE= gnu-gpl-v2 AND gnu-gpl-v3 AND gnu-lgpl-v2 AND gnu-lgpl-v3
15 16
16# These are conditionally overwritten depending on the package options. 17# These are conditionally overwritten depending on the package options.

cvs diff -r1.3 -r1.4 pkgsrc/lang/gcc9/distinfo (expand / switch to unified diff)

--- pkgsrc/lang/gcc9/distinfo 2020/04/08 16:35:59 1.3
+++ pkgsrc/lang/gcc9/distinfo 2020/04/20 14:25:52 1.4
@@ -1,9 +1,13 @@ @@ -1,9 +1,13 @@
1$NetBSD: distinfo,v 1.3 2020/04/08 16:35:59 wiz Exp $ 1$NetBSD: distinfo,v 1.4 2020/04/20 14:25:52 bsiegert Exp $
2 2
3SHA1 (gcc-9.3.0.tar.xz) = b746688bf045a316fc92c3528138ad10d0822b6b 3SHA1 (gcc-9.3.0.tar.xz) = b746688bf045a316fc92c3528138ad10d0822b6b
4RMD160 (gcc-9.3.0.tar.xz) = e0ade31726b8fbb1eb308e2b1383a79633aef996 4RMD160 (gcc-9.3.0.tar.xz) = e0ade31726b8fbb1eb308e2b1383a79633aef996
5SHA512 (gcc-9.3.0.tar.xz) = 4b9e3639eef6e623747a22c37a904b4750c93b6da77cf3958d5047e9b5ebddb7eebe091cc16ca0a227c0ecbd2bf3b984b221130f269a97ee4cc18f9cf6c444de 5SHA512 (gcc-9.3.0.tar.xz) = 4b9e3639eef6e623747a22c37a904b4750c93b6da77cf3958d5047e9b5ebddb7eebe091cc16ca0a227c0ecbd2bf3b984b221130f269a97ee4cc18f9cf6c444de
6Size (gcc-9.3.0.tar.xz) = 70533868 bytes 6Size (gcc-9.3.0.tar.xz) = 70533868 bytes
7SHA1 (patch-gcc_gimplify.c) = f933a033d4a6c11fa82c8c9c6785842ba7993862 7SHA1 (patch-gcc_gimplify.c) = f933a033d4a6c11fa82c8c9c6785842ba7993862
 8SHA1 (patch-libgo_go_runtime_os__netbsd.go) = 357c62afe017a5ca3d7138abb2c19dc10bc5cd3d
 9SHA1 (patch-libgo_go_runtime_signal__gccgo.go) = 51b632c1c827f6d99fc2d7803294a0b7a64514a1
 10SHA1 (patch-libgo_go_runtime_stubs.go) = f4753765eb7ee9a933f2bb3a05f27c487a1d51ef
 11SHA1 (patch-libgo_runtime_go-signal.c) = 6121b041cdd850adeea943f385d52b65d6bfe249
8SHA1 (patch-libstdc++-v3_config_os_bsd_netbsd_ctype__base.h) = f12f6a97f94d13efa73a2500411bc77b27887edd 12SHA1 (patch-libstdc++-v3_config_os_bsd_netbsd_ctype__base.h) = f12f6a97f94d13efa73a2500411bc77b27887edd
9SHA1 (patch-libstdc++-v3_config_os_bsd_netbsd_ctype__configure__char.cc) = 007bce70f75deace18f60924b5a3f94bf7a0af2f 13SHA1 (patch-libstdc++-v3_config_os_bsd_netbsd_ctype__configure__char.cc) = 007bce70f75deace18f60924b5a3f94bf7a0af2f

File Added: pkgsrc/lang/gcc9/patches/patch-libgo_go_runtime_os__netbsd.go
$NetBSD: patch-libgo_go_runtime_os__netbsd.go,v 1.1 2020/04/20 14:25:52 bsiegert Exp $

Fix compilation errors under NetBSD. Taken from upstream Go 1.14 sources.

--- libgo/go/runtime/os_netbsd.go.orig	2020-03-12 11:07:24.000000000 +0000
+++ libgo/go/runtime/os_netbsd.go
@@ -52,11 +52,11 @@ func semasleep(ns int64) int32 {
 				return -1
 			}
 			var nsec int32
-			ts.set_sec(timediv(wait, 1000000000, &nsec))
+			ts.set_sec(int64(timediv(wait, 1000000000, &nsec)))
 			ts.set_nsec(nsec)
 			tsp = &ts
 		}
-		ret := lwp_park(_CLOCK_MONOTONIC, _TIMER_RELTIME, tsp, 0, unsafe.Pointer(&_g_.m.waitsemacount), nil)
+		ret := lwp_park(_CLOCK_MONOTONIC, _TIMER_RELTIME, tsp, 0, unsafe.Pointer(&_g_.m.mos.waitsemacount), nil)
 		if ret == _ETIMEDOUT {
 			return -1
 		}
@@ -77,3 +77,34 @@ func semawakeup(mp *m) {
 		})
 	}
 }
+
+func sysargs(argc int32, argv **byte) {
+	n := argc + 1
+
+	// skip over argv, envp to get to auxv
+	for argv_index(argv, n) != nil {
+		n++
+	}
+
+	// skip NULL separator
+	n++
+
+	// now argv+n is auxv
+	auxv := (*[1 << 28]uintptr)(add(unsafe.Pointer(argv), uintptr(n)*sys.PtrSize))
+	sysauxv(auxv[:])
+}
+
+const (
+	_AT_NULL   = 0 // Terminates the vector
+	_AT_PAGESZ = 6 // Page size in bytes
+)
+
+func sysauxv(auxv []uintptr) {
+	for i := 0; auxv[i] != _AT_NULL; i += 2 {
+		tag, val := auxv[i], auxv[i+1]
+		switch tag {
+		case _AT_PAGESZ:
+			physPageSize = val
+		}
+	}
+}

File Added: pkgsrc/lang/gcc9/patches/patch-libgo_go_runtime_signal__gccgo.go
$NetBSD: patch-libgo_go_runtime_signal__gccgo.go,v 1.1 2020/04/20 14:25:52 bsiegert Exp $

si_code is a macro on NetBSD, add a C trampoline function.

--- libgo/go/runtime/signal_gccgo.go.orig	2020-04-18 16:53:50.092569597 +0000
+++ libgo/go/runtime/signal_gccgo.go
@@ -65,7 +65,7 @@ func (c *sigctxt) sigcode() uint64 {
 		// code, just avoid a misleading value.
 		return _SI_USER + 1
 	}
-	return uint64(c.info.si_code)
+	return uint64(getSiginfoCode(c.info))
 }
 
 //go:nosplit

File Added: pkgsrc/lang/gcc9/patches/patch-libgo_go_runtime_stubs.go
$NetBSD: patch-libgo_go_runtime_stubs.go,v 1.1 2020/04/20 14:25:52 bsiegert Exp $

si_code is a macro on NetBSD, add a C trampoline function.

--- libgo/go/runtime/stubs.go.orig	2020-03-12 11:07:24.000000000 +0000
+++ libgo/go/runtime/stubs.go
@@ -326,6 +326,10 @@ func getSigactionHandler(*_sigaction) ui
 //go:noescape
 func setSigactionHandler(*_sigaction, uintptr)
 
+// Get signal code, written in C.
+//go:noescape
+func getSiginfoCode(*_siginfo_t) uintptr
+
 // Retrieve fields from the siginfo_t and ucontext_t pointers passed
 // to a signal handler using C, as they are often hidden in a union.
 // Returns  and, if available, PC where signal occurred.

File Added: pkgsrc/lang/gcc9/patches/patch-libgo_runtime_go-signal.c
$NetBSD: patch-libgo_runtime_go-signal.c,v 1.1 2020/04/20 14:25:52 bsiegert Exp $

si_code is a macro on NetBSD, add a C trampoline function.

--- libgo/runtime/go-signal.c.orig	2020-03-12 11:07:24.000000000 +0000
+++ libgo/runtime/go-signal.c
@@ -179,6 +179,18 @@ setSigactionHandler(struct sigaction* sa
 // C code to fetch values from the siginfo_t and ucontext_t pointers
 // passed to a signal handler.
 
+uintptr getSiginfoCode(siginfo_t *)
+	__attribute__ ((no_split_stack));
+
+uintptr getSiginfoCode(siginfo_t *)
+	__asm__ (GOSYM_PREFIX "runtime.getSiginfoCode");
+
+uintptr
+getSiginfoCode(siginfo_t *info)
+{
+	return (uintptr)(info->si_code);
+}
+
 struct getSiginfoRet {
 	uintptr sigaddr;
 	uintptr sigpc;