From: Russ Cox Date: Mon, 21 Dec 2020 06:14:36 +0000 (-0500) Subject: [dev.regabi] cmd/compile: setup to move Addrconst, Patch into cmd/internal/obj X-Git-Tag: go1.17beta1~1539^2~290 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2153a99914c3c24b98cd4cfccd1d2f670273a4ac;p=gostls13.git [dev.regabi] cmd/compile: setup to move Addrconst, Patch into cmd/internal/obj Deleting the Pc assignment from Patch is safe because the actual PCs are not assigned until well after the compiler is done patching jumps. And it proves that replacing uses of Patch with SetTarget will be safe later. Change-Id: Iffcbe03f0b5949ccd4c91e79c1272cd06be0f434 Reviewed-on: https://go-review.googlesource.com/c/go/+/279296 Trust: Russ Cox Run-TryBot: Russ Cox TryBot-Result: Go Bot Reviewed-by: Matthew Dempsky --- diff --git a/src/cmd/compile/internal/gc/gsubr.go b/src/cmd/compile/internal/gc/gsubr.go index 79ca669dfb..ddb431d5ab 100644 --- a/src/cmd/compile/internal/gc/gsubr.go +++ b/src/cmd/compile/internal/gc/gsubr.go @@ -321,15 +321,9 @@ func ggloblsym(s *obj.LSym, width int32, flags int16) { } func Addrconst(a *obj.Addr, v int64) { - a.Sym = nil - a.Type = obj.TYPE_CONST - a.Offset = v + a.SetConst(v) } func Patch(p *obj.Prog, to *obj.Prog) { - if p.To.Type != obj.TYPE_BRANCH { - base.Fatalf("patch: not a branch") - } p.To.SetTarget(to) - p.To.Offset = to.Pc } diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go index eaebfaf4b6..7b5c990a5d 100644 --- a/src/cmd/internal/obj/link.go +++ b/src/cmd/internal/obj/link.go @@ -250,6 +250,12 @@ func (a *Addr) SetTarget(t *Prog) { a.Val = t } +func (a *Addr) SetConst(v int64) { + a.Sym = nil + a.Type = TYPE_CONST + a.Offset = v +} + // Prog describes a single machine instruction. // // The general instruction form is: