1
0
mirror of https://github.com/golang/go synced 2024-11-24 15:30:13 -07:00

cmd/link: align string data to Minalign when merging strings

Minalign > 1 implies that relocations inserted by the linker cannot
target arbitrary bytes.

Related to #14604

Change-Id: Ie68d14887bc4047d9b29b0cb1149a8d14b6c62e2
Reviewed-on: https://go-review.googlesource.com/20214
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Michael Munday 2016-03-04 10:14:03 -05:00 committed by David Crawshaw
parent 99b6b77e22
commit 4c69e92f51

View File

@ -52,15 +52,21 @@ func mergestrings() {
alldata := Linklookup(Ctxt, "go.string.alldata", 0) alldata := Linklookup(Ctxt, "go.string.alldata", 0)
alldata.Type = obj.SGOSTRING alldata.Type = obj.SGOSTRING
alldata.Attr |= AttrReachable alldata.Attr |= AttrReachable
alldata.Size = int64(size)
alldata.P = make([]byte, 0, size) alldata.P = make([]byte, 0, size)
for _, str := range strs { for _, str := range strs {
off := len(alldata.P) off := len(alldata.P)
alldata.P = append(alldata.P, str.P...) alldata.P = append(alldata.P, str.P...)
// Architectures with Minalign > 1 cannot have relocations pointing
// to arbitrary locations, so make sure each string is appropriately
// aligned.
for r := len(alldata.P) % Thearch.Minalign; r > 0; r-- {
alldata.P = append(alldata.P, 0)
}
str.Attr.Set(AttrReachable, false) str.Attr.Set(AttrReachable, false)
for _, r := range relocsToStrs[str] { for _, r := range relocsToStrs[str] {
r.Add += int64(off) r.Add += int64(off)
r.Sym = alldata r.Sym = alldata
} }
} }
alldata.Size = int64(len(alldata.P))
} }