Race detection with CGO_ENABLED=0?

366 views
Skip to first unread message

Blake Caldwell

unread,
Feb 17, 2015, 4:09:22 PM2/17/15
to golan...@googlegroups.com
I'm building my service without CGO, so ideally, I'd like to run my tests with the same settings, and I really like race detection. Is there any way to use the race detector with CGO_ENABLED=0?

# testmain
runtime/race(.text): __libc_malloc: not defined
runtime/race(.text): getuid: not defined
runtime/race(.text): pthread_self: not defined
runtime/race(.text): madvise: not defined
runtime/race(.text): sleep: not defined
runtime/race(.text): usleep: not defined
runtime/race(.text): abort: not defined
runtime/race(.text): isatty: not defined
runtime/race(.text): __libc_free: not defined
runtime/race(.text): getrlimit: not defined
runtime/race(.text): __libc_stack_end: not defined
runtime/race(.text): getrlimit: not defined
runtime/race(.text): setrlimit: not defined
runtime/race(.text): setrlimit: not defined
runtime/race(.text): setrlimit: not defined
runtime/race(.text): exit: not defined
runtime/race(.text.unlikely): __errno_location: not defined
runtime/race(.text): undefined: __libc_malloc
runtime/race(.text): undefined: getuid
runtime/race(.text): undefined: pthread_self
runtime/race(.text): undefined: madvise
too many errors

Dave Cheney

unread,
Feb 17, 2015, 10:15:09 PM2/17/15
to golan...@googlegroups.com
The race detector needs cgo, the race detector lives in a .so that provides those missing symbols. 

The simplest solution may be to modify your go install to always use the pure go resolver, look for the // +build netgo tags, and remove "linux" from the version that uses cgo, this should let you have both cgo an the pure Go resolver, and thus the race detector at the same time.

Dmitry Vyukov

unread,
Feb 18, 2015, 2:07:03 AM2/18/15
to Blake Caldwell, golang-nuts
Yes, unfortunately it does not work now.
I have this in plans for a long time. Filed:
https://github.com/golang/go/issues/9918
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Blake Caldwell

unread,
Feb 18, 2015, 11:56:12 AM2/18/15
to golan...@googlegroups.com
Thanks guys!
Reply all
Reply to author
Forward
0 new messages