Skip to content

Commit b76c83f

Browse files
bsiegertianlancetaylor
authored andcommitted
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. Change-Id: I818069de3eea8f3d33479542a798c729c9efd042 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/228918 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 571e2db commit b76c83f

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

libgo/go/runtime/os_netbsd.go

+36-5
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ func semasleep(ns int64) int32 {
6868
}
6969

7070
for {
71-
v := atomic.Load(&_g_.m.mos.waitsemacount)
71+
v := atomic.Load(&_g_.m.waitsemacount)
7272
if v > 0 {
73-
if atomic.Cas(&_g_.m.mos.waitsemacount, v, v-1) {
73+
if atomic.Cas(&_g_.m.waitsemacount, v, v-1) {
7474
return 0 // semaphore acquired
7575
}
7676
continue
@@ -96,15 +96,15 @@ func semasleep(ns int64) int32 {
9696

9797
//go:nosplit
9898
func semawakeup(mp *m) {
99-
atomic.Xadd(&mp.mos.waitsemacount, 1)
99+
atomic.Xadd(&mp.waitsemacount, 1)
100100
// From NetBSD's _lwp_unpark(2) manual:
101101
// "If the target LWP is not currently waiting, it will return
102102
// immediately upon the next call to _lwp_park()."
103-
ret := lwp_unpark(int32(mp.procid), unsafe.Pointer(&mp.mos.waitsemacount))
103+
ret := lwp_unpark(int32(mp.procid), unsafe.Pointer(&mp.waitsemacount))
104104
if ret != 0 && ret != _ESRCH {
105105
// semawakeup can be called on signal stack.
106106
systemstack(func() {
107-
print("thrwakeup addr=", &mp.mos.waitsemacount, " sem=", mp.mos.waitsemacount, " ret=", ret, "\n")
107+
print("thrwakeup addr=", &mp.waitsemacount, " sem=", mp.waitsemacount, " ret=", ret, "\n")
108108
})
109109
}
110110
}
@@ -115,3 +115,34 @@ func osinit() {
115115
physPageSize = getPageSize()
116116
}
117117
}
118+
119+
func sysargs(argc int32, argv **byte) {
120+
n := argc + 1
121+
122+
// skip over argv, envp to get to auxv
123+
for argv_index(argv, n) != nil {
124+
n++
125+
}
126+
127+
// skip NULL separator
128+
n++
129+
130+
// now argv+n is auxv
131+
auxv := (*[1 << 28]uintptr)(add(unsafe.Pointer(argv), uintptr(n)*sys.PtrSize))
132+
sysauxv(auxv[:])
133+
}
134+
135+
const (
136+
_AT_NULL = 0 // Terminates the vector
137+
_AT_PAGESZ = 6 // Page size in bytes
138+
)
139+
140+
func sysauxv(auxv []uintptr) {
141+
for i := 0; auxv[i] != _AT_NULL; i += 2 {
142+
tag, val := auxv[i], auxv[i+1]
143+
switch tag {
144+
case _AT_PAGESZ:
145+
physPageSize = val
146+
}
147+
}
148+
}

libgo/go/runtime/signal_gccgo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type sigctxt struct {
6060
}
6161

6262
func (c *sigctxt) sigcode() uint64 {
63-
return uint64(c.info.si_code)
63+
return uint64(getSiginfoCode(c.info))
6464
}
6565

6666
//go:nosplit

libgo/go/runtime/stubs.go

+4
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ func getSigactionHandler(*_sigaction) uintptr
297297
//go:noescape
298298
func setSigactionHandler(*_sigaction, uintptr)
299299

300+
// Get signal code, written in C.
301+
//go:noescape
302+
func getSiginfoCode(*_siginfo_t) uintptr
303+
300304
// Retrieve fields from the siginfo_t and ucontext_t pointers passed
301305
// to a signal handler using C, as they are often hidden in a union.
302306
// Returns and, if available, PC where signal occurred.

libgo/runtime/go-signal.c

+12
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@ setSigactionHandler(struct sigaction* sa, uintptr handler)
179179
// C code to fetch values from the siginfo_t and ucontext_t pointers
180180
// passed to a signal handler.
181181

182+
uintptr getSiginfoCode(siginfo_t *)
183+
__attribute__ ((no_split_stack));
184+
185+
uintptr getSiginfoCode(siginfo_t *)
186+
__asm__ (GOSYM_PREFIX "runtime.getSiginfoCode");
187+
188+
uintptr
189+
getSiginfoCode(siginfo_t *info)
190+
{
191+
return (uintptr)(info->si_code);
192+
}
193+
182194
struct getSiginfoRet {
183195
uintptr sigaddr;
184196
uintptr sigpc;

0 commit comments

Comments
 (0)