Skip to content

Commit 37b194a

Browse files
cmd/link: put shlib ".type" functions in internal ABI
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Austin Clements <[email protected]>
1 parent 24a6ca0 commit 37b194a

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

misc/cgo/testshared/shared_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,3 +941,10 @@ func TestTestInstalledShared(t *testing.T) {
941941
func TestGeneratedMethod(t *testing.T) {
942942
goCmd(t, "install", "-buildmode=shared", "-linkshared", "./issue25065")
943943
}
944+
945+
// Test use of shared library struct with generated hash function.
946+
// Issue 30768.
947+
func TestGeneratedHash(t *testing.T) {
948+
goCmd(nil, "install", "-buildmode=shared", "-linkshared", "./issue30768/issue30768lib")
949+
goCmd(nil, "test", "-linkshared", "./issue30768")
950+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2019 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package issue30768lib
6+
7+
// S is a struct that requires a generated hash function.
8+
type S struct {
9+
A string
10+
B int
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2019 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package issue30768_test
6+
7+
import (
8+
"testing"
9+
10+
"testshared/issue30768/issue30768lib"
11+
)
12+
13+
type s struct {
14+
s issue30768lib.S
15+
}
16+
17+
func Test30768(t *testing.T) {
18+
// Calling t.Log will convert S to an empty interface,
19+
// which will force a reference to the generated hash function,
20+
// defined in the shared library.
21+
t.Log(s{})
22+
}

src/cmd/link/internal/ld/lib.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,15 @@ func ldshlibsyms(ctxt *Link, shlib string) {
19021902
if elf.ST_TYPE(elfsym.Info) == elf.STT_NOTYPE || elf.ST_TYPE(elfsym.Info) == elf.STT_SECTION {
19031903
continue
19041904
}
1905-
lsym := ctxt.Syms.Lookup(elfsym.Name, 0)
1905+
1906+
// Symbols whose names start with "type." are compiler
1907+
// generated, so make functions with that prefix internal.
1908+
ver := 0
1909+
if elf.ST_TYPE(elfsym.Info) == elf.STT_FUNC && strings.HasPrefix(elfsym.Name, "type.") {
1910+
ver = sym.SymVerABIInternal
1911+
}
1912+
1913+
lsym := ctxt.Syms.Lookup(elfsym.Name, ver)
19061914
// Because loadlib above loads all .a files before loading any shared
19071915
// libraries, any non-dynimport symbols we find that duplicate symbols
19081916
// already loaded should be ignored (the symbols from the .a files
@@ -1930,7 +1938,7 @@ func ldshlibsyms(ctxt *Link, shlib string) {
19301938
// the ABIs are actually different. We might have to
19311939
// mangle Go function names in the .so to include the
19321940
// ABI.
1933-
if elf.ST_TYPE(elfsym.Info) == elf.STT_FUNC {
1941+
if elf.ST_TYPE(elfsym.Info) == elf.STT_FUNC && ver == 0 {
19341942
alias := ctxt.Syms.Lookup(elfsym.Name, sym.SymVerABIInternal)
19351943
if alias.Type != 0 {
19361944
continue

0 commit comments

Comments
 (0)