Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: runtime: Allow changing debug.cgocheck at runtime #60426

spacewander opened this issue May 25, 2023 · 1 comment

proposal: runtime: Allow changing debug.cgocheck at runtime #60426

spacewander opened this issue May 25, 2023 · 1 comment


Copy link

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

{name: "cgocheck", value: &debug.cgocheck},
to an atomic. Then the cgocheck=xxx can be updated like the panicnil.


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:

func goenvs_unix() {
// TODO(austin): ppc64 in dynamic linking mode doesn't
// guarantee env[] will immediately follow argv. Might cause
// problems.
n := int32(0)
for argv_index(argv, argc+1+n) != nil {
envs = make([]string, n)
for i := 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.

@gopherbot gopherbot added this to the Proposal milestone May 25, 2023
Copy link

CC @golang/runtime @randall77

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Status: Incoming

No branches or pull requests

3 participants