]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: put shlib ".type" functions in internal ABI
authorIan Lance Taylor <iant@golang.org>
Sat, 13 Jul 2019 19:20:43 +0000 (12:20 -0700)
committerIan Lance Taylor <iant@golang.org>
Mon, 15 Jul 2019 22:54:39 +0000 (22:54 +0000)
These functions are compiler generated, and as such are only available
in the internal ABI. Doing this avoids generating an alias symbol.
Doing that avoids confusion between unmangled and mangled type symbols.

Fixes #30768

Change-Id: I197a5ba6403aac11989ffa951dbe35bd0506de91
Reviewed-on: https://go-review.googlesource.com/c/go/+/186077
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
misc/cgo/testshared/shared_test.go
misc/cgo/testshared/testdata/issue30768/issue30768lib/lib.go [new file with mode: 0644]
misc/cgo/testshared/testdata/issue30768/x_test.go [new file with mode: 0644]
src/cmd/link/internal/ld/lib.go

index ac1a1c7f1a8cca20da9448ad244eb529e1a8fce7..9d16338c0f6342fc4375f76ff04f556f799a5bac 100644 (file)
@@ -941,3 +941,10 @@ func TestTestInstalledShared(t *testing.T) {
 func TestGeneratedMethod(t *testing.T) {
        goCmd(t, "install", "-buildmode=shared", "-linkshared", "./issue25065")
 }
+
+// Test use of shared library struct with generated hash function.
+// Issue 30768.
+func TestGeneratedHash(t *testing.T) {
+       goCmd(nil, "install", "-buildmode=shared", "-linkshared", "./issue30768/issue30768lib")
+       goCmd(nil, "test", "-linkshared", "./issue30768")
+}
diff --git a/misc/cgo/testshared/testdata/issue30768/issue30768lib/lib.go b/misc/cgo/testshared/testdata/issue30768/issue30768lib/lib.go
new file mode 100644 (file)
index 0000000..9e45ebe
--- /dev/null
@@ -0,0 +1,11 @@
+// Copyright 2019 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 issue30768lib
+
+// S is a struct that requires a generated hash function.
+type S struct {
+       A string
+       B int
+}
diff --git a/misc/cgo/testshared/testdata/issue30768/x_test.go b/misc/cgo/testshared/testdata/issue30768/x_test.go
new file mode 100644 (file)
index 0000000..1bbd139
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2019 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 issue30768_test
+
+import (
+       "testing"
+
+       "testshared/issue30768/issue30768lib"
+)
+
+type s struct {
+       s issue30768lib.S
+}
+
+func Test30768(t *testing.T) {
+       // Calling t.Log will convert S to an empty interface,
+       // which will force a reference to the generated hash function,
+       // defined in the shared library.
+       t.Log(s{})
+}
index 49f3b3c0d7c654b74ef004439e91b94bb20af312..9c71a4f51eb4d649fe7e237f69c904a83169dc32 100644 (file)
@@ -1902,7 +1902,15 @@ func ldshlibsyms(ctxt *Link, shlib string) {
                if elf.ST_TYPE(elfsym.Info) == elf.STT_NOTYPE || elf.ST_TYPE(elfsym.Info) == elf.STT_SECTION {
                        continue
                }
-               lsym := ctxt.Syms.Lookup(elfsym.Name, 0)
+
+               // Symbols whose names start with "type." are compiler
+               // generated, so make functions with that prefix internal.
+               ver := 0
+               if elf.ST_TYPE(elfsym.Info) == elf.STT_FUNC && strings.HasPrefix(elfsym.Name, "type.") {
+                       ver = sym.SymVerABIInternal
+               }
+
+               lsym := ctxt.Syms.Lookup(elfsym.Name, ver)
                // Because loadlib above loads all .a files before loading any shared
                // libraries, any non-dynimport symbols we find that duplicate symbols
                // already loaded should be ignored (the symbols from the .a files
@@ -1930,7 +1938,7 @@ func ldshlibsyms(ctxt *Link, shlib string) {
                // the ABIs are actually different. We might have to
                // mangle Go function names in the .so to include the
                // ABI.
-               if elf.ST_TYPE(elfsym.Info) == elf.STT_FUNC {
+               if elf.ST_TYPE(elfsym.Info) == elf.STT_FUNC && ver == 0 {
                        alias := ctxt.Syms.Lookup(elfsym.Name, sym.SymVerABIInternal)
                        if alias.Type != 0 {
                                continue