From: David Crawshaw Date: Fri, 1 Apr 2016 14:55:21 +0000 (-0400) Subject: cmd/link: keep types together when dynamic linking X-Git-Tag: go1.7beta1~922 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2d5688952db33fc967a23011c22fa8fc71251fb1;p=gostls13.git cmd/link: keep types together when dynamic linking To refer to types and names by offsets, we want to keep the symbols in the same sections. Do this by making all types .relro for now. Once name offsets are further along, name data can move out of relro. Change-Id: I1cbd2e914bd180cdf25c4aeb13d9c1c734febe69 Reviewed-on: https://go-review.googlesource.com/21394 Reviewed-by: Michael Hudson-Doyle Run-TryBot: David Crawshaw TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index b658cc4f5c..fe74cc9208 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -1271,7 +1271,7 @@ func dodata() { // when building a shared library. We do this by boosting objects of // type SXXX with relocations to type SXXXRELRO. for s := datap; s != nil; s = s.Next { - if (s.Type >= obj.STYPE && s.Type <= obj.SFUNCTAB && len(s.R) > 0) || s.Type == obj.SGOSTRINGHDR { + if (s.Type >= obj.STYPE && s.Type <= obj.SFUNCTAB && len(s.R) > 0) || s.Type == obj.STYPE || s.Type == obj.SGOSTRINGHDR { s.Type += (obj.STYPERELRO - obj.STYPE) if s.Outer != nil { s.Outer.Type = s.Type diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 2a3f4298f5..5616700445 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -186,7 +186,7 @@ func UseRelro() bool { case BuildmodeCShared, BuildmodeShared, BuildmodePIE: return Iself default: - return false + return Linkshared } } diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go index 3f8784f996..3258bc1ff9 100644 --- a/src/cmd/link/internal/ld/symtab.go +++ b/src/cmd/link/internal/ld/symtab.go @@ -451,8 +451,10 @@ func symtab() { continue } - if strings.HasPrefix(s.Name, "type.") && !DynlinkingGo() { - s.Attr |= AttrHidden + if strings.HasPrefix(s.Name, "type.") { + if !DynlinkingGo() { + s.Attr |= AttrHidden + } if UseRelro() && len(s.R) > 0 { s.Type = obj.STYPERELRO s.Outer = symtyperel