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 · 7 comments
Open

runtime/race: eliminate dependency on libc #9918

dvyukov opened this issue Feb 18, 2015 · 7 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
Contributor

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 <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
@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.

@zyxkad
Copy link
Contributor

zyxkad commented Jul 15, 2024

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
$ go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/ckpn/Library/Caches/go-build'
GOENV='/Users/ckpn/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/ckpn/Mine/projects/golang/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/ckpn/Mine/projects/golang'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.5'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='0'
GOMOD='/Users/ckpn/Mine/projects/golang/src/github.com/zyxkad/drone/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/3g/rxdhvbj96lv68y35t2cvghkr0000gn/T/go-build525222943=/tmp/go-build -gno-record-gcc-switches -fno-common'
Logs
SIGSEGV: segmentation violation
PC=0x1046f423c m=0 sigcode=2 addr=0x10
signal arrived during cgo execution

goroutine 1 gp=0xc0000021c0 m=0 mp=0x1052b3380 [syscall, locked to thread]:
runtime.cgocall(0x104b7d1c0, 0x0)
        /usr/local/go/src/runtime/cgocall.go:157 +0x58 fp=0xc00008df40 sp=0xc00008df00 pc=0x104739848
runtime.main()
        /usr/local/go/src/runtime/proc.go:242 +0x214 fp=0xc00008dfd0 sp=0xc00008df40 pc=0x10476f0d4
runtime.goexit({})
        /usr/local/go/src/runtime/asm_arm64.s:1222 +0x4 fp=0xc00008dfd0 sp=0xc00008dfd0 pc=0x1047a4ba4

goroutine 2 gp=0xc000002c40 m=nil [force gc (idle)]:
runtime.gopark(0x0?, 0x105265d30?, 0x80?, 0x33?, 0x0?)
        /usr/local/go/src/runtime/proc.go:402 +0xc8 fp=0xc000072790 sp=0xc000072770 pc=0x10476f578
runtime.goparkunlock(...)
        /usr/local/go/src/runtime/proc.go:408
runtime.forcegchelper()
        /usr/local/go/src/runtime/proc.go:326 +0xb8 fp=0xc0000727d0 sp=0xc000072790 pc=0x10476f408
runtime.goexit({})
        /usr/local/go/src/runtime/asm_arm64.s:1222 +0x4 fp=0xc0000727d0 sp=0xc0000727d0 pc=0x1047a4ba4
created by runtime.init.6 in goroutine 1
        /usr/local/go/src/runtime/proc.go:314 +0x24

goroutine 3 gp=0xc000003180 m=nil [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /usr/local/go/src/runtime/proc.go:402 +0xc8 fp=0xc000088f60 sp=0xc000088f40 pc=0x10476f578
runtime.goparkunlock(...)
        /usr/local/go/src/runtime/proc.go:408
runtime.bgsweep(0xc000044070)
        /usr/local/go/src/runtime/mgcsweep.go:278 +0xa0 fp=0xc000088fb0 sp=0xc000088f60 pc=0x10475b430
runtime.gcenable.gowrap1()
        /usr/local/go/src/runtime/mgc.go:203 +0x28 fp=0xc000088fd0 sp=0xc000088fb0 pc=0x10474f668
runtime.goexit({})
        /usr/local/go/src/runtime/asm_arm64.s:1222 +0x4 fp=0xc000088fd0 sp=0xc000088fd0 pc=0x1047a4ba4
created by runtime.gcenable in goroutine 1
        /usr/local/go/src/runtime/mgc.go:203 +0x6c

goroutine 4 gp=0xc000003340 m=nil [GC scavenge wait]:
runtime.gopark(0xc000044070?, 0x104e5a100?, 0x1?, 0x0?, 0xc000003340?)
        /usr/local/go/src/runtime/proc.go:402 +0xc8 fp=0xc000194f60 sp=0xc000194f40 pc=0x10476f578
runtime.goparkunlock(...)
        /usr/local/go/src/runtime/proc.go:408
runtime.(*scavengerState).park(0x1052b1aa0)
        /usr/local/go/src/runtime/mgcscavenge.go:425 +0x5c fp=0xc000194f90 sp=0xc000194f60 pc=0x104758e4c
runtime.bgscavenge(0xc000044070)
        /usr/local/go/src/runtime/mgcscavenge.go:653 +0x44 fp=0xc000194fb0 sp=0xc000194f90 pc=0x104759374
runtime.gcenable.gowrap2()
        /usr/local/go/src/runtime/mgc.go:204 +0x28 fp=0xc000194fd0 sp=0xc000194fb0 pc=0x10474f608
runtime.goexit({})
        /usr/local/go/src/runtime/asm_arm64.s:1222 +0x4 fp=0xc000194fd0 sp=0xc000194fd0 pc=0x1047a4ba4
created by runtime.gcenable in goroutine 1
        /usr/local/go/src/runtime/mgc.go:204 +0xac

r0      0x0
r1      0x104b7d1d0
r2      0xc00008def0
r3      0x1052b2080
r4      0x110
r5      0xc000002250
r6      0x1
r7      0x0
r8      0x1052b3380
r9      0x1046f422c
r10     0x1052b3380
r11     0x1052b2080
r12     0x1000000000000000
r13     0x16b70f300
r14     0xffffff0000000000
r15     0x0
r16     0xc00008d6c0
r17     0x1f4b05938
r18     0x0
r19     0x104b7d1d0
r20     0x0
r21     0x16b70f2e0
r22     0x105324c14
r23     0x16b70f410
r24     0x16b70f450
r25     0x18260231b
r26     0x104faa0c8
r27     0x105324000
r28     0x1052b2080
r29     0x16b70f278
lr      0x1047a59a4
sp      0x16b70f260
pc      0x1046f423c
fault   0x10
exit status 2

I'm not sure if the error is caused by some syscall, but without the -race flag my program works fine

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

7 participants