Skip to content

Commit d6a27e8

Browse files
mwhudsonianlancetaylor
authored andcommitted
cmd/link: never coalesce type descriptors when dynamically linking Go
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 899e0e3 commit d6a27e8

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
package main
22

33
func main() {
4+
// This is enough to make sure that the executable references
5+
// a type descriptor, which was the cause of
6+
// https://golang.org/issue/25970.
7+
c := make(chan int)
8+
_ = c
49
}

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

+20-18
Original file line numberDiff line numberDiff line change
@@ -368,28 +368,30 @@ func (ctxt *Link) symtab() {
368368
// pseudo-symbols to mark locations of type, string, and go string data.
369369
var symtype *sym.Symbol
370370
var symtyperel *sym.Symbol
371-
if ctxt.UseRelro() && (ctxt.BuildMode == BuildModeCArchive || ctxt.BuildMode == BuildModeCShared || ctxt.BuildMode == BuildModePIE) {
372-
s = ctxt.Syms.Lookup("type.*", 0)
371+
if !ctxt.DynlinkingGo() {
372+
if ctxt.UseRelro() && (ctxt.BuildMode == BuildModeCArchive || ctxt.BuildMode == BuildModeCShared || ctxt.BuildMode == BuildModePIE) {
373+
s = ctxt.Syms.Lookup("type.*", 0)
373374

374-
s.Type = sym.STYPE
375-
s.Size = 0
376-
s.Attr |= sym.AttrReachable
377-
symtype = s
375+
s.Type = sym.STYPE
376+
s.Size = 0
377+
s.Attr |= sym.AttrReachable
378+
symtype = s
378379

379-
s = ctxt.Syms.Lookup("typerel.*", 0)
380+
s = ctxt.Syms.Lookup("typerel.*", 0)
380381

381-
s.Type = sym.STYPERELRO
382-
s.Size = 0
383-
s.Attr |= sym.AttrReachable
384-
symtyperel = s
385-
} else if !ctxt.DynlinkingGo() {
386-
s = ctxt.Syms.Lookup("type.*", 0)
382+
s.Type = sym.STYPERELRO
383+
s.Size = 0
384+
s.Attr |= sym.AttrReachable
385+
symtyperel = s
386+
} else {
387+
s = ctxt.Syms.Lookup("type.*", 0)
387388

388-
s.Type = sym.STYPE
389-
s.Size = 0
390-
s.Attr |= sym.AttrReachable
391-
symtype = s
392-
symtyperel = s
389+
s.Type = sym.STYPE
390+
s.Size = 0
391+
s.Attr |= sym.AttrReachable
392+
symtype = s
393+
symtyperel = s
394+
}
393395
}
394396

395397
groupSym := func(name string, t sym.SymKind) *sym.Symbol {

0 commit comments

Comments
 (0)