internal/fakecgo: correct the explanation of using closure calls (#85)
PR #73 circumvent go 1.20 race mode on darwin. However, the explanation for using the closure calls are partly wrong, and also not so much clear about how the trick works. This commit reworks the comments, and adding a more detail explanation. Updates #71
- commit
- a7c4d8fb43b1fe6b3cbde6e9495935f06f538af2
- author
- Cuong Manh Le · · 2023-01-07 01:10 UTC
- committer
- GitHub · · 2023-01-07 01:10 UTC
- parent
- 9e27b96
- signature
- GPG Unverified
4AEE18F83AFDEB23The key is unknown
1 file · +10 -4
M internal/fakecgo/callbacks.go +10 -4
| @@ -46,10 +46,16 @@ var ( | |||
| 46 | 46 | // In Go 1.20 the race detector was rewritten to pure Go | |
| 47 | 47 | // on darwin. This means that when CGO_ENABLED=0 is set | |
| 48 | 48 | // fakecgo is built with race detector code. This is not | |
| 49 | - | // good since this code is pretending to be C. The | |
| 50 | - | // go:norace comments are not enough since the ABI wrappers | |
| 51 | - | // still have race code. These variables will circumvent | |
| 52 | - | // that issue by calling the function directly. | |
| 49 | + | // good since this code is pretending to be C. The go:norace | |
| 50 | + | // pragma is not enough, since it only applies to the native | |
| 51 | + | // ABIInternal function. The ABIO wrapper (which is necessary, | |
| 52 | + | // since all references to text symbols from assembly will use it) | |
| 53 | + | // does not inherit the go:norace pragma, so it will still be | |
| 54 | + | // instrumented by the race detector. | |
| 55 | + | // | |
| 56 | + | // To circumvent this issue, using closure calls in the | |
| 57 | + | // assembly, which forces the compiler to use the ABIInternal | |
| 58 | + | // native implementation (which has go:norace) instead. | |
| 53 | 59 | threadentry_call = threadentry | |
| 54 | 60 | x_cgo_init_call = x_cgo_init | |
| 55 | 61 | x_cgo_setenv_call = x_cgo_setenv | |
| @@ -46,10 +46,16 @@ var ( | |||||
| 46 | // In Go 1.20 the race detector was rewritten to pure Go | 46 | // In Go 1.20 the race detector was rewritten to pure Go | ||
| 47 | // on darwin. This means that when CGO_ENABLED=0 is set | 47 | // on darwin. This means that when CGO_ENABLED=0 is set | ||
| 48 | // fakecgo is built with race detector code. This is not | 48 | // fakecgo is built with race detector code. This is not | ||
| 49 | - | // good since this code is pretending to be C. The | 49 | + | // good since this code is pretending to be C. The go:norace |
| 50 | - | // go:norace comments are not enough since the ABI wrappers | 50 | + | // pragma is not enough, since it only applies to the native |
| 51 | - | // still have race code. These variables will circumvent | 51 | + | // ABIInternal function. The ABIO wrapper (which is necessary, |
| 52 | - | // that issue by calling the function directly. | 52 | + | // since all references to text symbols from assembly will use it) |
| 53 | + | // does not inherit the go:norace pragma, so it will still be | |||
| 54 | + | // instrumented by the race detector. | |||
| 55 | + | // | |||
| 56 | + | // To circumvent this issue, using closure calls in the | |||
| 57 | + | // assembly, which forces the compiler to use the ABIInternal | |||
| 58 | + | // native implementation (which has go:norace) instead. | |||
| 53 | threadentry_call = threadentry | 59 | threadentry_call = threadentry | ||
| 54 | x_cgo_init_call = x_cgo_init | 60 | x_cgo_init_call = x_cgo_init | ||
| 55 | x_cgo_setenv_call = x_cgo_setenv | 61 | x_cgo_setenv_call = x_cgo_setenv | ||