]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: never coalesce type descriptors when dynamically linking Go
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Wed, 20 Jun 2018 22:31:57 +0000 (10:31 +1200)
committerIan Lance Taylor <iant@golang.org>
Sat, 23 Jun 2018 00:16:14 +0000 (00:16 +0000)
Add a test by making misc/cgo/testshared/src/trivial.go marginally less
trivial.

Fixes #25970.

Change-Id: I8815d0c56b8850fcdbf9b45f8406f37bd21b6865
Reviewed-on: https://go-review.googlesource.com/120235
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
misc/cgo/testshared/src/trivial/trivial.go
src/cmd/link/internal/ld/symtab.go

index da29a2cadf1e00b14b1a4bd0a52780888bf3e532..6ade47ce36fb6ff469a0c5bf05b283b2238f91d7 100644 (file)
@@ -1,4 +1,9 @@
 package main
 
 func main() {
+       // This is enough to make sure that the executable references
+       // a type descriptor, which was the cause of
+       // https://golang.org/issue/25970.
+       c := make(chan int)
+       _ = c
 }
index bb8c1992ba877ad2055271a9fa2aead4b859f6c7..88d476710b93795df4b1549adc6e6d514055237a 100644 (file)
@@ -368,28 +368,30 @@ func (ctxt *Link) symtab() {
        // pseudo-symbols to mark locations of type, string, and go string data.
        var symtype *sym.Symbol
        var symtyperel *sym.Symbol
-       if ctxt.UseRelro() && (ctxt.BuildMode == BuildModeCArchive || ctxt.BuildMode == BuildModeCShared || ctxt.BuildMode == BuildModePIE) {
-               s = ctxt.Syms.Lookup("type.*", 0)
+       if !ctxt.DynlinkingGo() {
+               if ctxt.UseRelro() && (ctxt.BuildMode == BuildModeCArchive || ctxt.BuildMode == BuildModeCShared || ctxt.BuildMode == BuildModePIE) {
+                       s = ctxt.Syms.Lookup("type.*", 0)
 
-               s.Type = sym.STYPE
-               s.Size = 0
-               s.Attr |= sym.AttrReachable
-               symtype = s
+                       s.Type = sym.STYPE
+                       s.Size = 0
+                       s.Attr |= sym.AttrReachable
+                       symtype = s
 
-               s = ctxt.Syms.Lookup("typerel.*", 0)
+                       s = ctxt.Syms.Lookup("typerel.*", 0)
 
-               s.Type = sym.STYPERELRO
-               s.Size = 0
-               s.Attr |= sym.AttrReachable
-               symtyperel = s
-       } else if !ctxt.DynlinkingGo() {
-               s = ctxt.Syms.Lookup("type.*", 0)
+                       s.Type = sym.STYPERELRO
+                       s.Size = 0
+                       s.Attr |= sym.AttrReachable
+                       symtyperel = s
+               } else {
+                       s = ctxt.Syms.Lookup("type.*", 0)
 
-               s.Type = sym.STYPE
-               s.Size = 0
-               s.Attr |= sym.AttrReachable
-               symtype = s
-               symtyperel = s
+                       s.Type = sym.STYPE
+                       s.Size = 0
+                       s.Attr |= sym.AttrReachable
+                       symtype = s
+                       symtyperel = s
+               }
        }
 
        groupSym := func(name string, t sym.SymKind) *sym.Symbol {