From 740043f516f716fe359ffd3bd76f1a30a9aa5eec Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sun, 23 Jun 2024 15:21:28 -0700 Subject: [PATCH 1/3] net/netip: unexport fields of addrDetail For #68113 Change-Id: I19c7d8eff8e3a7a1b6c8e28cb867edeca6be237d Reviewed-on: https://go-review.googlesource.com/c/go/+/593737 Auto-Submit: Ian Lance Taylor Reviewed-by: Michael Knyszek Commit-Queue: Ian Lance Taylor Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor --- src/net/netip/export_test.go | 4 ++++ src/net/netip/netip.go | 10 +++++----- src/net/netip/netip_test.go | 8 ++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/net/netip/export_test.go b/src/net/netip/export_test.go index 4febcad893..b2fae1aa47 100644 --- a/src/net/netip/export_test.go +++ b/src/net/netip/export_test.go @@ -16,6 +16,10 @@ type Uint128 = uint128 type AddrDetail = addrDetail +func MakeAddrDetail(isV6 bool, zoneV6 string) AddrDetail { + return AddrDetail{isV6: isV6, zoneV6: zoneV6} +} + func Mk128(hi, lo uint64) Uint128 { return uint128{hi, lo} } diff --git a/src/net/netip/netip.go b/src/net/netip/netip.go index 57063eeb71..a1e93cb29b 100644 --- a/src/net/netip/netip.go +++ b/src/net/netip/netip.go @@ -59,8 +59,8 @@ type Addr struct { // addrDetail represents the details of an Addr, like address family and IPv6 zone. type addrDetail struct { - IsV6 bool // IPv4 is false, IPv6 is true. - ZoneV6 string // != "" only if IsV6 is true. + isV6 bool // IPv4 is false, IPv6 is true. + zoneV6 string // != "" only if IsV6 is true. } // z0, z4, and z6noz are sentinel Addr.z values. @@ -68,7 +68,7 @@ type addrDetail struct { var ( z0 unique.Handle[addrDetail] z4 = unique.Make(addrDetail{}) - z6noz = unique.Make(addrDetail{IsV6: true}) + z6noz = unique.Make(addrDetail{isV6: true}) ) // IPv6LinkLocalAllNodes returns the IPv6 link-local all nodes multicast @@ -410,7 +410,7 @@ func (ip Addr) Zone() string { if ip.z == z0 { return "" } - return ip.z.Value().ZoneV6 + return ip.z.Value().zoneV6 } // Compare returns an integer comparing two IPs. @@ -495,7 +495,7 @@ func (ip Addr) WithZone(zone string) Addr { ip.z = z6noz return ip } - ip.z = unique.Make(addrDetail{IsV6: true, ZoneV6: zone}) + ip.z = unique.Make(addrDetail{isV6: true, zoneV6: zone}) return ip } diff --git a/src/net/netip/netip_test.go b/src/net/netip/netip_test.go index ad0e754208..94c70f2290 100644 --- a/src/net/netip/netip_test.go +++ b/src/net/netip/netip_test.go @@ -112,18 +112,18 @@ func TestParseAddr(t *testing.T) { // IPv6 with a zone specifier. { in: "fd7a:115c:a1e0:ab12:4843:cd96:626b:430b%eth0", - ip: MkAddr(Mk128(0xfd7a115ca1e0ab12, 0x4843cd96626b430b), unique.Make(AddrDetail{IsV6: true, ZoneV6: "eth0"})), + ip: MkAddr(Mk128(0xfd7a115ca1e0ab12, 0x4843cd96626b430b), unique.Make(MakeAddrDetail(true, "eth0"))), }, // IPv6 with dotted decimal and zone specifier. { in: "1:2::ffff:192.168.140.255%eth1", - ip: MkAddr(Mk128(0x0001000200000000, 0x0000ffffc0a88cff), unique.Make(AddrDetail{IsV6: true, ZoneV6: "eth1"})), + ip: MkAddr(Mk128(0x0001000200000000, 0x0000ffffc0a88cff), unique.Make(MakeAddrDetail(true, "eth1"))), str: "1:2::ffff:c0a8:8cff%eth1", }, // 4-in-6 with zone { in: "::ffff:192.168.140.255%eth1", - ip: MkAddr(Mk128(0, 0x0000ffffc0a88cff), unique.Make(AddrDetail{IsV6: true, ZoneV6: "eth1"})), + ip: MkAddr(Mk128(0, 0x0000ffffc0a88cff), unique.Make(MakeAddrDetail(true, "eth1"))), str: "::ffff:192.168.140.255%eth1", }, // IPv6 with capital letters. @@ -1723,7 +1723,7 @@ var parseBenchInputs = []struct { } func BenchmarkParseAddr(b *testing.B) { - sinkInternValue = unique.Make(AddrDetail{IsV6: true, ZoneV6: "eth1"}) // Pin to not benchmark the intern package + sinkInternValue = unique.Make(MakeAddrDetail(true, "eth1")) // Pin to not benchmark the intern package for _, test := range parseBenchInputs { b.Run(test.name, func(b *testing.B) { b.ReportAllocs() From 085cf0fcdc4faa2f473839f8cc1860ec5bcf97a3 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 24 Jun 2024 07:57:45 -0700 Subject: [PATCH 2/3] net/netip: add test that Compare and reflect.DeepEqual match Updates #68113 Change-Id: I1107686ef364f77f48f55534ea8ec68d1785e1e6 Reviewed-on: https://go-review.googlesource.com/c/go/+/594375 Auto-Submit: Brad Fitzpatrick LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor Reviewed-by: Michael Knyszek --- src/net/netip/netip_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/net/netip/netip_test.go b/src/net/netip/netip_test.go index 94c70f2290..e1a0a83f64 100644 --- a/src/net/netip/netip_test.go +++ b/src/net/netip/netip_test.go @@ -893,6 +893,15 @@ func TestAddrLessCompare(t *testing.T) { {mustIP("::1%a"), mustIP("::1%b"), true}, {mustIP("::1%a"), mustIP("::1%a"), false}, {mustIP("::1%b"), mustIP("::1%a"), false}, + + // For Issue 68113, verify that an IPv4 address and a + // v4-mapped-IPv6 address differing only in their zone + // pointer are unequal via all three of + // ==/Compare/reflect.DeepEqual. In Go 1.22 and + // earlier, these were accidentally equal via + // DeepEqual due to their zone pointers (z) differing + // but pointing to identical structures. + {mustIP("::ffff:11.1.1.12"), mustIP("11.1.1.12"), false}, } for _, tt := range tests { got := tt.a.Less(tt.b) @@ -920,6 +929,12 @@ func TestAddrLessCompare(t *testing.T) { t.Errorf("Less(%q, %q) was correctly %v, but so was Less(%q, %q)", tt.a, tt.b, got, tt.b, tt.a) } } + + // Also check reflect.DeepEqual. See issue 68113. + deepEq := reflect.DeepEqual(tt.a, tt.b) + if (cmp == 0) != deepEq { + t.Errorf("%q and %q differ in == (%v) vs reflect.DeepEqual (%v)", tt.a, tt.b, cmp == 0, deepEq) + } } // And just sort. From 0def9d5c02166b50a011b4cc8d4c1d891a04f89d Mon Sep 17 00:00:00 2001 From: Sebastian Nickolls Date: Thu, 25 Apr 2024 17:19:20 +0100 Subject: [PATCH 3/3] cmd/internal/obj/arm64: Enable arm64 assembler tests for cross-compiler builds Some of the tests for the arm64 assembler are not running for cross-compiled arm64 builds with GOARCH=arm64. This patch allows the tests to run for all architectures and moves the test that can only run on arm64 into its own conditionally compiled file. Updates #44734 Change-Id: I045870d47cdc1280bfacc1ef275f34504278ed89 Reviewed-on: https://go-review.googlesource.com/c/go/+/587315 Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Reviewed-by: David Chase Reviewed-by: Sebastian Nickolls --- src/cmd/internal/obj/arm64/asm_arm64_test.go | 297 +------------------ src/cmd/internal/obj/arm64/asm_test.go | 258 ++++++++++++++++ 2 files changed, 259 insertions(+), 296 deletions(-) create mode 100644 src/cmd/internal/obj/arm64/asm_test.go diff --git a/src/cmd/internal/obj/arm64/asm_arm64_test.go b/src/cmd/internal/obj/arm64/asm_arm64_test.go index 068039496a..83d137a084 100644 --- a/src/cmd/internal/obj/arm64/asm_arm64_test.go +++ b/src/cmd/internal/obj/arm64/asm_arm64_test.go @@ -4,302 +4,7 @@ package arm64 -import ( - "bytes" - "fmt" - "internal/testenv" - "os" - "path/filepath" - "regexp" - "testing" -) - -func TestSplitImm24uScaled(t *testing.T) { - tests := []struct { - v int32 - shift int - wantErr bool - wantHi int32 - wantLo int32 - }{ - { - v: 0, - shift: 0, - wantHi: 0, - wantLo: 0, - }, - { - v: 0x1001, - shift: 0, - wantHi: 0x1000, - wantLo: 0x1, - }, - { - v: 0xffffff, - shift: 0, - wantHi: 0xfff000, - wantLo: 0xfff, - }, - { - v: 0xffffff, - shift: 1, - wantErr: true, - }, - { - v: 0xfe, - shift: 1, - wantHi: 0x0, - wantLo: 0x7f, - }, - { - v: 0x10fe, - shift: 1, - wantHi: 0x0, - wantLo: 0x87f, - }, - { - v: 0x2002, - shift: 1, - wantHi: 0x2000, - wantLo: 0x1, - }, - { - v: 0xfffffe, - shift: 1, - wantHi: 0xffe000, - wantLo: 0xfff, - }, - { - v: 0x1000ffe, - shift: 1, - wantHi: 0xfff000, - wantLo: 0xfff, - }, - { - v: 0x1001000, - shift: 1, - wantErr: true, - }, - { - v: 0xfffffe, - shift: 2, - wantErr: true, - }, - { - v: 0x4004, - shift: 2, - wantHi: 0x4000, - wantLo: 0x1, - }, - { - v: 0xfffffc, - shift: 2, - wantHi: 0xffc000, - wantLo: 0xfff, - }, - { - v: 0x1002ffc, - shift: 2, - wantHi: 0xfff000, - wantLo: 0xfff, - }, - { - v: 0x1003000, - shift: 2, - wantErr: true, - }, - { - v: 0xfffffe, - shift: 3, - wantErr: true, - }, - { - v: 0x8008, - shift: 3, - wantHi: 0x8000, - wantLo: 0x1, - }, - { - v: 0xfffff8, - shift: 3, - wantHi: 0xff8000, - wantLo: 0xfff, - }, - { - v: 0x1006ff8, - shift: 3, - wantHi: 0xfff000, - wantLo: 0xfff, - }, - { - v: 0x1007000, - shift: 3, - wantErr: true, - }, - } - for _, test := range tests { - hi, lo, err := splitImm24uScaled(test.v, test.shift) - switch { - case err == nil && test.wantErr: - t.Errorf("splitImm24uScaled(%v, %v) succeeded, want error", test.v, test.shift) - case err != nil && !test.wantErr: - t.Errorf("splitImm24uScaled(%v, %v) failed: %v", test.v, test.shift, err) - case !test.wantErr: - if got, want := hi, test.wantHi; got != want { - t.Errorf("splitImm24uScaled(%x, %x) - got hi %x, want %x", test.v, test.shift, got, want) - } - if got, want := lo, test.wantLo; got != want { - t.Errorf("splitImm24uScaled(%x, %x) - got lo %x, want %x", test.v, test.shift, got, want) - } - } - } - for shift := 0; shift <= 3; shift++ { - for v := int32(0); v < 0xfff000+0xfff<