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: PIEs don't detect deadlocks #29322

Open
aarzilli opened this Issue Dec 18, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@aarzilli
Copy link
Contributor

aarzilli commented Dec 18, 2018

What version of Go are you using (go version)?

$ go version
go version go1.11.4 linux/amd64

Does this issue reproduce with the latest release?

Yes (also master as of last week)

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/a/.cache/go-build"
GOEXE=""
GOFLAGS="-mod=vendor"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/a/n/go/"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build536260035=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Did go run -buildmode=pie with this:

package main

func main() {
	ch1 := make(chan string)
	ch2 := make(chan string)
	go func() {
		<-ch1
		ch2 <- "done"
	}()
	<-ch2
	ch1 <- "done"
}

What did you expect to see?

Process dies with the "all goroutines are asleep" message.

What did you see instead?

Not dead but forever sleeping.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

ianlancetaylor commented Dec 18, 2018

This is happening because using -buildmode=pie causes the final link to be done using the external linker, which causes the runtime to think that the program uses cgo. In a program that uses cgo the deadlock detector is, in effect, disabled, because it is possible that the C code has started a new thread.

The fix would require separating the use of the external linker from actually using cgo.

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