From e2cfc1eb3affe8bcdfeca4a9f0a2d7902dbb940f Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Fri, 12 Sep 2025 20:54:49 +1000 Subject: cmd/internal/obj/riscv: improve handling of float point moves Translate moves from an integer register to a floating point register, or from a floating point register to an integer register, to the appropriate move instruction (i.e. FMVXW/FMVWX/FMVXD/FMVDX). Add support for MOVF with a constant - we previously added support for MOVD but not for MOVF. Add special handling for 0.0, which we can translate to a move from the zero register to a floating point register (leveraging the above mentioned change). Change-Id: If8df2f5610e69b4ec0af85efb884951024685f5b Reviewed-on: https://go-review.googlesource.com/c/go/+/703216 Reviewed-by: Meng Zhuo Reviewed-by: Mark Freeman Reviewed-by: Michael Knyszek LUCI-TryBot-Result: Go LUCI Reviewed-by: Mark Ryan --- src/cmd/asm/internal/asm/testdata/riscv64.s | 13 ++++++- src/cmd/internal/obj/riscv/obj.go | 56 +++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 8 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/asm/internal/asm/testdata/riscv64.s b/src/cmd/asm/internal/asm/testdata/riscv64.s index 4f7e7acd77..39d2faac25 100644 --- a/src/cmd/asm/internal/asm/testdata/riscv64.s +++ b/src/cmd/asm/internal/asm/testdata/riscv64.s @@ -1952,12 +1952,23 @@ start: MOVF 4(X5), F0 // 07a04200 MOVF F0, 4(X5) // 27a20200 MOVF F0, F1 // d3000020 + MOVF X1, F3 // d38100f0 + MOVF F3, X1 // d38001e0 + MOVF X0, F3 // d30100f0 + MOVF $(0.0), F3 // d30100f0 + + // Converted to load of symbol (AUIPC + FLW) + MOVF $(709.78271289338397), F3 // 970f000087a10f00 MOVD 4(X5), F0 // 07b04200 MOVD F0, 4(X5) // 27b20200 MOVD F0, F1 // d3000022 + MOVD F3, X1 // d38001e2 + MOVD X1, F3 // d38100f2 + MOVD X0, F3 // d30100f2 + MOVD $(0.0), F3 // d30100f2 - // Convert to load of symbol (AUIPC + FLD) + // Converted to load of symbol (AUIPC + FLD) MOVD $(709.78271289338397), F3 // 970f000087b10f00 // TLS load with local-exec (LUI + ADDIW + ADD of TP + load) diff --git a/src/cmd/internal/obj/riscv/obj.go b/src/cmd/internal/obj/riscv/obj.go index 1538d03179..fcdea57460 100644 --- a/src/cmd/internal/obj/riscv/obj.go +++ b/src/cmd/internal/obj/riscv/obj.go @@ -29,6 +29,7 @@ import ( "internal/abi" "internal/buildcfg" "log" + "math" "math/bits" "strings" ) @@ -145,9 +146,29 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { p.From.Offset = 0 } + case AMOVF: + if p.From.Type == obj.TYPE_FCONST && p.From.Name == obj.NAME_NONE && p.From.Reg == obj.REG_NONE { + f64 := p.From.Val.(float64) + f32 := float32(f64) + if math.Float32bits(f32) == 0 { + p.From.Type = obj.TYPE_REG + p.From.Reg = REG_ZERO + break + } + p.From.Type = obj.TYPE_MEM + p.From.Sym = ctxt.Float32Sym(f32) + p.From.Name = obj.NAME_EXTERN + p.From.Offset = 0 + } + case AMOVD: if p.From.Type == obj.TYPE_FCONST && p.From.Name == obj.NAME_NONE && p.From.Reg == obj.REG_NONE { f64 := p.From.Val.(float64) + if math.Float64bits(f64) == 0 { + p.From.Type = obj.TYPE_REG + p.From.Reg = REG_ZERO + break + } p.From.Type = obj.TYPE_MEM p.From.Sym = ctxt.Float64Sym(f64) p.From.Name = obj.NAME_EXTERN @@ -3254,16 +3275,37 @@ func instructionsForMOV(p *obj.Prog) []*instruction { case p.From.Type == obj.TYPE_REG && p.To.Type == obj.TYPE_REG: // Handle register to register moves. switch p.As { - case AMOV: // MOV Ra, Rb -> ADDI $0, Ra, Rb + case AMOV: + // MOV Ra, Rb -> ADDI $0, Ra, Rb ins.as, ins.rs1, ins.rs2, ins.imm = AADDI, uint32(p.From.Reg), obj.REG_NONE, 0 - case AMOVW: // MOVW Ra, Rb -> ADDIW $0, Ra, Rb + case AMOVW: + // MOVW Ra, Rb -> ADDIW $0, Ra, Rb ins.as, ins.rs1, ins.rs2, ins.imm = AADDIW, uint32(p.From.Reg), obj.REG_NONE, 0 - case AMOVBU: // MOVBU Ra, Rb -> ANDI $255, Ra, Rb + case AMOVBU: + // MOVBU Ra, Rb -> ANDI $255, Ra, Rb ins.as, ins.rs1, ins.rs2, ins.imm = AANDI, uint32(p.From.Reg), obj.REG_NONE, 255 - case AMOVF: // MOVF Ra, Rb -> FSGNJS Ra, Ra, Rb - ins.as, ins.rs1 = AFSGNJS, uint32(p.From.Reg) - case AMOVD: // MOVD Ra, Rb -> FSGNJD Ra, Ra, Rb - ins.as, ins.rs1 = AFSGNJD, uint32(p.From.Reg) + case AMOVF: + // MOVF Ra, Rb -> FSGNJS Ra, Ra, Rb + // or -> FMVWX Ra, Rb + // or -> FMVXW Ra, Rb + if ins.rs2 >= REG_X0 && ins.rs2 <= REG_X31 && ins.rd >= REG_F0 && ins.rd <= REG_F31 { + ins.as = AFMVWX + } else if ins.rs2 >= REG_F0 && ins.rs2 <= REG_F31 && ins.rd >= REG_X0 && ins.rd <= REG_X31 { + ins.as = AFMVXW + } else { + ins.as, ins.rs1 = AFSGNJS, uint32(p.From.Reg) + } + case AMOVD: + // MOVD Ra, Rb -> FSGNJD Ra, Ra, Rb + // or -> FMVDX Ra, Rb + // or -> FMVXD Ra, Rb + if ins.rs2 >= REG_X0 && ins.rs2 <= REG_X31 && ins.rd >= REG_F0 && ins.rd <= REG_F31 { + ins.as = AFMVDX + } else if ins.rs2 >= REG_F0 && ins.rs2 <= REG_F31 && ins.rd >= REG_X0 && ins.rd <= REG_X31 { + ins.as = AFMVXD + } else { + ins.as, ins.rs1 = AFSGNJD, uint32(p.From.Reg) + } case AMOVB, AMOVH: if buildcfg.GORISCV64 >= 22 { // Use SEXTB or SEXTH to extend. -- cgit v1.3-6-g1900 From 0b26678db2d042c6273c435df5cb5a37e7e04994 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Mon, 15 Sep 2025 19:59:22 -0700 Subject: cmd/compile: fix mips zerorange implementation A +8 was missed when simplifying this code in CL 700936. Fixes #75477 Change-Id: Ic7b83322dc1373432b44f0b63607141195220380 Reviewed-on: https://go-review.googlesource.com/c/go/+/703937 Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: Julian Zhu Auto-Submit: Keith Randall Reviewed-by: Tianon Gravi Reviewed-by: Michael Knyszek --- src/cmd/compile/internal/mips/ggen.go | 3 ++- src/cmd/compile/internal/mips64/ggen.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/compile/internal/mips/ggen.go b/src/cmd/compile/internal/mips/ggen.go index 023f4d958e..394f015589 100644 --- a/src/cmd/compile/internal/mips/ggen.go +++ b/src/cmd/compile/internal/mips/ggen.go @@ -5,6 +5,7 @@ package mips import ( + "cmd/compile/internal/base" "cmd/compile/internal/objw" "cmd/compile/internal/types" "cmd/internal/obj" @@ -17,7 +18,7 @@ func zerorange(pp *objw.Progs, p *obj.Prog, off, cnt int64, _ *uint32) *obj.Prog } for cnt != 0 { - p = pp.Append(p, mips.AMOVW, obj.TYPE_REG, mips.REGZERO, 0, obj.TYPE_MEM, mips.REGSP, off) + p = pp.Append(p, mips.AMOVW, obj.TYPE_REG, mips.REGZERO, 0, obj.TYPE_MEM, mips.REGSP, base.Ctxt.Arch.FixedFrameSize+off) cnt -= int64(types.PtrSize) off += int64(types.PtrSize) } diff --git a/src/cmd/compile/internal/mips64/ggen.go b/src/cmd/compile/internal/mips64/ggen.go index 0740d9abe8..740d68e335 100644 --- a/src/cmd/compile/internal/mips64/ggen.go +++ b/src/cmd/compile/internal/mips64/ggen.go @@ -17,7 +17,7 @@ func zerorange(pp *objw.Progs, p *obj.Prog, off, cnt int64, _ *uint32) *obj.Prog } for cnt != 0 { - p = pp.Append(p, mips.AMOVV, obj.TYPE_REG, mips.REGZERO, 0, obj.TYPE_MEM, mips.REGSP, off) + p = pp.Append(p, mips.AMOVV, obj.TYPE_REG, mips.REGZERO, 0, obj.TYPE_MEM, mips.REGSP, off+8) cnt -= int64(types.PtrSize) off += int64(types.PtrSize) } -- cgit v1.3-6-g1900 From c2d85eb999fcd428a1cd71ed93805cbde0c16eaa Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Sun, 14 Sep 2025 02:32:24 +0800 Subject: cmd/go: disable cgo by default if CC unset and DefaultCC doesn't exist CL 621995 disrupted the behavior introduced by CL 450739, now restore it. Fixes #75340 Change-Id: Icd1a0eb970876995f9446e0547ceb9e78990f6ed Reviewed-on: https://go-review.googlesource.com/c/go/+/703555 LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Matloob Reviewed-by: Michael Matloob Reviewed-by: Ian Alexander Reviewed-by: Sean Liao --- src/cmd/go/internal/cfg/cfg.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/cmd') diff --git a/src/cmd/go/internal/cfg/cfg.go b/src/cmd/go/internal/cfg/cfg.go index a4edd854f1..97e4eeeff3 100644 --- a/src/cmd/go/internal/cfg/cfg.go +++ b/src/cmd/go/internal/cfg/cfg.go @@ -145,7 +145,8 @@ func defaultContext() build.Context { if buildcfg.DefaultCGO_ENABLED == "1" { defaultCgoEnabled = true } else if buildcfg.DefaultCGO_ENABLED == "0" { - } else if runtime.GOARCH == ctxt.GOARCH && runtime.GOOS == ctxt.GOOS { + } + if runtime.GOARCH == ctxt.GOARCH && runtime.GOOS == ctxt.GOOS { defaultCgoEnabled = platform.CgoSupported(ctxt.GOOS, ctxt.GOARCH) // Use built-in default cgo setting for GOOS/GOARCH. // Note that ctxt.GOOS/GOARCH are derived from the preference list -- cgit v1.3-6-g1900 From cbdad4fc3cecbdfcee4e9d30df04916a151bfc16 Mon Sep 17 00:00:00 2001 From: Youlin Feng Date: Thu, 4 Sep 2025 09:17:26 +0800 Subject: cmd/go: check pattern for utf8 validity before call regexp.MustCompile Do not panic if the package path or the package version contains invalid UTF-8 characters. Fixes #75251 Change-Id: Ib787e74277cf814253857b911d378ea5e53d8824 Reviewed-on: https://go-review.googlesource.com/c/go/+/700815 Reviewed-by: Michael Matloob LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Alexander Reviewed-by: Michael Matloob --- src/cmd/go/internal/modget/query.go | 6 ++++++ src/cmd/go/testdata/script/get_panic_issue75251.txt | 16 ++++++++++++++++ src/cmd/internal/pkgpattern/pkgpattern.go | 3 ++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/cmd/go/testdata/script/get_panic_issue75251.txt (limited to 'src/cmd') diff --git a/src/cmd/go/internal/modget/query.go b/src/cmd/go/internal/modget/query.go index f95b503d8f..05872d52ec 100644 --- a/src/cmd/go/internal/modget/query.go +++ b/src/cmd/go/internal/modget/query.go @@ -10,6 +10,7 @@ import ( "regexp" "strings" "sync" + "unicode/utf8" "cmd/go/internal/base" "cmd/go/internal/gover" @@ -285,6 +286,11 @@ func reportError(q *query, err error) { // TODO(bcmills): Use errors.As to unpack these errors instead of parsing // strings with regular expressions. + if !utf8.ValidString(q.pattern) || !utf8.ValidString(q.version) { + base.Errorf("go: %s", errStr) + return + } + patternRE := regexp.MustCompile("(?m)(?:[ \t(\"`]|^)" + regexp.QuoteMeta(q.pattern) + "(?:[ @:;)\"`]|$)") if patternRE.MatchString(errStr) { if q.rawVersion == "" { diff --git a/src/cmd/go/testdata/script/get_panic_issue75251.txt b/src/cmd/go/testdata/script/get_panic_issue75251.txt new file mode 100644 index 0000000000..2cc3f3a9c4 --- /dev/null +++ b/src/cmd/go/testdata/script/get_panic_issue75251.txt @@ -0,0 +1,16 @@ +# Issue #75251: Don't panic if the package path or the package version +# contains invalid UTF-8 characters. + +go mod init m + +! go get golang.org/x/net/http/httpgutsÿv0.43.0 # contains 0xff byte +! stderr panic +stderr 'malformed module path' + +! go get golang.org/x/net/http/httpgutsÿ@v0.43.0 # contains 0xff byte +! stderr panic +stderr 'malformed module path' + +! go get golang.org/x/net/http/httpguts@ÿv0.43.0 # contains 0xff byte +! stderr panic +stderr 'disallowed version string' diff --git a/src/cmd/internal/pkgpattern/pkgpattern.go b/src/cmd/internal/pkgpattern/pkgpattern.go index 1496eebb3e..5bbe8a52fb 100644 --- a/src/cmd/internal/pkgpattern/pkgpattern.go +++ b/src/cmd/internal/pkgpattern/pkgpattern.go @@ -7,6 +7,7 @@ package pkgpattern import ( "regexp" "strings" + "unicode/utf8" ) // Note: most of this code was originally part of the cmd/go/internal/search @@ -71,7 +72,7 @@ func matchPatternInternal(pattern string, vendorExclude bool) func(name string) const vendorChar = "\x00" - if vendorExclude && strings.Contains(pattern, vendorChar) { + if vendorExclude && strings.Contains(pattern, vendorChar) || !utf8.ValidString(pattern) { return func(name string) bool { return false } } -- cgit v1.3-6-g1900 From 594deca981f0dd4a9351569e7c3e6999838148e3 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Tue, 13 May 2025 11:24:30 +0200 Subject: cmd/link: simplify PE relocations mapping The code for mapping Windows PE relocations to Go relocations was difficult to follow and contains some duplicated code. Also, it was mapping IMAGE_REL_AMD64_ADDR32 to R_PCREL instead of R_ADDR. This CL commit simplifies the code and fixes the mapping. I haven't been able to coerce mingw-w64 to generate IMAGE_REL_AMD64_ADDR32 relocations, so I haven't been able to test this change. However, the previous implementation was clearly wrong. While here, remove code supporting the unsupported windows/arm support. Updates #71671 Updates #75485 Change-Id: Id0d6f352fa7d5df9e00509fcdf09ca0cb91ca524 Reviewed-on: https://go-review.googlesource.com/c/go/+/672155 Reviewed-by: Michael Knyszek Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI --- src/cmd/link/internal/loadpe/ldpe.go | 104 ++++++++++++----------------------- 1 file changed, 34 insertions(+), 70 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/link/internal/loadpe/ldpe.go b/src/cmd/link/internal/loadpe/ldpe.go index b895ac4149..d3a050135c 100644 --- a/src/cmd/link/internal/loadpe/ldpe.go +++ b/src/cmd/link/internal/loadpe/ldpe.go @@ -17,6 +17,7 @@ import ( "errors" "fmt" "io" + "strconv" "strings" ) @@ -348,11 +349,11 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read return nil, fmt.Errorf("relocation number %d symbol index idx=%d cannot be large then number of symbols %d", j, r.SymbolTableIndex, len(f.COFFSymbols)) } pesym := &f.COFFSymbols[r.SymbolTableIndex] - _, gosym, err := state.readpesym(pesym) + _, rSym, err := state.readpesym(pesym) if err != nil { return nil, err } - if gosym == 0 { + if rSym == 0 { name, err := pesym.FullName(f.StringTable) if err != nil { name = string(pesym.Name[:]) @@ -360,90 +361,53 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read return nil, fmt.Errorf("reloc of invalid sym %s idx=%d type=%d", name, r.SymbolTableIndex, pesym.Type) } - rSym := gosym rSize := uint8(4) rOff := int32(r.VirtualAddress) - var rAdd int64 var rType objabi.RelocType switch arch.Family { default: return nil, fmt.Errorf("%s: unsupported arch %v", pn, arch.Family) - case sys.I386, sys.AMD64: + case sys.I386: switch r.Type { - default: - return nil, fmt.Errorf("%s: %v: unknown relocation type %v", pn, state.sectsyms[rsect], r.Type) - - case IMAGE_REL_I386_REL32, IMAGE_REL_AMD64_REL32, - IMAGE_REL_AMD64_ADDR32, // R_X86_64_PC32 - IMAGE_REL_AMD64_ADDR32NB: - if r.Type == IMAGE_REL_AMD64_ADDR32NB { - rType = objabi.R_PEIMAGEOFF - } else { - rType = objabi.R_PCREL - } - - rAdd = int64(int32(binary.LittleEndian.Uint32(state.sectdata[rsect][rOff:]))) - - case IMAGE_REL_I386_DIR32NB, IMAGE_REL_I386_DIR32: - if r.Type == IMAGE_REL_I386_DIR32NB { - rType = objabi.R_PEIMAGEOFF - } else { - rType = objabi.R_ADDR - } - - // load addend from image - rAdd = int64(int32(binary.LittleEndian.Uint32(state.sectdata[rsect][rOff:]))) - - case IMAGE_REL_AMD64_ADDR64: // R_X86_64_64 - rSize = 8 - + case IMAGE_REL_I386_REL32: + rType = objabi.R_PCREL + case IMAGE_REL_I386_DIR32: rType = objabi.R_ADDR - - // load addend from image - rAdd = int64(binary.LittleEndian.Uint64(state.sectdata[rsect][rOff:])) + case IMAGE_REL_I386_DIR32NB: + rType = objabi.R_PEIMAGEOFF } - - case sys.ARM: + case sys.AMD64: switch r.Type { - default: - return nil, fmt.Errorf("%s: %v: unknown ARM relocation type %v", pn, state.sectsyms[rsect], r.Type) - - case IMAGE_REL_ARM_SECREL: + case IMAGE_REL_AMD64_REL32: rType = objabi.R_PCREL - - rAdd = int64(int32(binary.LittleEndian.Uint32(state.sectdata[rsect][rOff:]))) - - case IMAGE_REL_ARM_ADDR32, IMAGE_REL_ARM_ADDR32NB: - if r.Type == IMAGE_REL_ARM_ADDR32NB { - rType = objabi.R_PEIMAGEOFF - } else { - rType = objabi.R_ADDR - } - - rAdd = int64(int32(binary.LittleEndian.Uint32(state.sectdata[rsect][rOff:]))) - - case IMAGE_REL_ARM_BRANCH24: - rType = objabi.R_CALLARM - - rAdd = int64(int32(binary.LittleEndian.Uint32(state.sectdata[rsect][rOff:]))) + case IMAGE_REL_AMD64_ADDR32: + rType = objabi.R_ADDR + case IMAGE_REL_AMD64_ADDR64: + rType = objabi.R_ADDR + rSize = 8 + case IMAGE_REL_AMD64_ADDR32NB: + rType = objabi.R_PEIMAGEOFF } - case sys.ARM64: switch r.Type { - default: - return nil, fmt.Errorf("%s: %v: unknown ARM64 relocation type %v", pn, state.sectsyms[rsect], r.Type) - - case IMAGE_REL_ARM64_ADDR32, IMAGE_REL_ARM64_ADDR32NB: - if r.Type == IMAGE_REL_ARM64_ADDR32NB { - rType = objabi.R_PEIMAGEOFF - } else { - rType = objabi.R_ADDR - } - - rAdd = int64(int32(binary.LittleEndian.Uint32(state.sectdata[rsect][rOff:]))) + case IMAGE_REL_ARM64_ADDR32: + rType = objabi.R_ADDR + case IMAGE_REL_ARM64_ADDR32NB: + rType = objabi.R_PEIMAGEOFF } } - + if rType == 0 { + return nil, fmt.Errorf("%s: %v: unknown relocation type %v", pn, state.sectsyms[rsect], r.Type) + } + var rAdd int64 + switch rSize { + default: + panic("unexpected relocation size " + strconv.Itoa(int(rSize))) + case 4: + rAdd = int64(int32(binary.LittleEndian.Uint32(state.sectdata[rsect][rOff:]))) + case 8: + rAdd = int64(binary.LittleEndian.Uint64(state.sectdata[rsect][rOff:])) + } // ld -r could generate multiple section symbols for the // same section but with different values, we have to take // that into account, or in the case of split resources, -- cgit v1.3-6-g1900 From 78ef487a6f936a39e9d4ebf66ac421bb1244a7a9 Mon Sep 17 00:00:00 2001 From: Xiaolin Zhao Date: Tue, 16 Sep 2025 15:27:42 +0800 Subject: cmd/compile: fix the issue of shift amount exceeding the valid range Fixes #75479 Change-Id: I362d3e49090e94f91a840dd5a475978b59222a00 Reviewed-on: https://go-review.googlesource.com/c/go/+/704135 Reviewed-by: Mark Freeman LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek Reviewed-by: Meidan Li Reviewed-by: abner chenc --- src/cmd/compile/internal/ssa/_gen/LOONG64.rules | 3 +- src/cmd/compile/internal/ssa/_gen/LOONG64Ops.go | 2 +- src/cmd/compile/internal/ssa/rewriteLOONG64.go | 46 ++++++++++++++++++++++--- test/codegen/shift.go | 2 ++ 4 files changed, 47 insertions(+), 6 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/compile/internal/ssa/_gen/LOONG64.rules b/src/cmd/compile/internal/ssa/_gen/LOONG64.rules index d0a64364d6..0d2384143c 100644 --- a/src/cmd/compile/internal/ssa/_gen/LOONG64.rules +++ b/src/cmd/compile/internal/ssa/_gen/LOONG64.rules @@ -717,7 +717,8 @@ (SRLVconst [rc] (MOVBUreg x)) && rc >= 8 => (MOVVconst [0]) // (x + x) << c -> x << c+1 -((SLLV|SLL)const [c] (ADDV x x)) => ((SLLV|SLL)const [c+1] x) +((SLLV|SLL)const [c] (ADDV x x)) && c < t.Size() * 8 - 1 => ((SLLV|SLL)const [c+1] x) +((SLLV|SLL)const [c] (ADDV x x)) && c >= t.Size() * 8 - 1 => (MOVVconst [0]) // mul by constant (MULV _ (MOVVconst [0])) => (MOVVconst [0]) diff --git a/src/cmd/compile/internal/ssa/_gen/LOONG64Ops.go b/src/cmd/compile/internal/ssa/_gen/LOONG64Ops.go index 0d5e0eb76f..a3db4def56 100644 --- a/src/cmd/compile/internal/ssa/_gen/LOONG64Ops.go +++ b/src/cmd/compile/internal/ssa/_gen/LOONG64Ops.go @@ -247,7 +247,7 @@ func init() { {name: "SLL", argLength: 2, reg: gp21, asm: "SLL"}, // arg0 << arg1, shift amount is mod 32 {name: "SLLV", argLength: 2, reg: gp21, asm: "SLLV"}, // arg0 << arg1, shift amount is mod 64 {name: "SLLconst", argLength: 1, reg: gp11, asm: "SLL", aux: "Int64"}, // arg0 << auxInt, auxInt should be in the range 0 to 31. - {name: "SLLVconst", argLength: 1, reg: gp11, asm: "SLLV", aux: "Int64"}, // arg0 << auxInt + {name: "SLLVconst", argLength: 1, reg: gp11, asm: "SLLV", aux: "Int64"}, // arg0 << auxInt, auxInt should be in the range 0 to 63. {name: "SRL", argLength: 2, reg: gp21, asm: "SRL"}, // arg0 >> arg1, shift amount is mod 32 {name: "SRLV", argLength: 2, reg: gp21, asm: "SRLV"}, // arg0 >> arg1, unsigned, shift amount is mod 64 {name: "SRLconst", argLength: 1, reg: gp11, asm: "SRL", aux: "Int64"}, // arg0 >> auxInt, auxInt should be in the range 0 to 31. diff --git a/src/cmd/compile/internal/ssa/rewriteLOONG64.go b/src/cmd/compile/internal/ssa/rewriteLOONG64.go index 6a9b723c8c..3990b2833b 100644 --- a/src/cmd/compile/internal/ssa/rewriteLOONG64.go +++ b/src/cmd/compile/internal/ssa/rewriteLOONG64.go @@ -6561,15 +6561,17 @@ func rewriteValueLOONG64_OpLOONG64SLLV(v *Value) bool { } func rewriteValueLOONG64_OpLOONG64SLLVconst(v *Value) bool { v_0 := v.Args[0] - // match: (SLLVconst [c] (ADDV x x)) + // match: (SLLVconst [c] (ADDV x x)) + // cond: c < t.Size() * 8 - 1 // result: (SLLVconst [c+1] x) for { + t := v.Type c := auxIntToInt64(v.AuxInt) if v_0.Op != OpLOONG64ADDV { break } x := v_0.Args[1] - if x != v_0.Args[0] { + if x != v_0.Args[0] || !(c < t.Size()*8-1) { break } v.reset(OpLOONG64SLLVconst) @@ -6577,6 +6579,23 @@ func rewriteValueLOONG64_OpLOONG64SLLVconst(v *Value) bool { v.AddArg(x) return true } + // match: (SLLVconst [c] (ADDV x x)) + // cond: c >= t.Size() * 8 - 1 + // result: (MOVVconst [0]) + for { + t := v.Type + c := auxIntToInt64(v.AuxInt) + if v_0.Op != OpLOONG64ADDV { + break + } + x := v_0.Args[1] + if x != v_0.Args[0] || !(c >= t.Size()*8-1) { + break + } + v.reset(OpLOONG64MOVVconst) + v.AuxInt = int64ToAuxInt(0) + return true + } // match: (SLLVconst [c] (MOVVconst [d])) // result: (MOVVconst [d< [c] (ADDV x x)) + // cond: c < t.Size() * 8 - 1 // result: (SLLconst [c+1] x) for { + t := v.Type c := auxIntToInt64(v.AuxInt) if v_0.Op != OpLOONG64ADDV { break } x := v_0.Args[1] - if x != v_0.Args[0] { + if x != v_0.Args[0] || !(c < t.Size()*8-1) { break } v.reset(OpLOONG64SLLconst) @@ -6609,6 +6630,23 @@ func rewriteValueLOONG64_OpLOONG64SLLconst(v *Value) bool { v.AddArg(x) return true } + // match: (SLLconst [c] (ADDV x x)) + // cond: c >= t.Size() * 8 - 1 + // result: (MOVVconst [0]) + for { + t := v.Type + c := auxIntToInt64(v.AuxInt) + if v_0.Op != OpLOONG64ADDV { + break + } + x := v_0.Args[1] + if x != v_0.Args[0] || !(c >= t.Size()*8-1) { + break + } + v.reset(OpLOONG64MOVVconst) + v.AuxInt = int64ToAuxInt(0) + return true + } return false } func rewriteValueLOONG64_OpLOONG64SRA(v *Value) bool { diff --git a/test/codegen/shift.go b/test/codegen/shift.go index 7385058726..4b0885a4dd 100644 --- a/test/codegen/shift.go +++ b/test/codegen/shift.go @@ -148,11 +148,13 @@ func lshConst64x2Add(x int64) int64 { } func lshConst32x31Add(x int32) int32 { + // loong64:-"SLL\t","MOVV\tR0" // riscv64:-"SLLI","MOV\t[$]0" return (x + x) << 31 } func lshConst64x63Add(x int64) int64 { + // loong64:-"SLLV","MOVV\tR0" // riscv64:-"SLLI","MOV\t[$]0" return (x + x) << 63 } -- cgit v1.3-6-g1900 From ef05b66d6115209361dd99ff8f3ab978695fd74a Mon Sep 17 00:00:00 2001 From: lxq015 <1824368278@qq.com> Date: Wed, 17 Sep 2025 04:10:13 +0000 Subject: cmd/internal/obj/riscv: add support for Zicond instructions This patch implement assembler for the Zicond extension: CZEROEQZ and CZERONEZ. Follow-up to CL 631576 Updates #75350 Change-Id: Icf4be131fe61c3b7a3bde4811cf42dc807660907 GitHub-Last-Rev: 6539cc86cbf3c49c3247ed935bcbbb31bb886dea GitHub-Pull-Request: golang/go#75408 Reviewed-on: https://go-review.googlesource.com/c/go/+/702677 Reviewed-by: Mark Freeman Reviewed-by: Joel Sing Reviewed-by: Meng Zhuo Reviewed-by: Michael Knyszek Reviewed-by: Mark Ryan TryBot-Bypass: Joel Sing --- src/cmd/asm/internal/asm/testdata/riscv64.s | 6 ++++++ src/cmd/internal/obj/riscv/anames.go | 2 ++ src/cmd/internal/obj/riscv/cpu.go | 4 ++++ src/cmd/internal/obj/riscv/inst.go | 6 +++++- src/cmd/internal/obj/riscv/obj.go | 4 ++++ 5 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src/cmd') diff --git a/src/cmd/asm/internal/asm/testdata/riscv64.s b/src/cmd/asm/internal/asm/testdata/riscv64.s index 39d2faac25..07a898465f 100644 --- a/src/cmd/asm/internal/asm/testdata/riscv64.s +++ b/src/cmd/asm/internal/asm/testdata/riscv64.s @@ -195,6 +195,12 @@ start: RDTIME X5 // f32210c0 RDINSTRET X5 // f32220c0 + // 12.3: Integer Conditional Operations (Zicond) + CZEROEQZ X5, X6, X7 // b353530e + CZEROEQZ X5, X7 // b3d3530e + CZERONEZ X5, X6, X7 // b373530e + CZERONEZ X5, X7 // b3f3530e + // 13.1: Multiplication Operations MUL X5, X6, X7 // b3035302 MULH X5, X6, X7 // b3135302 diff --git a/src/cmd/internal/obj/riscv/anames.go b/src/cmd/internal/obj/riscv/anames.go index 88ac746573..a8807fc7a8 100644 --- a/src/cmd/internal/obj/riscv/anames.go +++ b/src/cmd/internal/obj/riscv/anames.go @@ -61,6 +61,8 @@ var Anames = []string{ "CSRRWI", "CSRRSI", "CSRRCI", + "CZEROEQZ", + "CZERONEZ", "MUL", "MULH", "MULHU", diff --git a/src/cmd/internal/obj/riscv/cpu.go b/src/cmd/internal/obj/riscv/cpu.go index e265e04482..305ef061e3 100644 --- a/src/cmd/internal/obj/riscv/cpu.go +++ b/src/cmd/internal/obj/riscv/cpu.go @@ -409,6 +409,10 @@ const ( ACSRRSI ACSRRCI + // 12.3: Integer Conditional Operations (Zicond) + ACZEROEQZ + ACZERONEZ + // 13.1: Multiplication Operations AMUL AMULH diff --git a/src/cmd/internal/obj/riscv/inst.go b/src/cmd/internal/obj/riscv/inst.go index a6a03dc565..a5b3acdb18 100644 --- a/src/cmd/internal/obj/riscv/inst.go +++ b/src/cmd/internal/obj/riscv/inst.go @@ -1,4 +1,4 @@ -// Code generated by ./parse.py -go rv64_a rv64_c rv64_d rv64_f rv64_i rv64_m rv64_q rv64_zba rv64_zbb rv64_zbs rv_a rv_c rv_c_d rv_d rv_f rv_i rv_m rv_q rv_s rv_system rv_v rv_zba rv_zbb rv_zbs rv_zicsr; DO NOT EDIT. +// Code generated by ./parse.py -go rv64_a rv64_c rv64_d rv64_f rv64_i rv64_m rv64_q rv64_zba rv64_zbb rv64_zbs rv_a rv_c rv_c_d rv_d rv_f rv_i rv_m rv_q rv_s rv_system rv_v rv_zba rv_zbb rv_zbs rv_zicond rv_zicsr; DO NOT EDIT. package riscv import "cmd/internal/obj" @@ -194,6 +194,10 @@ func encode(a obj.As) *inst { return &inst{0x13, 0x1, 0x0, 0x1, 1537, 0x30} case ACTZW: return &inst{0x1b, 0x1, 0x0, 0x1, 1537, 0x30} + case ACZEROEQZ: + return &inst{0x33, 0x5, 0x0, 0x0, 224, 0x7} + case ACZERONEZ: + return &inst{0x33, 0x7, 0x0, 0x0, 224, 0x7} case ADIV: return &inst{0x33, 0x4, 0x0, 0x0, 32, 0x1} case ADIVU: diff --git a/src/cmd/internal/obj/riscv/obj.go b/src/cmd/internal/obj/riscv/obj.go index fcdea57460..9d595f301c 100644 --- a/src/cmd/internal/obj/riscv/obj.go +++ b/src/cmd/internal/obj/riscv/obj.go @@ -1948,6 +1948,10 @@ var instructions = [ALAST & obj.AMask]instructionData{ ACSRRW & obj.AMask: {enc: iIIEncoding, immForm: ACSRRWI}, ACSRRWI & obj.AMask: {enc: iIIEncoding}, + // 12.3: "Zicond" Extension for Integer Conditional Operations + ACZERONEZ & obj.AMask: {enc: rIIIEncoding, ternary: true}, + ACZEROEQZ & obj.AMask: {enc: rIIIEncoding, ternary: true}, + // 13.1: Multiplication Operations AMUL & obj.AMask: {enc: rIIIEncoding, ternary: true}, AMULH & obj.AMask: {enc: rIIIEncoding, ternary: true}, -- cgit v1.3-6-g1900 From 0ab038af6290c7fb52d4c26949d735692781b3d1 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 17 Sep 2025 18:00:10 -0700 Subject: cmd/compile/internal/abi: use clear built-in Replace for loop with clear, available since Go 1.21. Change-Id: I949da08b2a11845cc8a02b2639af78835e316970 Reviewed-on: https://go-review.googlesource.com/c/go/+/704879 LUCI-TryBot-Result: Go LUCI Reviewed-by: Mark Freeman Reviewed-by: Sean Liao Reviewed-by: Michael Knyszek --- src/cmd/compile/internal/abi/abiutils.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/compile/internal/abi/abiutils.go b/src/cmd/compile/internal/abi/abiutils.go index c013aba19c..dacaad3f30 100644 --- a/src/cmd/compile/internal/abi/abiutils.go +++ b/src/cmd/compile/internal/abi/abiutils.go @@ -661,9 +661,7 @@ func (state *assignState) tryAllocRegs(typ *types.Type) []RegIndex { func (pa *ABIParamAssignment) ComputePadding(storage []uint64) []uint64 { nr := len(pa.Registers) padding := storage[:nr] - for i := 0; i < nr; i++ { - padding[i] = 0 - } + clear(padding) if pa.Type.Kind() != types.TSTRUCT || nr == 0 { return padding } -- cgit v1.3-6-g1900 From f9e61a9a32c8cbfd810ac9fec135b5c0911b8d69 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Thu, 18 Sep 2025 13:59:41 -0400 Subject: cmd/compile: duplicate nil check to two branches of write barrier Currently, for a write of a pointer (e.g. *p = x where x is a pointer), we generate an explicit nil check of p, despite that the store instruction may have the same faulting behavior as the nil check. This is because the write needs a write barrier, which creates a control flow, which prevents the nil check being removed as it is in a differnt block as the actual store. This CL duplicates the nil check to two branches, so it is likely that they will be followed by the actual store and the write barrier load, which may have the same faulting behavior, so they can be removed. Change-Id: Ied9480de5dd6a8fcbd5affc5f6e029944943cc07 Reviewed-on: https://go-review.googlesource.com/c/go/+/705156 Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/writebarrier.go | 43 ++++++++++++++++++++++------ test/nilptr5.go | 6 ++++ test/nilptr5_aix.go | 6 ++++ test/nilptr5_wasm.go | 5 ++++ 4 files changed, 51 insertions(+), 9 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/compile/internal/ssa/writebarrier.go b/src/cmd/compile/internal/ssa/writebarrier.go index 9ef3667d51..ec6901f13e 100644 --- a/src/cmd/compile/internal/ssa/writebarrier.go +++ b/src/cmd/compile/internal/ssa/writebarrier.go @@ -303,6 +303,15 @@ func writebarrier(f *Func) { mem := stores[0].MemoryArg() pos := stores[0].Pos + // If there is a nil check before the WB store, duplicate it to + // the two branches, where the store and the WB load occur. So + // they are more likely be removed by late nilcheck removal (which + // is block-local). + var nilcheck, nilcheckThen, nilcheckEnd *Value + if a := stores[0].Args[0]; a.Op == OpNilCheck && a.Args[1] == mem { + nilcheck = a + } + // If the source of a MoveWB is volatile (will be clobbered by a // function call), we need to copy it to a temporary location, as // marshaling the args of wbMove might clobber the value we're @@ -377,6 +386,10 @@ func writebarrier(f *Func) { // For each write barrier store, append write barrier code to bThen. memThen := mem + if nilcheck != nil { + nilcheckThen = bThen.NewValue2(nilcheck.Pos, OpNilCheck, nilcheck.Type, nilcheck.Args[0], memThen) + } + // Note: we can issue the write barrier code in any order. In particular, // it doesn't matter if they are in a different order *even if* they end // up referring to overlapping memory regions. For instance if an OpStore @@ -447,6 +460,9 @@ func writebarrier(f *Func) { // take care of the vast majority of these. We could // patch this up in the signal handler, or use XCHG to // combine the read and the write. + if ptr == nilcheck { + ptr = nilcheckThen + } oldVal := bThen.NewValue2(pos, OpLoad, types.Types[types.TUINTPTR], ptr, memThen) // Save old value to write buffer. addEntry(pos, oldVal) @@ -459,9 +475,12 @@ func writebarrier(f *Func) { // Now do the rare cases, Zeros and Moves. for _, w := range stores { pos := w.Pos + dst := w.Args[0] + if dst == nilcheck { + dst = nilcheckThen + } switch w.Op { case OpZeroWB: - dst := w.Args[0] typ := reflectdata.TypeLinksym(w.Aux.(*types.Type)) // zeroWB(&typ, dst) taddr := b.NewValue1A(pos, OpAddr, b.Func.Config.Types.Uintptr, typ, sb) @@ -469,7 +488,6 @@ func writebarrier(f *Func) { f.fe.Func().SetWBPos(pos) nWBops-- case OpMoveWB: - dst := w.Args[0] src := w.Args[1] if isVolatile(src) { for _, c := range volatiles { @@ -491,24 +509,29 @@ func writebarrier(f *Func) { // merge memory mem = bEnd.NewValue2(pos, OpPhi, types.TypeMem, mem, memThen) + if nilcheck != nil { + nilcheckEnd = bEnd.NewValue2(nilcheck.Pos, OpNilCheck, nilcheck.Type, nilcheck.Args[0], mem) + } + // Do raw stores after merge point. for _, w := range stores { pos := w.Pos + dst := w.Args[0] + if dst == nilcheck { + dst = nilcheckEnd + } switch w.Op { case OpStoreWB: - ptr := w.Args[0] val := w.Args[1] if buildcfg.Experiment.CgoCheck2 { // Issue cgo checking code. - mem = wbcall(pos, bEnd, cgoCheckPtrWrite, sp, mem, ptr, val) + mem = wbcall(pos, bEnd, cgoCheckPtrWrite, sp, mem, dst, val) } - mem = bEnd.NewValue3A(pos, OpStore, types.TypeMem, w.Aux, ptr, val, mem) + mem = bEnd.NewValue3A(pos, OpStore, types.TypeMem, w.Aux, dst, val, mem) case OpZeroWB: - dst := w.Args[0] mem = bEnd.NewValue2I(pos, OpZero, types.TypeMem, w.AuxInt, dst, mem) mem.Aux = w.Aux case OpMoveWB: - dst := w.Args[0] src := w.Args[1] if isVolatile(src) { for _, c := range volatiles { @@ -529,9 +552,8 @@ func writebarrier(f *Func) { case OpVarDef, OpVarLive: mem = bEnd.NewValue1A(pos, w.Op, types.TypeMem, w.Aux, mem) case OpStore: - ptr := w.Args[0] val := w.Args[1] - mem = bEnd.NewValue3A(pos, OpStore, types.TypeMem, w.Aux, ptr, val, mem) + mem = bEnd.NewValue3A(pos, OpStore, types.TypeMem, w.Aux, dst, val, mem) } } @@ -557,6 +579,9 @@ func writebarrier(f *Func) { f.freeValue(w) } } + if nilcheck != nil && nilcheck.Uses == 0 { + nilcheck.reset(OpInvalid) + } // put values after the store sequence into the end block bEnd.Values = append(bEnd.Values, after...) diff --git a/test/nilptr5.go b/test/nilptr5.go index 51a302f252..a76592abad 100644 --- a/test/nilptr5.go +++ b/test/nilptr5.go @@ -30,3 +30,9 @@ func f6(p, q *T) { func f8(t *struct{ b [8]int }) struct{ b [8]int } { return *t // ERROR "removed nil check" } + +// nil check is removed for pointer write (which involves a +// write barrier). +func f9(x **int, y *int) { + *x = y // ERROR "removed nil check" +} diff --git a/test/nilptr5_aix.go b/test/nilptr5_aix.go index 3b116ca19f..cd8ecb1e49 100644 --- a/test/nilptr5_aix.go +++ b/test/nilptr5_aix.go @@ -30,3 +30,9 @@ func f6(p, q *T) { func f8(t *[8]int) [8]int { return *t // ERROR "generated nil check" } + +// On AIX, a write nil check is removed, but a read nil check +// remains (for the write barrier). +func f9(x **int, y *int) { + *x = y // ERROR "generated nil check" "removed nil check" +} diff --git a/test/nilptr5_wasm.go b/test/nilptr5_wasm.go index ea380d1384..e653ffd287 100644 --- a/test/nilptr5_wasm.go +++ b/test/nilptr5_wasm.go @@ -30,3 +30,8 @@ func f6(p, q *T) { func f8(t *[8]int) [8]int { return *t // ERROR "generated nil check" } + +// nil check is not removed on Wasm. +func f9(x **int, y *int) { + *x = y // ERROR "generated nil check" +} -- cgit v1.3-6-g1900 From 51dc5bfe6c1e8e71065401f12cf000b9941882fd Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Fri, 19 Sep 2025 09:25:20 -0700 Subject: Revert "cmd/go: disable cgo by default if CC unset and DefaultCC doesn't exist" This reverts commit c2d85eb999fcd428a1cd71ed93805cbde0c16eaa. Reason for revert: change was incorrect. ignores setting of CGO_ENABLED in some cases Change-Id: I8e6e68dd600be5306a247a3314f4b57175f1aa56 Reviewed-on: https://go-review.googlesource.com/c/go/+/705495 Auto-Submit: Michael Matloob Reviewed-by: Michael Matloob Reviewed-by: Michael Matloob Reviewed-by: Ian Alexander LUCI-TryBot-Result: Go LUCI --- src/cmd/go/internal/cfg/cfg.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/go/internal/cfg/cfg.go b/src/cmd/go/internal/cfg/cfg.go index 97e4eeeff3..a4edd854f1 100644 --- a/src/cmd/go/internal/cfg/cfg.go +++ b/src/cmd/go/internal/cfg/cfg.go @@ -145,8 +145,7 @@ func defaultContext() build.Context { if buildcfg.DefaultCGO_ENABLED == "1" { defaultCgoEnabled = true } else if buildcfg.DefaultCGO_ENABLED == "0" { - } - if runtime.GOARCH == ctxt.GOARCH && runtime.GOOS == ctxt.GOOS { + } else if runtime.GOARCH == ctxt.GOARCH && runtime.GOOS == ctxt.GOOS { defaultCgoEnabled = platform.CgoSupported(ctxt.GOOS, ctxt.GOARCH) // Use built-in default cgo setting for GOOS/GOARCH. // Note that ctxt.GOOS/GOARCH are derived from the preference list -- cgit v1.3-6-g1900 From 7f6ff5ec3edfa1ed82014ad53f6cad3dc023f48e Mon Sep 17 00:00:00 2001 From: Will Faught Date: Fri, 19 Sep 2025 21:59:21 +0000 Subject: cmd/compile: fix doc word "using" -> "uses" Change-Id: I2bcefc6128dafd4fd05d7ce291b1afb28465a25c GitHub-Last-Rev: bf9006eeb65c94a4e492be29f530f511a3d6ffc1 GitHub-Pull-Request: golang/go#75548 Reviewed-on: https://go-review.googlesource.com/c/go/+/705515 Reviewed-by: Keith Randall Auto-Submit: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui Reviewed-by: Keith Randall --- src/cmd/compile/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/cmd') diff --git a/src/cmd/compile/README.md b/src/cmd/compile/README.md index 79d2336154..1089348030 100644 --- a/src/cmd/compile/README.md +++ b/src/cmd/compile/README.md @@ -57,7 +57,7 @@ terms of these, so the next step after type checking is to convert the syntax and types2 representations to ir and types. This process is referred to as "noding." -Noding using a process called Unified IR, which builds a node representation +Noding uses a process called Unified IR, which builds a node representation using a serialized version of the typechecked code from step 2. Unified IR is also involved in import/export of packages and inlining. -- cgit v1.3-6-g1900 From 32dfd69282ac86b0ce49909d36e2a4e5797ad25c Mon Sep 17 00:00:00 2001 From: qmuntal Date: Mon, 22 Sep 2025 12:59:20 +0200 Subject: cmd/dist: disable FIPS 140-3 mode when testing maphash with purego hash/maphash can't be built with FIPS 140-3 mode and the purego tag since CL 703095. That change precludes running "GODEBUG=fips140=on go dist test" with, as there is a test variant that tests maphash with the purego tag. Change-Id: Iaedfaf3bb79281a799ef95283310c96d2e64207f Reviewed-on: https://go-review.googlesource.com/c/go/+/705775 Auto-Submit: Quim Muntal Reviewed-by: Filippo Valsorda LUCI-TryBot-Result: Go LUCI Reviewed-by: Roland Shoemaker Reviewed-by: Michael Knyszek --- src/cmd/dist/test.go | 1 + 1 file changed, 1 insertion(+) (limited to 'src/cmd') diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index 7c26d001bc..1e74438f48 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -705,6 +705,7 @@ func (t *tester) registerTests() { timeout: 300 * time.Second, tags: []string{"purego"}, pkg: "hash/maphash", + env: []string{"GODEBUG=fips140=off"}, // FIPS 140-3 mode is incompatible with purego }) } -- cgit v1.3-6-g1900 From 2353c1578596aae7128f028c75b52c6047f0b057 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Fri, 19 Sep 2025 12:18:26 +0200 Subject: cmd/cgo/internal/test: skip TestMultipleAssign when using UCRT on Windows The Universal C Runtime (UCRT) default behavior is to crash the program when strtol is called with an invalid base (that is, not 0 or 2..36). This an invalid base (that is, not 0 or 2..36). This changes the test to skip when running on Windows and linking with UCRT. When using external linking mode this test passes if using the Mingw-w64 toolchain, even when linking with UCRT. That's because the Mingw-w64 linker adds a _set_invalid_parameter_handler call at startup that overrides the default UCRT behavior. However, other toolchains, like MSVC and LLVM, doesn't override the default behavior. Overriding the default behavior is out of the scope for this test, so the test is skipped instead. Fixes #62887 Change-Id: I60f140faf0eda80a2de4e10876be25e0dbe442d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/705455 Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek --- src/cmd/cgo/internal/test/test.go | 6 ++++++ src/cmd/cgo/internal/test/test_unix.go | 9 ++++++++- src/cmd/cgo/internal/test/test_windows.go | 16 +++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/cgo/internal/test/test.go b/src/cmd/cgo/internal/test/test.go index fb4a8250a2..9626407d88 100644 --- a/src/cmd/cgo/internal/test/test.go +++ b/src/cmd/cgo/internal/test/test.go @@ -1096,6 +1096,12 @@ func testErrno(t *testing.T) { } func testMultipleAssign(t *testing.T) { + if runtime.GOOS == "windows" && usesUCRT(t) { + // UCRT's strtol throws an unrecoverable crash when + // using an invalid base (that is, not 0 or 2..36). + // See go.dev/issue/62887. + t.Skip("skipping test on Windows when linking with UCRT") + } p := C.CString("234") n, m := C.strtol(p, nil, 345), C.strtol(p, nil, 10) defer C.free(unsafe.Pointer(p)) diff --git a/src/cmd/cgo/internal/test/test_unix.go b/src/cmd/cgo/internal/test/test_unix.go index 664c4850d3..9f35583125 100644 --- a/src/cmd/cgo/internal/test/test_unix.go +++ b/src/cmd/cgo/internal/test/test_unix.go @@ -6,6 +6,13 @@ package cgotest -import "syscall" +import ( + "syscall" + "testing" +) var syscall_dot_SIGCHLD = syscall.SIGCHLD + +func usesUCRT(t *testing.T) bool { + return false +} diff --git a/src/cmd/cgo/internal/test/test_windows.go b/src/cmd/cgo/internal/test/test_windows.go index 7bfb33a83c..c6f31430cf 100644 --- a/src/cmd/cgo/internal/test/test_windows.go +++ b/src/cmd/cgo/internal/test/test_windows.go @@ -4,6 +4,20 @@ package cgotest -import "syscall" +import ( + "internal/syscall/windows" + "syscall" + "testing" +) var syscall_dot_SIGCHLD syscall.Signal + +// usesUCRT reports whether the test is using the Windows UCRT (Universal C Runtime). +func usesUCRT(t *testing.T) bool { + name, err := syscall.UTF16PtrFromString("ucrtbase.dll") + if err != nil { + t.Fatal(err) + } + h, err := windows.GetModuleHandle(name) + return err == nil && h != 0 +} -- cgit v1.3-6-g1900 From 9b2d39b75bcc8ced3eaab1c841d7d62e27867931 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Sat, 20 Sep 2025 00:39:03 +0000 Subject: cmd/compile/internal/ssa: match style and formatting Format final sentence in paragraph and make sentence case to match style. Change-Id: I991729257fea202509f59a928b943e10ef1761f4 GitHub-Last-Rev: 770bbf5e7507c0a296f28cb667f0b022a1df846a GitHub-Pull-Request: golang/go#75550 Reviewed-on: https://go-review.googlesource.com/c/go/+/705519 Reviewed-by: Jorropo Reviewed-by: Keith Randall Reviewed-by: Michael Knyszek LUCI-TryBot-Result: Go LUCI Auto-Submit: Jorropo --- src/cmd/compile/internal/ssa/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/compile/internal/ssa/README.md b/src/cmd/compile/internal/ssa/README.md index 8184f9c002..3626f5bb7b 100644 --- a/src/cmd/compile/internal/ssa/README.md +++ b/src/cmd/compile/internal/ssa/README.md @@ -48,8 +48,7 @@ However, certain types don't come from Go and are special; below we will cover Some operators contain an auxiliary field. The aux fields are usually printed as enclosed in `[]` or `{}`, and could be the constant op argument, argument type, -etc. -for example: +etc. For example: v13 (?) = Const64 [1] -- cgit v1.3-6-g1900