-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/cgo: add #cgo noescape/nocallback annotations #60399
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
Conversation
This PR (HEAD: 14cb5e6) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/497837 to see it. Tip: You can toggle comments from me using the |
Message from xie cui: Patch Set 1: Run-TryBot+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 1: TryBot-Result+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from DeJiang Zhu (doujiang): Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Ian Lance Taylor: Patch Set 1: (10 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
This PR (HEAD: 1383297) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/497837 to see it. Tip: You can toggle comments from me using the |
This PR (HEAD: 8cff4bc) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/497837 to see it. Tip: You can toggle comments from me using the |
Message from DeJiang Zhu (doujiang): Patch Set 3: (11 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from xie cui: Patch Set 3: Run-TryBot+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 3: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 3: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 3: TryBot-Result-1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
This PR (HEAD: a310150) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/497837 to see it. Tip: You can toggle comments from me using the |
Message from Macrombi Lux: Patch Set 4: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from xie cui: Patch Set 4: Run-TryBot+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 4: (2 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 4: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 4: TryBot-Result-1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
This PR (HEAD: 203f3dd) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/497837 to see it. Tip: You can toggle comments from me using the |
Message from xie cui: Patch Set 5: Run-TryBot+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 5: (2 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 5: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 5: TryBot-Result-1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
This PR (HEAD: 2cad086) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/497837 to see it. Tip: You can toggle comments from me using the |
Message from xie cui: Patch Set 6: Run-TryBot+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 6: (2 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 6: TryBot-Result+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Ian Lance Taylor: Patch Set 6: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
This PR (HEAD: f01351d) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/497837. Important tips:
|
Message from DeJiang Zhu (doujiang): Patch Set 10: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Ian Lance Taylor: Patch Set 10: Run-TryBot+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 10: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 10: TryBot-Result+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Ian Lance Taylor: Patch Set 10: (11 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Signed-off-by: doujiang24 <[email protected]>
This PR (HEAD: d5dd38d) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/497837. Important tips:
|
Message from DeJiang Zhu (doujiang): Patch Set 10: (12 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Ian Lance Taylor: Patch Set 11: Run-TryBot+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 11: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 11: TryBot-Result+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Ian Lance Taylor: Patch Set 11: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Signed-off-by: doujiang24 <[email protected]>
This PR (HEAD: 6e4adbc) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/497837. Important tips:
|
Message from DeJiang Zhu (doujiang): Patch Set 12: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Ian Lance Taylor: Patch Set 12: Run-TryBot+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 12: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 12: TryBot-Result+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Ian Lance Taylor: Patch Set 12: Auto-Submit+1 Code-Review+2 Run-TryBot+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Bryan Mills: Patch Set 12: Code-Review+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Signed-off-by: doujiang24 <[email protected]>
This PR (HEAD: f1a17b0) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/497837. Important tips:
|
Message from DeJiang Zhu (doujiang): Patch Set 13: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Bryan Mills: Patch Set 13: Auto-Submit+1 Code-Review+1 Run-TryBot+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
Message from Gopher Robot: Patch Set 13: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/497837. |
When passing pointers of Go objects from Go to C, the cgo command generate _Cgo_use(pN) for the unsafe.Pointer type arguments, so that the Go compiler will escape these object to heap. Since the C function may callback to Go, then the Go stack might grow/shrink, that means the pointers that the C function have will be invalid. After adding the #cgo noescape annotation for a C function, the cgo command won't generate _Cgo_use(pN), and the Go compiler won't force the object escape to heap. After adding the #cgo nocallback annotation for a C function, which means the C function won't callback to Go, if it do callback to Go, the Go process will crash. Fixes #56378 Change-Id: Ifdca070584e0d349c7b12276270e50089e481f7a GitHub-Last-Rev: f1a17b0 GitHub-Pull-Request: #60399 Reviewed-on: https://go-review.googlesource.com/c/go/+/497837 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
This PR is being closed because golang.org/cl/497837 has been merged. |
When passing pointers of Go objects from Go to C, the cgo command generate _Cgo_use(pN) for the unsafe.Pointer type arguments, so that the Go compiler will escape these object to heap.
Since the C function may callback to Go, then the Go stack might grow/shrink, that means the pointers that the C function have will be invalid.
After adding the #cgo noescape annotation for a C function, the cgo command won't generate _Cgo_use(pN), and the Go compiler won't force the object escape to heap.
After adding the #cgo nocallback annotation for a C function, which means the C function won't callback to Go, if it do callback to Go, the Go process will crash.
Fixes #56378