Skip to content

Commit 2a031e6

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent ec9aae7 commit 2a031e6

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/cmd/internal/obj/arm64/asm7.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -535,17 +535,17 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) {
535535
buildop(ctxt)
536536
}
537537

538-
bflag := 0
539-
c := int32(0)
540-
p.Pc = int64(c)
538+
bflag := 1
539+
c := int64(0)
540+
p.Pc = c
541541
var m int
542542
var o *Optab
543543
for p = p.Link; p != nil; p = p.Link {
544544
ctxt.Curp = p
545545
if p.As == ADWORD && (c&7) != 0 {
546546
c += 4
547547
}
548-
p.Pc = int64(c)
548+
p.Pc = c
549549
o = oplook(ctxt, p)
550550
m = int(o.size)
551551
if m == 0 {
@@ -567,13 +567,13 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) {
567567
if p.As == AB || p.As == obj.ARET || p.As == AERET { /* TODO: other unconditional operations */
568568
checkpool(ctxt, p, 0)
569569
}
570-
c += int32(m)
570+
c += int64(m)
571571
if ctxt.Blitrl != nil {
572572
checkpool(ctxt, p, 1)
573573
}
574574
}
575575

576-
cursym.Size = int64(c)
576+
cursym.Size = c
577577

578578
/*
579579
* if any procedure is large enough to
@@ -582,38 +582,38 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) {
582582
* around jmps to fix. this is rare.
583583
*/
584584
for bflag != 0 {
585+
if ctxt.Debugvlog != 0 {
586+
fmt.Fprintf(ctxt.Bso, "%5.2f span1\n", obj.Cputime())
587+
}
585588
bflag = 0
586589
c = 0
587-
for p = cursym.Text; p != nil; p = p.Link {
590+
for p = cursym.Text.Link; p != nil; p = p.Link {
588591
if p.As == ADWORD && (c&7) != 0 {
589592
c += 4
590593
}
591-
p.Pc = int64(c)
594+
p.Pc = c
592595
o = oplook(ctxt, p)
593596

594-
/* very large branches
595-
if(o->type == 6 && p->cond) {
596-
otxt = p->cond->pc - c;
597-
if(otxt < 0)
598-
otxt = -otxt;
599-
if(otxt >= (1L<<17) - 10) {
600-
q = ctxt->arch->prg();
601-
q->link = p->link;
602-
p->link = q;
603-
q->as = AB;
604-
q->to.type = obj.TYPE_BRANCH;
605-
q->cond = p->cond;
606-
p->cond = q;
607-
q = ctxt->arch->prg();
608-
q->link = p->link;
609-
p->link = q;
610-
q->as = AB;
611-
q->to.type = obj.TYPE_BRANCH;
612-
q->cond = q->link->link;
613-
bflag = 1;
597+
/* very large branches */
598+
if o.type_ == 7 && p.Pcond != nil {
599+
otxt := p.Pcond.Pc - c
600+
if otxt <= -(1<<18)+10 || otxt >= (1<<18)-10 {
601+
q := ctxt.NewProg()
602+
q.Link = p.Link
603+
p.Link = q
604+
q.As = AB
605+
q.To.Type = obj.TYPE_BRANCH
606+
q.Pcond = p.Pcond
607+
p.Pcond = q
608+
q = ctxt.NewProg()
609+
q.Link = p.Link
610+
p.Link = q
611+
q.As = AB
612+
q.To.Type = obj.TYPE_BRANCH
613+
q.Pcond = q.Link.Link
614+
bflag = 1
614615
}
615616
}
616-
*/
617617
m = int(o.size)
618618

619619
if m == 0 {
@@ -623,12 +623,12 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) {
623623
continue
624624
}
625625

626-
c += int32(m)
626+
c += int64(m)
627627
}
628628
}
629629

630630
c += -c & (FuncAlign - 1)
631-
cursym.Size = int64(c)
631+
cursym.Size = c
632632

633633
/*
634634
* lay out the code, emitting code and data relocations.

0 commit comments

Comments
 (0)