Description
It is not allowed to have C pointers into go memory, from my understanding, mostly because the go stack is movable.
The only reliable way to find bugs in this is currently just using manual review.
I propose that there should be a way to force the runtime to move the stack at random intervals.
This could be done entirely in runtime with a ENV variable, or a compile option due to runtime overhead.
context:
I am currently working on improving performance of a c->go transpiler (ccgo by @cznic, https://gitlab.com/cznic/ccgo) in this case by allowing some pointers to be *T
instead of uintptr
. It is a fine line between the 2, but in no circumstance should they ever be mixed because of the movable stack (no C pointer to go stack). ccgo runs all GCC tests to verify it translates properly. Getting all the tests to work isnt too complicated. However there might be cases where a uintptr
points to go allocated object, and it just works because the stack wasn't moved. It is impossible to verify this doesn't happen, I would have to manually check 1300 GCC test, and preferably also some randomly generated code.
This is of course a unique situation, however I think this could also help less aware people find these problems.
This would of course not be able to verify the code, however, just like fuzzing, it means we can be much more confident in the code.
CC @josharian @ianlancetaylor @prattmic @aclements on recommendations of josh