mirror of
https://github.com/golang/go.git
synced 2025-10-19 19:13:18 +00:00
cmd/asm: process forward jump to PCALIGN
The forward jump target are not processed when the target is PCALIGN, so process it before emit nops for PCALIGN. Fixes #74648 Change-Id: I690fbfacf79e26d7a37628a2551729b2381616c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/696915 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
parent
13c082601d
commit
1ad30844d9
4 changed files with 45 additions and 13 deletions
|
@ -2120,19 +2120,6 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
|
||||||
c0 := c
|
c0 := c
|
||||||
c = pjc.padJump(ctxt, s, p, c)
|
c = pjc.padJump(ctxt, s, p, c)
|
||||||
|
|
||||||
if p.As == obj.APCALIGN || p.As == obj.APCALIGNMAX {
|
|
||||||
v := obj.AlignmentPadding(c, p, ctxt, s)
|
|
||||||
if v > 0 {
|
|
||||||
s.Grow(int64(c) + int64(v))
|
|
||||||
fillnop(s.P[c:], int(v))
|
|
||||||
}
|
|
||||||
p.Pc = int64(c)
|
|
||||||
c += int32(v)
|
|
||||||
pPrev = p
|
|
||||||
continue
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if maxLoopPad > 0 && p.Back&branchLoopHead != 0 && c&(loopAlign-1) != 0 {
|
if maxLoopPad > 0 && p.Back&branchLoopHead != 0 && c&(loopAlign-1) != 0 {
|
||||||
// pad with NOPs
|
// pad with NOPs
|
||||||
v := -c & (loopAlign - 1)
|
v := -c & (loopAlign - 1)
|
||||||
|
@ -2165,6 +2152,18 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p.As == obj.APCALIGN || p.As == obj.APCALIGNMAX {
|
||||||
|
v := obj.AlignmentPadding(c, p, ctxt, s)
|
||||||
|
if v > 0 {
|
||||||
|
s.Grow(int64(c) + int64(v))
|
||||||
|
fillnop(s.P[c:], int(v))
|
||||||
|
}
|
||||||
|
p.Pc = int64(c)
|
||||||
|
c += int32(v)
|
||||||
|
pPrev = p
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
p.Rel = nil
|
p.Rel = nil
|
||||||
|
|
||||||
p.Pc = int64(c)
|
p.Pc = int64(c)
|
||||||
|
|
11
test/fixedbugs/issue74648.dir/a.s
Normal file
11
test/fixedbugs/issue74648.dir/a.s
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
// Copyright 2025 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
TEXT ·F(SB), $0
|
||||||
|
JMP prealigned
|
||||||
|
INT $3 // should never be reached
|
||||||
|
prealigned:
|
||||||
|
PCALIGN $0x10
|
||||||
|
aligned:
|
||||||
|
RET
|
13
test/fixedbugs/issue74648.dir/x.go
Normal file
13
test/fixedbugs/issue74648.dir/x.go
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// Copyright 2025 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Issue 74648: wrong jump target when using PCALIGN.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
func F()
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
F()
|
||||||
|
}
|
9
test/fixedbugs/issue74648.go
Normal file
9
test/fixedbugs/issue74648.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// runindir
|
||||||
|
|
||||||
|
//go:build amd64
|
||||||
|
|
||||||
|
// Copyright 2025 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package ignored
|
Loading…
Add table
Add a link
Reference in a new issue