[dev.link] cmd/link: fix payload pointer liveness

Currently, the symbol updater uses a pointer pointing to the
loader's payloads array. If the payloads slice grows (and moves),
the pointer may become stale and no longer point to the symbol's
actual payload. Specifically, consider

	sb, sym := l.MakeSymbolUpdater(...)
	// add a bunch of external symbols, which grows payload slice
	sb.SetType(t)
	l.SymType(sym) // may not return t

sb.SetType on line 3 may not have the desired effect, as
sb.extSymPayload may no longer point to the right payload. As a
result, the type we get on line 4 may be not the one we set.

Fix this by making the payload's address permanent. Once it is
allocated it will never move.

Change-Id: Iab190ea5aceb5c37f91d09ad4ffd458e881b03f4
Reviewed-on: https://go-review.googlesource.com/c/go/+/217063
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
Cherry Zhang 2020-01-29 22:10:51 -05:00
parent af98efc545
commit b1f9f47982
3 changed files with 34 additions and 12 deletions

View file

@ -28,7 +28,7 @@ func (l *Loader) MakeSymbolBuilder(name string) *SymbolBuilder {
panic("can't build if sym.Symbol already present")
}
sb := &SymbolBuilder{l: l, symIdx: symIdx}
sb.extSymPayload = &l.payloads[symIdx-l.extStart]
sb.extSymPayload = l.payloads[symIdx-l.extStart]
return sb
}
@ -53,7 +53,7 @@ func (l *Loader) MakeSymbolUpdater(symIdx Sym) (*SymbolBuilder, Sym) {
// Construct updater and return.
sb := &SymbolBuilder{l: l, symIdx: symIdx}
sb.extSymPayload = &l.payloads[symIdx-l.extStart]
sb.extSymPayload = l.payloads[symIdx-l.extStart]
return sb, symIdx
}