Skip to content

Commit 1ad3084

Browse files
zhouguangyuan0718cherrymui
authored andcommitted
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 golang#74648 Change-Id: I690fbfacf79e26d7a37628a2551729b2381616c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/696915 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 13c0826 commit 1ad3084

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

src/cmd/internal/obj/x86/asm6.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,19 +2120,6 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
21202120
c0 := c
21212121
c = pjc.padJump(ctxt, s, p, c)
21222122

2123-
if p.As == obj.APCALIGN || p.As == obj.APCALIGNMAX {
2124-
v := obj.AlignmentPadding(c, p, ctxt, s)
2125-
if v > 0 {
2126-
s.Grow(int64(c) + int64(v))
2127-
fillnop(s.P[c:], int(v))
2128-
}
2129-
p.Pc = int64(c)
2130-
c += int32(v)
2131-
pPrev = p
2132-
continue
2133-
2134-
}
2135-
21362123
if maxLoopPad > 0 && p.Back&branchLoopHead != 0 && c&(loopAlign-1) != 0 {
21372124
// pad with NOPs
21382125
v := -c & (loopAlign - 1)
@@ -2165,6 +2152,18 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
21652152
}
21662153
}
21672154

2155+
if p.As == obj.APCALIGN || p.As == obj.APCALIGNMAX {
2156+
v := obj.AlignmentPadding(c, p, ctxt, s)
2157+
if v > 0 {
2158+
s.Grow(int64(c) + int64(v))
2159+
fillnop(s.P[c:], int(v))
2160+
}
2161+
p.Pc = int64(c)
2162+
c += int32(v)
2163+
pPrev = p
2164+
continue
2165+
}
2166+
21682167
p.Rel = nil
21692168

21702169
p.Pc = int64(c)

test/fixedbugs/issue74648.dir/a.s

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
TEXT ·F(SB), $0
6+
JMP prealigned
7+
INT $3 // should never be reached
8+
prealigned:
9+
PCALIGN $0x10
10+
aligned:
11+
RET

test/fixedbugs/issue74648.dir/x.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Issue 74648: wrong jump target when using PCALIGN.
6+
7+
package main
8+
9+
func F()
10+
11+
func main() {
12+
F()
13+
}

test/fixedbugs/issue74648.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// runindir
2+
3+
//go:build amd64
4+
5+
// Copyright 2025 The Go Authors. All rights reserved.
6+
// Use of this source code is governed by a BSD-style
7+
// license that can be found in the LICENSE file.
8+
9+
package ignored

0 commit comments

Comments
 (0)