aboutsummaryrefslogtreecommitdiff
path: root/libgo/go
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2022-09-29 10:41:04 +0200
committerMartin Liska <mliska@suse.cz>2022-09-29 10:41:04 +0200
commit54f3cfaf3a6f50958c71d79c85206a6c722e1a22 (patch)
tree5f33297a30acc0df71baa0566cffa701eb97ab4e /libgo/go
parent3c527a35fa428b727807c81f1225a5e0025446c1 (diff)
parenta1cd4d52d6ef90b977fb2d80c1cf17f3efa5b01d (diff)
downloadgcc-54f3cfaf3a6f50958c71d79c85206a6c722e1a22.zip
gcc-54f3cfaf3a6f50958c71d79c85206a6c722e1a22.tar.gz
gcc-54f3cfaf3a6f50958c71d79c85206a6c722e1a22.tar.bz2
Merge branch 'master' into devel/sphinx
Diffstat (limited to 'libgo/go')
-rw-r--r--libgo/go/runtime/ffi.go14
-rw-r--r--libgo/go/runtime/os_linux.go12
2 files changed, 21 insertions, 5 deletions
diff --git a/libgo/go/runtime/ffi.go b/libgo/go/runtime/ffi.go
index cd8479e..86ce5b8 100644
--- a/libgo/go/runtime/ffi.go
+++ b/libgo/go/runtime/ffi.go
@@ -4,6 +4,7 @@
// Only build this file if libffi is supported.
+//go:build libffi
// +build libffi
package runtime
@@ -221,9 +222,6 @@ func stringToFFI() *__ffi_type {
// structToFFI returns an ffi_type for a Go struct type.
func structToFFI(typ *structtype) *__ffi_type {
c := len(typ.fields)
- if c == 0 {
- return emptyStructToFFI()
- }
if typ.typ.kind&kindDirectIface != 0 {
return ffi_type_pointer()
}
@@ -231,6 +229,7 @@ func structToFFI(typ *structtype) *__ffi_type {
fields := make([]*__ffi_type, 0, c+1)
checkPad := false
lastzero := false
+ sawnonzero := false
for i, v := range typ.fields {
// Skip zero-sized fields; they confuse libffi,
// and there is no value to pass in any case.
@@ -239,10 +238,13 @@ func structToFFI(typ *structtype) *__ffi_type {
// next field.
if v.typ.size == 0 {
checkPad = true
- lastzero = true
+ if v.name == nil || *v.name != "_" {
+ lastzero = true
+ }
continue
}
lastzero = false
+ sawnonzero = true
if checkPad {
off := uintptr(0)
@@ -263,6 +265,10 @@ func structToFFI(typ *structtype) *__ffi_type {
fields = append(fields, typeToFFI(v.typ))
}
+ if !sawnonzero {
+ return emptyStructToFFI()
+ }
+
if lastzero {
// The compiler adds one byte padding to non-empty struct ending
// with a zero-sized field (types.cc:get_backend_struct_fields).
diff --git a/libgo/go/runtime/os_linux.go b/libgo/go/runtime/os_linux.go
index 96fb178..2b2d827 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