debug.cgocheck is a configuration in the runtime package which controls whether to check cgo parameter. It's set by the GODEBUG=cgocheck=xxx. But unlike debug variable GODEBUG=panicnil=xxx, the cgocheck=xxx is only set once and can't be changed at runtime.
If a framework requires disabling cgocheck, as there is no way to change cgocheck=xxx at runtime, the framework developers have to require the user to set this env var manually which is inconvenient.
At first glance, it looks like we can implement this idea by changing
to an atomic. Then the cgocheck=xxx can be updated like the panicnil.
Background
As mentioned in #56378 (comment), We are implementing the Envoy Golang filter extension by using cgo. Currently, we disable cgocheck for a better performance.
We do it by using the env var GODEBUG=cgocheck=0, but it is inconvenient for users to set up this variable. As discussed in envoyproxy/envoy#25178 (comment), we hope to change Go's code to allow disabling cgocheck at runtime.
Why we can't set the env var outside? Because Go's env vars are coming from the argv:
// TODO(austin): ppc64 in dynamic linking mode doesn't
// guarantee env[] will immediately follow argv. Might cause
// problems.
n:=int32(0)
forargv_index(argv, argc+1+n) !=nil {
n++
}
envs=make([]string, n)
fori:=int32(0); i<n; i++ {
envs[i] =gostring(argv_index(argv, argc+1+i))
}
}
when loading a Go library via dlopen, the argv is passed by libc with a pre-stored var (assigned in the _init function when the host starts). So there is no way for the host to add the env var.
Another solution is to use the //go:debug flag. Unfortunately, as a framework developer, we cannot control users’ main package or the compile flags.
If such a change is acceptable, I am willing to submit it.
The text was updated successfully, but these errors were encountered:
debug.cgocheck
is a configuration in the runtime package which controls whether to check cgo parameter. It's set by theGODEBUG=cgocheck=xxx
. But unlike debug variableGODEBUG=panicnil=xxx
, thecgocheck=xxx
is only set once and can't be changed at runtime.If a framework requires disabling cgocheck, as there is no way to change
cgocheck=xxx
at runtime, the framework developers have to require the user to set this env var manually which is inconvenient.At first glance, it looks like we can implement this idea by changing
go/src/runtime/runtime1.go
Line 344 in c6fd0c2
cgocheck=xxx
can be updated like thepanicnil
.Background
As mentioned in #56378 (comment), We are implementing the Envoy Golang filter extension by using cgo. Currently, we disable
cgocheck
for a better performance.We do it by using the env var
GODEBUG=cgocheck=0
, but it is inconvenient for users to set up this variable. As discussed in envoyproxy/envoy#25178 (comment), we hope to change Go's code to allow disabling cgocheck at runtime.Why we can't set the env var outside? Because Go's env vars are coming from the argv:
go/src/runtime/runtime1.go
Lines 82 to 96 in c6fd0c2
when loading a Go library via dlopen, the argv is passed by libc with a pre-stored var (assigned in the
_init
function when the host starts). So there is no way for the host to add the env var.Another solution is to use the
//go:debug
flag. Unfortunately, as a framework developer, we cannot control users’ main package or the compile flags.If such a change is acceptable, I am willing to submit it.
The text was updated successfully, but these errors were encountered: