Go build -race with binary packages and CGO

Hi, I’m trying to understand if it is possible to use -race for build/testrun while linking binary packages that use cgo : lookup at go build code there seems to be a requierement CGO_ENABLED=1 :

but then there an exclusion during what seems to be a cgo related part :
like if linking cgo dependencies is disabled if the -race flag is true.
Anyone knows if binary packages + cgo are testable with -race ?

Thanks in advance

I think the race detector should work even in the presence of cgo packages, but I’m not sure if it covers accesses done from C land.

-trace is something else though, and there I’m not sure. Although I would expect it to work.

Have you tried?

Sorry, it was a typo for -race : looks like that -race works with a go source package (even if the package uses CGO) but does not when the packge is a binary one.

That I can believe. The race detector adds instrumentation to the code when it compiles it. If it can’t compile it, that can’t happen.

Is there a way to provide -race compiled binaries as a binary-package ? I tried to build the binary package using -race but this does not work.

I’ve no idea, I’ve never used a binary package. But what would be the point? If a problem was detected it would point to the source, and require the source to understand, source which doesn’t exist.

Consider a project with 100 packages and tests running after -race build. If one binary package prevents the whole suite from running in -race mode this might be perceived as a problem.

Oh, certainly. I thought you were talking about being able to run race testing on the binary package.

In general, binary packages are not a well supported thing.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.