Skip to content

Commit ce842c5

Browse files
cherrymuidmitshur
authored andcommitted
[release-branch.go1.10] cmd/internal/obj/arm64: fix branch-too-far with TBZ like instructions
The compiler now emits TBZ like instructions, but the assembler's too-far-branch patch code didn't include that case. Add it. Updates #23889 Fixes #25794 Change-Id: Ib75f9250c660b9fb652835fbc83263a5d5073dc5 Reviewed-on: https://go-review.googlesource.com/94902 Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: David Chase <[email protected]> (cherry picked from commit 911839c) Reviewed-on: https://go-review.googlesource.com/c/147057 Reviewed-by: Cherry Zhang <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]>
1 parent 13a2f53 commit ce842c5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,16 @@ func span7(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
696696
o = c.oplook(p)
697697

698698
/* very large branches */
699-
if (o.type_ == 7 || o.type_ == 39) && p.Pcond != nil { // 7: BEQ and like, 39: CBZ and like
699+
if (o.type_ == 7 || o.type_ == 39 || o.type_ == 40) && p.Pcond != nil { // 7: BEQ and like, 39: CBZ and like, 40: TBZ and like
700700
otxt := p.Pcond.Pc - pc
701-
if otxt <= -(1<<18)+10 || otxt >= (1<<18)-10 {
701+
var toofar bool
702+
switch o.type_ {
703+
case 7, 39: // branch instruction encodes 19 bits
704+
toofar = otxt <= -(1<<20)+10 || otxt >= (1<<20)-10
705+
case 40: // branch instruction encodes 14 bits
706+
toofar = otxt <= -(1<<15)+10 || otxt >= (1<<15)-10
707+
}
708+
if toofar {
702709
q := c.newprog()
703710
q.Link = p.Link
704711
p.Link = q

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func TestLarge(t *testing.T) {
5252
// gen generates a very large program, with a very far conditional branch.
5353
func gen(buf *bytes.Buffer) {
5454
fmt.Fprintln(buf, "TEXT f(SB),0,$0-0")
55+
fmt.Fprintln(buf, "TBZ $5, R0, label")
5556
fmt.Fprintln(buf, "CBZ R0, label")
5657
fmt.Fprintln(buf, "BEQ label")
5758
for i := 0; i < 1<<19; i++ {

0 commit comments

Comments
 (0)