Summary
runtime.GOMAXPROCS(n) in an LLGo-generated program returns the host maximum but does not apply positive n. This also makes go test -cpu=1 ineffective and causes the testing package to report that every benchmark left GOMAXPROCS at the host CPU count.
Tested on xgo-dev/llgo main at 60c30f2ff, Go 1.26.5, LLVM 22.1.8, Darwin/arm64.
Minimal reproduction
package main
import "runtime"
func main() {
before := runtime.GOMAXPROCS(0)
previous := runtime.GOMAXPROCS(1)
after := runtime.GOMAXPROCS(0)
println(before, previous, after)
if previous != before || after != 1 {
panic("runtime.GOMAXPROCS did not apply the requested value")
}
}
With GOMAXPROCS=4, the host Go toolchain prints:
The current LLGo main build prints and then panics:
16 16 16
panic: runtime.GOMAXPROCS did not apply the requested value
The implementation currently ignores n:
func GOMAXPROCS(n int) int {
return int(c_maxprocs())
}
Impact
testing cannot enforce -test.cpu / go test -cpu.
- Benchmarks emit messages such as
testing: BenchmarkDirectCall left GOMAXPROCS set to 16.
- Programs that use GOMAXPROCS to bound parallelism observe incorrect standard-library behavior.
A regression test can use the program above and assert that the setter returns the previous value and that a subsequent query returns the requested value.
Summary
runtime.GOMAXPROCS(n)in an LLGo-generated program returns the host maximum but does not apply positiven. This also makesgo test -cpu=1ineffective and causes the testing package to report that every benchmark left GOMAXPROCS at the host CPU count.Tested on
xgo-dev/llgomain at60c30f2ff, Go 1.26.5, LLVM 22.1.8, Darwin/arm64.Minimal reproduction
With
GOMAXPROCS=4, the host Go toolchain prints:The current LLGo main build prints and then panics:
The implementation currently ignores
n:Impact
testingcannot enforce-test.cpu/go test -cpu.testing: BenchmarkDirectCall left GOMAXPROCS set to 16.A regression test can use the program above and assert that the setter returns the previous value and that a subsequent query returns the requested value.