public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/gccgo] gccgo: fix runtime compilation on NetBSD
@ 2020-07-12 17:22 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2020-07-12 17:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8e841bd419fb9dc3e027367fc11078b677541a9a

commit 8e841bd419fb9dc3e027367fc11078b677541a9a
Author: Benny Siegert <bsiegert@gmail.com>
Date:   Mon Apr 20 16:11:14 2020 +0200

    gccgo: fix runtime compilation on NetBSD
    
    si_code in siginfo_t is a macro on NetBSD, not a member of the
    struct itself, so add a C trampoline for receiving its value.
    
    Also replace references to mos.waitsemacount with the replacement and
    add some helpers from os_netbsd.go in the GC repository.
    
    Update golang/go#38538.
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/228918

Diff:
---
 gcc/go/gofrontend/MERGE          |  2 +-
 libgo/go/runtime/os_netbsd.go    | 41 +++++++++++++++++++++++++++++++++++-----
 libgo/go/runtime/signal_gccgo.go |  2 +-
 libgo/go/runtime/stubs.go        |  4 ++++
 libgo/runtime/go-signal.c        | 12 ++++++++++++
 5 files changed, 54 insertions(+), 7 deletions(-)

diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 7b382cf47b8..e48abcf71d6 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-0fe7a277c5d22265a73a4d216bd5d81799634453
+b76c83f34c006938fe6c3311d949496990bc5db9
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/go/runtime/os_netbsd.go b/libgo/go/runtime/os_netbsd.go
index 7c3d41fb9d1..69d2c710449 100644
--- a/libgo/go/runtime/os_netbsd.go
+++ b/libgo/go/runtime/os_netbsd.go
@@ -68,9 +68,9 @@ func semasleep(ns int64) int32 {
 	}
 
 	for {
-		v := atomic.Load(&_g_.m.mos.waitsemacount)
+		v := atomic.Load(&_g_.m.waitsemacount)
 		if v > 0 {
-			if atomic.Cas(&_g_.m.mos.waitsemacount, v, v-1) {
+			if atomic.Cas(&_g_.m.waitsemacount, v, v-1) {
 				return 0 // semaphore acquired
 			}
 			continue
@@ -96,15 +96,15 @@ func semasleep(ns int64) int32 {
 
 //go:nosplit
 func semawakeup(mp *m) {
-	atomic.Xadd(&mp.mos.waitsemacount, 1)
+	atomic.Xadd(&mp.waitsemacount, 1)
 	// From NetBSD's _lwp_unpark(2) manual:
 	// "If the target LWP is not currently waiting, it will return
 	// immediately upon the next call to _lwp_park()."
-	ret := lwp_unpark(int32(mp.procid), unsafe.Pointer(&mp.mos.waitsemacount))
+	ret := lwp_unpark(int32(mp.procid), unsafe.Pointer(&mp.waitsemacount))
 	if ret != 0 && ret != _ESRCH {
 		// semawakeup can be called on signal stack.
 		systemstack(func() {
-			print("thrwakeup addr=", &mp.mos.waitsemacount, " sem=", mp.mos.waitsemacount, " ret=", ret, "\n")
+			print("thrwakeup addr=", &mp.waitsemacount, " sem=", mp.waitsemacount, " ret=", ret, "\n")
 		})
 	}
 }
@@ -115,3 +115,34 @@ func osinit() {
 		physPageSize = getPageSize()
 	}
 }
+
+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
+		}
+	}
+}
diff --git a/libgo/go/runtime/signal_gccgo.go b/libgo/go/runtime/signal_gccgo.go
index 6f362fc05be..c555712a03c 100644
--- a/libgo/go/runtime/signal_gccgo.go
+++ b/libgo/go/runtime/signal_gccgo.go
@@ -60,7 +60,7 @@ type sigctxt struct {
 }
 
 func (c *sigctxt) sigcode() uint64 {
-	return uint64(c.info.si_code)
+	return uint64(getSiginfoCode(c.info))
 }
 
 //go:nosplit
diff --git a/libgo/go/runtime/stubs.go b/libgo/go/runtime/stubs.go
index 4a06da51fe5..25b1836daf0 100644
--- a/libgo/go/runtime/stubs.go
+++ b/libgo/go/runtime/stubs.go
@@ -297,6 +297,10 @@ func getSigactionHandler(*_sigaction) uintptr
 //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.
diff --git a/libgo/runtime/go-signal.c b/libgo/runtime/go-signal.c
index a07fdeafeb4..b429fdb2403 100644
--- a/libgo/runtime/go-signal.c
+++ b/libgo/runtime/go-signal.c
@@ -179,6 +179,18 @@ setSigactionHandler(struct sigaction* sa, uintptr handler)
 // 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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-07-12 17:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-12 17:22 [gcc/devel/gccgo] gccgo: fix runtime compilation on NetBSD Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).