Skip to content

Commit 9bfaaa1

Browse files
committed
cmd/internal/obj/ppc64: fix rebuilding of optab for asm tests
The end-to-end asm tests reinitialize the assembler using different GOPPC64 values. This caused duplicate entries to amass from the prefix and generated optab entries. This bug only affects the asm end-to-end tests. On reinitialization, optab contains the previous prefixedOptab and optabGen entries, not just the initial values. Rework the initialization to avoid the stale optab entries. Change-Id: I310499915a5272ed0174ed8135d60788e6b4b716 Reviewed-on: https://go-review.googlesource.com/c/go/+/528316 Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Lynn Boger <[email protected]> Reviewed-by: Bryan Mills <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 20944cf commit 9bfaaa1

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/cmd/internal/obj/ppc64/asm9.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ type Optab struct {
9999
//
100100
// Likewise, each slice of optab is dynamically sorted using the ocmp Sort interface
101101
// to arrange entries to minimize text size of each opcode.
102-
var optab = []Optab{
102+
//
103+
// optab is the sorted result of combining optabBase, optabGen, and prefixableOptab.
104+
var optab []Optab
105+
106+
var optabBase = []Optab{
103107
{as: obj.ATEXT, a1: C_LOREG, a6: C_TEXTSIZE, type_: 0, size: 0},
104108
{as: obj.ATEXT, a1: C_LOREG, a3: C_LCON, a6: C_TEXTSIZE, type_: 0, size: 0},
105109
{as: obj.ATEXT, a1: C_ADDR, a6: C_TEXTSIZE, type_: 0, size: 0},
@@ -1303,10 +1307,6 @@ func buildop(ctxt *obj.Link) {
13031307
entry.ispfx = true
13041308
entry.size = entry.pfxsize
13051309
}
1306-
// Use the legacy assembler function if none provided.
1307-
if entry.asmout == nil {
1308-
entry.asmout = asmout
1309-
}
13101310
prefixOptab = append(prefixOptab, entry.Optab)
13111311

13121312
}
@@ -1318,16 +1318,20 @@ func buildop(ctxt *obj.Link) {
13181318
}
13191319
}
13201320
}
1321+
1322+
// Append the generated entries, sort, and fill out oprange.
1323+
optab = make([]Optab, 0, len(optabBase)+len(optabGen)+len(prefixOptab))
1324+
optab = append(optab, optabBase...)
1325+
optab = append(optab, optabGen...)
1326+
optab = append(optab, prefixOptab...)
1327+
sort.Slice(optab, optabLess)
1328+
13211329
for i := range optab {
13221330
// Use the legacy assembler function if none provided.
13231331
if optab[i].asmout == nil {
13241332
optab[i].asmout = asmout
13251333
}
13261334
}
1327-
// Append the generated entries, sort, and fill out oprange.
1328-
optab = append(optab, optabGen...)
1329-
optab = append(optab, prefixOptab...)
1330-
sort.Slice(optab, optabLess)
13311335

13321336
for i := 0; i < len(optab); {
13331337
r := optab[i].as

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package ppc64
77
import (
88
"bytes"
99
"fmt"
10+
"internal/buildcfg"
1011
"internal/testenv"
1112
"math"
1213
"os"
@@ -553,3 +554,18 @@ func TestAddrClassifier(t *testing.T) {
553554
}
554555
}
555556
}
557+
558+
// The optab size should remain constant when reinitializing the PPC64 assembler backend.
559+
func TestOptabReinit(t *testing.T) {
560+
buildcfg.GOOS = "linux"
561+
buildcfg.GOARCH = "ppc64le"
562+
buildcfg.GOPPC64 = 8
563+
buildop(nil)
564+
optabLen := len(optab)
565+
buildcfg.GOPPC64 = 9
566+
buildop(nil)
567+
reinitOptabLen := len(optab)
568+
if reinitOptabLen != optabLen {
569+
t.Errorf("rerunning buildop changes optab size from %d to %d", optabLen, reinitOptabLen)
570+
}
571+
}

0 commit comments

Comments
 (0)