crypto/aes (and others): data race not detected due to assembly #63817
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
RaceDetector
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
Race detector doesn't instrument assembly functions, hence some of the data races go undetected.
For example, here's an obviously racy
crypto/aes
example, but running it with-race
does not detect it.https://go.dev/play/p/dK-fJz-p5ey
This is definitely not isolated to
crypto/aes
, but any standard (or external) library package that uses assembly.Going over the standard libary, assembly was used in:
Of course, not all of them are problematic in terms of data races.
Similar search for
x/crypto
packages:What did you expect to see?
A data race being detected in packages that use assembly.
What did you see instead?
No data race in an obviously racy code.
So, there seem to be two main issues:
I guess there are few ways to make the behavior visible to race detector:
-race
is used, and use Go code insteadNot using assembly can be a significant performance hit in some scenarios, so switching off assembly doesn't seem ideal.
The other approach is to call the race detector functions directly, e.g.
runtime.RaceReadRange
,runtime.RaceWriteRange
. One of the problems is that those functions are only exposed whenrace
tag is present, making it more annoying to instrument third-party packages. Standard library does have access tointernal/race
, which is conditionally compiled with-race
. It would be nice to use a similar package (maybe expose some of it inruntime/race
) from third-party party libraries. Of course, it shouldn't expose things likeDisable
,Enable
orEnabled
.Third approach is to add some magic incantation to assembly code to allow the compiler to add appropriate race detection, e.g. rough draft (ignore whether I got the content correct):
Of course, writing those annotations in comments is significantly more annoying than using some nicer Go API.
There's a related issue #61204, about
internal/bytes
package which has some additional constraints the non-internal packages don't have.The text was updated successfully, but these errors were encountered: