Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime/race: eliminate dependency on libc #9918

Open
dvyukov opened this issue Feb 18, 2015 · 6 comments
Open

runtime/race: eliminate dependency on libc #9918

dvyukov opened this issue Feb 18, 2015 · 6 comments
Assignees
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Feb 18, 2015

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:

  • don't work with CGO_ENABLED=0
  • there is circular dependency between runtime/race and cmd/cgo
  • cross-compilation is close to impossible
  • external linkage is required

If we eliminate all libc dependencies from race runtime, all these problems go away.

@dvyukov dvyukov added this to the Go1.5Maybe milestone Feb 18, 2015
@dvyukov dvyukov self-assigned this Feb 18, 2015
@dvyukov
Copy link
Member Author

dvyukov commented Feb 18, 2015

related to #6508

@dlsniper
Copy link
Contributor

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.

@dvyukov
Copy link
Member Author

dvyukov commented Feb 23, 2016

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.

@gopherbot
Copy link

CL https://golang.org/cl/41678 mentions this issue.

gopherbot pushed a commit that referenced this issue Apr 25, 2017
…s on Alpine

In an effort to at least understand the complete set of things not
working on Alpine Linux, I've been trying to get the build passing
again, even with tests disabled.

The race detector is broken on Alpine. That is #14481 (and #9918).
So disable those tests for now.

Also, internal linking with PIE doesn't work on Alpine yet.
That is #18243. So disable that test for now.

With this CL, all.bash almost passes. There's some cgo test failing
still, but there's no bug yet, so that can be a separate CL.

Change-Id: I3ffbb0e787ed54cb82f298b6bd5bf3ccfbc82622
Reviewed-on: https://go-review.googlesource.com/41678
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@dvyukov dvyukov changed the title race: eliminate dependency on libc runtime/race: eliminate dependency on libc May 29, 2017
mattbostock added a commit to mattbostock/timbala that referenced this issue Jul 17, 2017
Enable the Go race detector to help surface race conditions when
running the tests.

The race detector currently depends on libc, so does not work with
Alpine Linux (which uses musl):

golang/go#9918
golang/go#14481

Instead, use the default Go Docker image, which uses the libc-based
Debian Jessie and update the Dockerfiles accordingly.
mattbostock added a commit to mattbostock/timbala that referenced this issue Jul 17, 2017
Enable the Go race detector to help surface race conditions when
running the tests.

The race detector currently depends on libc, so does not work with
Alpine Linux (which uses musl):

golang/go#9918
golang/go#14481

Instead, use the default Go Docker image, which uses the libc-based
Debian Jessie and update the Dockerfiles accordingly.
@tamird
Copy link
Contributor

tamird commented Jan 11, 2022

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?

@hx
Copy link

hx commented Feb 15, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants