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 <michael.hudson@canonical.com>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
David Crawshaw 2016-04-01 10:55:21 -04:00
parent 74c0fea9e8
commit 2d5688952d
3 changed files with 6 additions and 4 deletions

View file

@ -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

View file

@ -186,7 +186,7 @@ func UseRelro() bool {
case BuildmodeCShared, BuildmodeShared, BuildmodePIE:
return Iself
default:
return false
return Linkshared
}
}

View file

@ -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