Open dvyukov opened 9 years ago
related to #6508
Hi, I wish to add that currently doing go test -race ./...
inside a go:1.5.3-alpine
container, with CGO disabled, will fail due to this.
PROJECT_DIR="${PWD}" #assume we are in $GOPATH/src/github.com/dlsniper/demo on the computer
CONTAINER_PROJECT_DIR="/go/src/github.com/dlsniper/demo"
CONTAINER_PROJECT_GOPATH="${CONTAINER_PROJECT_DIR}/vendor:/go"
docker run --rm \
--net="host" \
-v ${PROJECT_DIR}:${CONTAINER_PROJECT_DIR} \
-e CI=true \
-e GODEBUG=netdns=go \
-e CGO_ENABLED=0 \
-e GOPATH=${CONTAINER_PROJECT_GOPATH} \
-w "${CONTAINER_PROJECT_DIR}" \
golang:1.5.3-alpine \
go test -v -race ./...
Output:
# 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): madvise: 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): pipe: 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
/usr/local/go/pkg/tool/linux_amd64/link: too many errors
Not sure if I should open a separate issue or this comment is enough, please advise. Also the example is not meant to work as it currently points to an non-existing repository but I can make it work if needed.
Thank you.
Please file a separate issue. Race detector must work regardless of dependency on libc. Looks like some issue with linker. Does it work with 1.6? I guess it won't be fixed in 1.5 at this point.
CL https://golang.org/cl/41678 mentions this issue.
This issue seems fairly out of date; these days attempting to use -race
with CGO_ENABLED=0
prints go build: -race requires cgo; enable cgo by setting CGO_ENABLED=1
. The symbols mentioned in the description are out of date as well. What needs to be done to move this forward?
From https://tip.golang.org/doc/go1.20:
On macOS, the race detector has been rewritten not to use cgo: race-detector-enabled programs can be built and run without Xcode. On Linux and other Unix systems, and on Windows, a host C toolchain is required to use the race detector.
I can confirm -race
works with Go 1.20 on macOS (ARM64) with CGO_ENABLED=0
🎉 But it's unclear to me from the note above how other architectures are affected.
On go1.22.5 darwin/arm64
(official build), when I tring to do go run -race
with CGO_ENABLED=0
, I got following error:
go env
I'm not sure if the error is caused by some syscall, but without the -race
flag my program works fine
Race runtime currently depends on libc:
with CGO_ENABLED=0: runtime/race(.text): __libc_malloc: not defined runtime/race(.text): getuid: not defined runtime/race(.text): pthread_self: not defined ...
This has several negative effects:
If we eliminate all libc dependencies from race runtime, all these problems go away.