]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: export notinheap annotation to object file
authorKeith Randall <khr@golang.org>
Fri, 2 Oct 2020 22:48:50 +0000 (15:48 -0700)
committerKeith Randall <khr@golang.org>
Mon, 5 Oct 2020 18:52:43 +0000 (18:52 +0000)
In the rare case when a cgo type makes it into an object file, we need
the go:notinheap annotation to go with it.

Fixes #41761

Change-Id: I541500cb1a03de954881aef659f96fc0b7738848
Reviewed-on: https://go-review.googlesource.com/c/go/+/259297
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
misc/cgo/test/testdata/issue41761.go [new file with mode: 0644]
misc/cgo/test/testdata/issue41761a/a.go [new file with mode: 0644]
src/cmd/compile/internal/gc/iexport.go
src/cmd/compile/internal/gc/iimport.go
src/cmd/compile/internal/gc/lex.go

diff --git a/misc/cgo/test/testdata/issue41761.go b/misc/cgo/test/testdata/issue41761.go
new file mode 100644 (file)
index 0000000..919c749
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2020 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.
+
+package cgotest
+
+/*
+   typedef struct S S;
+*/
+import "C"
+
+import (
+       "cgotest/issue41761a"
+       "testing"
+)
+
+func test41761(t *testing.T) {
+       var x issue41761a.T
+       _ = (*C.struct_S)(x.X)
+}
diff --git a/misc/cgo/test/testdata/issue41761a/a.go b/misc/cgo/test/testdata/issue41761a/a.go
new file mode 100644 (file)
index 0000000..ca5c181
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2020 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.
+
+package issue41761a
+
+/*
+   typedef struct S S;
+*/
+import "C"
+
+type T struct {
+       X *C.S
+}
index b3f50b63af58f3281c53f6464adc37852e8ded73..3be3b0a21386ecf0da91328b459b8acf97046f38 100644 (file)
@@ -1017,6 +1017,8 @@ func (w *exportWriter) symIdx(s *types.Sym) {
 }
 
 func (w *exportWriter) typeExt(t *types.Type) {
+       // Export whether this type is marked notinheap.
+       w.bool(t.NotInHeap())
        // For type T, export the index of type descriptor symbols of T and *T.
        if i, ok := typeSymIdx[t]; ok {
                w.int64(i[0])
index 4169222c14f2b1fcf02a92e6934c80c44882e7b7..0c5e469c57a6d4af745938260a8ba3621f61b98a 100644 (file)
@@ -596,7 +596,6 @@ func (r *importReader) typ1() *types.Type {
 
                // Ensure we expand the interface in the frontend (#25055).
                checkwidth(t)
-
                return t
        }
 }
@@ -711,6 +710,7 @@ func (r *importReader) symIdx(s *types.Sym) {
 }
 
 func (r *importReader) typeExt(t *types.Type) {
+       t.SetNotInHeap(r.bool())
        i, pi := r.int64(), r.int64()
        if i != -1 && pi != -1 {
                typeSymIdx[t] = [2]int64{i, pi}
index 1a344c656625bdd76c1a4a260f293cb606ac616f..25bc0399ce392c3516bc262c803f916d7962c524 100644 (file)
@@ -48,7 +48,7 @@ const (
        Nowritebarrierrec  // error on write barrier in this or recursive callees
        Yeswritebarrierrec // cancels Nowritebarrierrec in this function and callees
 
-       // Runtime-only type pragmas
+       // Runtime and cgo type pragmas
        NotInHeap // values of this type must not be heap allocated
 )