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

go/build: -race build program that fails with ERROR: ThreadSanitizer failed to allocate #33514

Closed
AdamSLevy opened this issue Aug 7, 2019 · 6 comments

Comments

@AdamSLevy
Copy link

AdamSLevy commented Aug 7, 2019

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

$ go version
go version go1.12.7 linux/amd64

Does this issue reproduce with the latest release?

yes.

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/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-build234687535=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Create a simple go program.

package main

import "fmt"

func main() {
	fmt.Println("vim-go")
}

Build and run it with race detection enabled.

go run -race ./main.go

What did you expect to see?

The program should output "vim-go".

What did you see instead?

$ go run -race ./main.go 
==27053==ERROR: ThreadSanitizer failed to allocate 0x26f1000 (40833024) bytes at address 176ecc1200000 (errno: 12)
unexpected fault address 0x0
fatal error: fault
unexpected fault address 0x55bb3038c2ec
fatal error: fault
unexpected fault address 0x55bb30e38d6a
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x2 addr=0x55bb30e38d6a pc=0x55bb30e38d6a]

goroutine 1 [running, locked to thread]:
runtime: unexpected return pc for runtime.throw called from 0x55bb3038c0fb
stack: frame={sp:0x7fff317f3270, fp:0x7fff317f32a0} stack=[0xc000048000,0xc000048800)

runtime.throw(0x3, 0x3)
	/usr/lib/go/src/runtime/panic.go:617 +0x74 fp=0x7fff317f32a0 sp=0x7fff317f3270 pc=0x55bb302de804
exit status 2

The result is the same if building and running the program happens in separate steps.

@ALTree
Copy link
Member

ALTree commented Aug 7, 2019

Are you on Arch? Did you install Go from the OS package manager?

@AdamSLevy
Copy link
Author

Yes I am and I just discovered that I had go-pie installed. I tested the straight go package and the issue went away.

Something about the PIE compiled version is related to this.

@ALTree
Copy link
Member

ALTree commented Aug 7, 2019

Yeah the pie + -race combination is not supported, the race runtime assumes that the executable is loaded around the 0 address. We actually reject the combination in go build:

 $ go build --buildmode=pie -race test.go
-buildmode=pie not supported when -race is enabled

but obviously if you run with an Arch package that has pie enabled by default you'll bypass the check since it'll build pies by default.

@AdamSLevy
Copy link
Author

Okay thank you. This explains it. I'll go ahead and close the issue.

@av86743
Copy link

av86743 commented Aug 7, 2019

"go does not reject -race when buildmode=pie is enabled by default"

@AdamSLevy Downstream problem - consider to report.

@ALTree
Copy link
Member

ALTree commented Aug 7, 2019

go does not reject -race when buildmode=pie is enabled by default

@av86743 The platforms where pie is enabled by default in the toolchain are android/arm, android/arm64, android/amd64, and android/386 but none of these supports the race detector, so in practise this is not a problem, and we can just reject -race by checking that --buildmode=pie was set.

If you set -race with one of those you'll get an error in an early check informing you that you can't use the race detector.

So the only way to see the crash reported here is to use a patched toolchain (like the go-pie in Arch).
Usually we don't fix issues that can be triggered exclusively on patches applied downstream.

@ALTree ALTree changed the title go build/run -race build program that fails with ERROR: ThreadSanitizer failed to allocate go/build: -race build program that fails with ERROR: ThreadSanitizer failed to allocate Aug 7, 2019
@golang golang locked and limited conversation to collaborators Aug 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants