Commit 2d568895 authored by David Crawshaw's avatar David Crawshaw

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/21394Reviewed-by: default avatarMichael Hudson-Doyle <michael.hudson@canonical.com>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 74c0fea9
...@@ -1271,7 +1271,7 @@ func dodata() { ...@@ -1271,7 +1271,7 @@ func dodata() {
// when building a shared library. We do this by boosting objects of // when building a shared library. We do this by boosting objects of
// type SXXX with relocations to type SXXXRELRO. // type SXXX with relocations to type SXXXRELRO.
for s := datap; s != nil; s = s.Next { 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) s.Type += (obj.STYPERELRO - obj.STYPE)
if s.Outer != nil { if s.Outer != nil {
s.Outer.Type = s.Type s.Outer.Type = s.Type
......
...@@ -186,7 +186,7 @@ func UseRelro() bool { ...@@ -186,7 +186,7 @@ func UseRelro() bool {
case BuildmodeCShared, BuildmodeShared, BuildmodePIE: case BuildmodeCShared, BuildmodeShared, BuildmodePIE:
return Iself return Iself
default: default:
return false return Linkshared
} }
} }
......
...@@ -451,8 +451,10 @@ func symtab() { ...@@ -451,8 +451,10 @@ func symtab() {
continue continue
} }
if strings.HasPrefix(s.Name, "type.") && !DynlinkingGo() { if strings.HasPrefix(s.Name, "type.") {
s.Attr |= AttrHidden if !DynlinkingGo() {
s.Attr |= AttrHidden
}
if UseRelro() && len(s.R) > 0 { if UseRelro() && len(s.R) > 0 {
s.Type = obj.STYPERELRO s.Type = obj.STYPERELRO
s.Outer = symtyperel s.Outer = symtyperel
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment