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

Open
aarzilli opened this issue Dec 18, 2018 · 2 comments
Open

runtime: externally linked programs don't detect deadlocks #29322

aarzilli opened this issue Dec 18, 2018 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@aarzilli
Copy link
Contributor

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
Copy link
Contributor

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.

@ianlancetaylor ianlancetaylor added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Dec 18, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Dec 18, 2018
@cherrymui
Copy link
Member

We now support internal linking for PIE (and use by default) on a few platforms, including Linux/AMD64, Linux/ARM64, macOS/AMD64, macOS/ARM64, Windows, and some Android platforms. And deadlock detection does work.

It still doesn't work with external linking (PIE or not).

@cherrymui cherrymui changed the title runtime: PIEs don't detect deadlocks runtime: external linked programs don't detect deadlocks May 20, 2021
@cherrymui cherrymui changed the title runtime: external linked programs don't detect deadlocks runtime: externally linked programs don't detect deadlocks May 20, 2021
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants