Go version
go1.26.4 windows/amd64
What did you do
Built a cgo program on Windows using clang as the C compiler, specifically the one bundled with Visual Studio 2026 (clang 22.1.3, targets x86_64-pc-windows-msvc by default):
set CGO_ENABLED=1
set CC=clang
go build .
Any build that pulls in runtime/cgo reproduces it. Standalone repro with a failing CI run on a stock GitHub windows-latest runner: https://github.com/m-this/go-cgo-mthreads-repro (run: https://github.com/m-this/go-cgo-mthreads-repro/actions/runs/28890285104, built with go build -x so the full compiler invocation is visible).
What did you see happen
# runtime/cgo
clang: error: unsupported option '-mthreads' for target 'x86_64-pc-windows-msvc'
cmd/go unconditionally appends -mthreads to the compiler command line for cgo builds on Windows (ccompilerCmd in src/cmd/go/internal/work/exec.go), visible in GOGCCFLAGS=-m64 -mthreads .... The flag is MinGW-only. Clang used to accept it with an "argument unused during compilation" warning, but since the driver started treating MinGW link flags as target specific (llvm/llvm-project D151590 and follow-ups), it is a hard error for non-MinGW targets. So any cgo build with CC=clang on such a toolchain fails at runtime/cgo, before compiling any user code.
#16932 reported the broader "cgo assumes MinGW" problem in 2016 and was closed without a fix.
What did you expect to see
The build succeeding. -mthreads could be passed only when the compiler actually targets MinGW, or probed with the existing gccSupportsFlag mechanism like other optional flags.
Go version
go1.26.4 windows/amd64
What did you do
Built a cgo program on Windows using clang as the C compiler, specifically the one bundled with Visual Studio 2026 (clang 22.1.3, targets
x86_64-pc-windows-msvcby default):Any build that pulls in
runtime/cgoreproduces it. Standalone repro with a failing CI run on a stock GitHubwindows-latestrunner: https://github.com/m-this/go-cgo-mthreads-repro (run: https://github.com/m-this/go-cgo-mthreads-repro/actions/runs/28890285104, built withgo build -xso the full compiler invocation is visible).What did you see happen
cmd/go unconditionally appends
-mthreadsto the compiler command line for cgo builds on Windows (ccompilerCmdinsrc/cmd/go/internal/work/exec.go), visible inGOGCCFLAGS=-m64 -mthreads .... The flag is MinGW-only. Clang used to accept it with an "argument unused during compilation" warning, but since the driver started treating MinGW link flags as target specific (llvm/llvm-project D151590 and follow-ups), it is a hard error for non-MinGW targets. So any cgo build with CC=clang on such a toolchain fails atruntime/cgo, before compiling any user code.#16932 reported the broader "cgo assumes MinGW" problem in 2016 and was closed without a fix.
What did you expect to see
The build succeeding.
-mthreadscould be passed only when the compiler actually targets MinGW, or probed with the existinggccSupportsFlagmechanism like other optional flags.