Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/cgo: C functions that return values fail if they call a Go callback that copies the stack #8771
Cgo uses a wrapper function that calls C code, passing the address of the stack frame. This wrapper function is compiled by GCC, and it calls the real function written by the user. The user's function is permitted to call Go callbacks. Those Go callbacks will run on the stack of the original caller. They may cause a stack copy. If the stack gets copied during a Go callback, then the caller of the GCC-compiled wrapper is running in a different location. The stack frame pointer used by the GCC-compiled wrapper is not updated, since of course the stack copier knows nothing about GCC-compiled code. I don't think this is a problem for the arguments to the function; they have already been copied out of the stack frame when the wrapper calls the real function. However, it is a problem for C functions that return a value. The wrapper will take the value returned by the C function, and store it using its pointer to the stack frame. That pointer will not have been updated if a stack copy occurs. In other words, the wrapper may store the return value on the old stack, not the new one. There is a test case demonstrating the problem in https://golang.org/cl/145130043.
This issue was closed.