Commit 2a031e6a authored by Shenghou Ma's avatar Shenghou Ma Committed by Minux Ma

cmd/internal/obj/arm64: rewrite branches that are too far

Fixes #12540.

Change-Id: I7893fdc023145b0aca4b4c7df7e08e47edcf5bba
Reviewed-on: https://go-review.googlesource.com/16902
Run-TryBot: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent ec9aae77
...@@ -535,9 +535,9 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) { ...@@ -535,9 +535,9 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) {
buildop(ctxt) buildop(ctxt)
} }
bflag := 0 bflag := 1
c := int32(0) c := int64(0)
p.Pc = int64(c) p.Pc = c
var m int var m int
var o *Optab var o *Optab
for p = p.Link; p != nil; p = p.Link { for p = p.Link; p != nil; p = p.Link {
...@@ -545,7 +545,7 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) { ...@@ -545,7 +545,7 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) {
if p.As == ADWORD && (c&7) != 0 { if p.As == ADWORD && (c&7) != 0 {
c += 4 c += 4
} }
p.Pc = int64(c) p.Pc = c
o = oplook(ctxt, p) o = oplook(ctxt, p)
m = int(o.size) m = int(o.size)
if m == 0 { if m == 0 {
...@@ -567,13 +567,13 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) { ...@@ -567,13 +567,13 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) {
if p.As == AB || p.As == obj.ARET || p.As == AERET { /* TODO: other unconditional operations */ if p.As == AB || p.As == obj.ARET || p.As == AERET { /* TODO: other unconditional operations */
checkpool(ctxt, p, 0) checkpool(ctxt, p, 0)
} }
c += int32(m) c += int64(m)
if ctxt.Blitrl != nil { if ctxt.Blitrl != nil {
checkpool(ctxt, p, 1) checkpool(ctxt, p, 1)
} }
} }
cursym.Size = int64(c) cursym.Size = c
/* /*
* if any procedure is large enough to * if any procedure is large enough to
...@@ -582,38 +582,38 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) { ...@@ -582,38 +582,38 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) {
* around jmps to fix. this is rare. * around jmps to fix. this is rare.
*/ */
for bflag != 0 { for bflag != 0 {
if ctxt.Debugvlog != 0 {
fmt.Fprintf(ctxt.Bso, "%5.2f span1\n", obj.Cputime())
}
bflag = 0 bflag = 0
c = 0 c = 0
for p = cursym.Text; p != nil; p = p.Link { for p = cursym.Text.Link; p != nil; p = p.Link {
if p.As == ADWORD && (c&7) != 0 { if p.As == ADWORD && (c&7) != 0 {
c += 4 c += 4
} }
p.Pc = int64(c) p.Pc = c
o = oplook(ctxt, p) o = oplook(ctxt, p)
/* very large branches /* very large branches */
if(o->type == 6 && p->cond) { if o.type_ == 7 && p.Pcond != nil {
otxt = p->cond->pc - c; otxt := p.Pcond.Pc - c
if(otxt < 0) if otxt <= -(1<<18)+10 || otxt >= (1<<18)-10 {
otxt = -otxt; q := ctxt.NewProg()
if(otxt >= (1L<<17) - 10) { q.Link = p.Link
q = ctxt->arch->prg(); p.Link = q
q->link = p->link; q.As = AB
p->link = q; q.To.Type = obj.TYPE_BRANCH
q->as = AB; q.Pcond = p.Pcond
q->to.type = obj.TYPE_BRANCH; p.Pcond = q
q->cond = p->cond; q = ctxt.NewProg()
p->cond = q; q.Link = p.Link
q = ctxt->arch->prg(); p.Link = q
q->link = p->link; q.As = AB
p->link = q; q.To.Type = obj.TYPE_BRANCH
q->as = AB; q.Pcond = q.Link.Link
q->to.type = obj.TYPE_BRANCH; bflag = 1
q->cond = q->link->link;
bflag = 1;
} }
} }
*/
m = int(o.size) m = int(o.size)
if m == 0 { if m == 0 {
...@@ -623,12 +623,12 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) { ...@@ -623,12 +623,12 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) {
continue continue
} }
c += int32(m) c += int64(m)
} }
} }
c += -c & (FuncAlign - 1) c += -c & (FuncAlign - 1)
cursym.Size = int64(c) cursym.Size = c
/* /*
* lay out the code, emitting code and data relocations. * lay out the code, emitting code and data relocations.
......
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