Oriel — AI & technology worth noticing, every day.

Cgo's pointer check is all over the place

Web page · https://theconsensus.dev/p/2026/11/15/cgos-pointer-check.html

First seen by Oriel on .

AI summary

The article argues that cgo’s syntax-based pointer transformations produce inconsistent correctness checks, including panics on legal code and call latency ranging from 48ns to 76µs.

  • cmd/cgo generates Go and C wrappers that package function arguments behind one pointer, bridging Go and C calling conventions.
  • Go permits pointers to Go memory only when reachable Go pointers are pinned; runtime.Pinner supports this, while GODEBUG=cgocheck=0 disables runtime checking.
  • Passing unsafe.Pointer(&s.small) succeeds because cgo recognizes the field, but assigning that identical address to a variable before passing it causes a panic.
  • When pointer type information is unavailable, runtime.cgoCheckUnknownPointer scans the entire containing heap object, finding s.other even though only s.small was passed.
  • The article reports that syntactically small changes can make equivalent calls roughly 1,600 times slower and that argument checking can be exhaustive, lax, or abandoned.

#go #cgo #ffi #garbage collection

Generated by gpt-5.6-sol. Check the original for details.

Metric trends

Last 30 days · Up to 120 recorded samples per source and metric, with reposts kept separate · First and latest retained

Points

Score reported by the source.

  • Hacker News: 5, latest observation
  • Lobsters: 27, latest observation ; +26 over observed period since

Comments

Comment count reported by the source.

  • Hacker News: 0, latest observation
  • Lobsters: 5, latest observation ; +5 over observed period since

Aliases

SourceExternal IDURL
Hacker News50639999https://theconsensus.dev/p/2026/11/15/cgos-pointer-check.html Read discussion
Lobstersfgbvtthttps://theconsensus.dev/p/2026/11/15/cgos-pointer-check.html Read discussion