diff options
| author | Paul E. Murphy <murp@ibm.com> | 2023-09-12 15:39:56 -0500 |
|---|---|---|
| committer | Paul Murphy <murp@ibm.com> | 2023-09-29 14:58:44 +0000 |
| commit | 9bfaaa15fd38f10ba7f11eb6cc67c6dfb21454e6 (patch) | |
| tree | 2dd6b8000656744d1b2ebc74c2c3ece0811aac71 /src | |
| parent | 20944cf0665a5aec6abab802875a9700592b5391 (diff) | |
| download | go-9bfaaa15fd38f10ba7f11eb6cc67c6dfb21454e6.tar.xz | |
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 <thanm@google.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/internal/obj/ppc64/asm9.go | 22 | ||||
| -rw-r--r-- | src/cmd/internal/obj/ppc64/asm_test.go | 16 |
2 files changed, 29 insertions, 9 deletions
diff --git a/src/cmd/internal/obj/ppc64/asm9.go b/src/cmd/internal/obj/ppc64/asm9.go index c1207b01f9..4ce506cbf9 100644 --- a/src/cmd/internal/obj/ppc64/asm9.go +++ b/src/cmd/internal/obj/ppc64/asm9.go @@ -99,7 +99,11 @@ type Optab struct { // // Likewise, each slice of optab is dynamically sorted using the ocmp Sort interface // to arrange entries to minimize text size of each opcode. -var optab = []Optab{ +// +// optab is the sorted result of combining optabBase, optabGen, and prefixableOptab. +var optab []Optab + +var optabBase = []Optab{ {as: obj.ATEXT, a1: C_LOREG, a6: C_TEXTSIZE, type_: 0, size: 0}, {as: obj.ATEXT, a1: C_LOREG, a3: C_LCON, a6: C_TEXTSIZE, type_: 0, size: 0}, {as: obj.ATEXT, a1: C_ADDR, a6: C_TEXTSIZE, type_: 0, size: 0}, @@ -1303,10 +1307,6 @@ func buildop(ctxt *obj.Link) { entry.ispfx = true entry.size = entry.pfxsize } - // Use the legacy assembler function if none provided. - if entry.asmout == nil { - entry.asmout = asmout - } prefixOptab = append(prefixOptab, entry.Optab) } @@ -1318,16 +1318,20 @@ func buildop(ctxt *obj.Link) { } } } + + // Append the generated entries, sort, and fill out oprange. + optab = make([]Optab, 0, len(optabBase)+len(optabGen)+len(prefixOptab)) + optab = append(optab, optabBase...) + optab = append(optab, optabGen...) + optab = append(optab, prefixOptab...) + sort.Slice(optab, optabLess) + for i := range optab { // Use the legacy assembler function if none provided. if optab[i].asmout == nil { optab[i].asmout = asmout } } - // Append the generated entries, sort, and fill out oprange. - optab = append(optab, optabGen...) - optab = append(optab, prefixOptab...) - sort.Slice(optab, optabLess) for i := 0; i < len(optab); { r := optab[i].as diff --git a/src/cmd/internal/obj/ppc64/asm_test.go b/src/cmd/internal/obj/ppc64/asm_test.go index 433df5c8aa..87d4156ef9 100644 --- a/src/cmd/internal/obj/ppc64/asm_test.go +++ b/src/cmd/internal/obj/ppc64/asm_test.go @@ -7,6 +7,7 @@ package ppc64 import ( "bytes" "fmt" + "internal/buildcfg" "internal/testenv" "math" "os" @@ -553,3 +554,18 @@ func TestAddrClassifier(t *testing.T) { } } } + +// The optab size should remain constant when reinitializing the PPC64 assembler backend. +func TestOptabReinit(t *testing.T) { + buildcfg.GOOS = "linux" + buildcfg.GOARCH = "ppc64le" + buildcfg.GOPPC64 = 8 + buildop(nil) + optabLen := len(optab) + buildcfg.GOPPC64 = 9 + buildop(nil) + reinitOptabLen := len(optab) + if reinitOptabLen != optabLen { + t.Errorf("rerunning buildop changes optab size from %d to %d", optabLen, reinitOptabLen) + } +} |
