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

Comments

@aarzilli
Copy link
Contributor

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

@ianlancetaylor 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.

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented May 20, 2021

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants