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

cmd/go: -msan failure when rebuilding runtime/cgo with -fsanitize=memory #13815

Closed
tamird opened this issue Jan 4, 2016 · 4 comments
Closed
Milestone

Comments

@tamird
Copy link
Contributor

tamird commented Jan 4, 2016

foo_test.go:

package foo

import "testing"

func FooTest(t *testing.T) {
}
$ go test -msan
==1083== WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7ff79a84d2a8  (/tmp/go-build084496566/github.com/cockroachdb/cockroach/foo/_test/foo.test+0x30a2a8)
    #1 0x7ff79a74f7ac  (/tmp/go-build084496566/github.com/cockroachdb/cockroach/foo/_test/foo.test+0x20c7ac)

Exiting
exit status 77
FAIL    github.com/cockroachdb/cockroach/foo    0.013s

Running under lldb didn't reveal much other than the involvement of cgo (I had to build the executable to get image lookup to work):

$ go test -msan -c -o foo.test
$ lldb-3.6 -- foo.test
(lldb) target create "foo.test"
Current executable set to 'foo.test' (x86_64).
(lldb) process launch --disable-aslr=false
Process 1193 launching
Process 1193 launched: '/go/src/github.com/cockroachdb/cockroach/foo/foo.test' (x86_64)
(lldb) ==1193== WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f2b2762c2a8  (/go/src/github.com/cockroachdb/cockroach/foo/foo.test+0x30a2a8)
    #1 0x7f2b2752e7ac  (/go/src/github.com/cockroachdb/cockroach/foo/foo.test+0x20c7ac)

Exiting
Process 1193 exited with status = 77 (0x0000004d)

error: No auto repeat.
(lldb) image lookup --address 0x7f2b2752e7ac
      Address: foo.test[0x000000000020c7ac] (foo.test..text + 709100)
      Summary: foo.test`runtime.asmcgocall + 172 at asm_amd64.s:612
(lldb) image lookup --address 0x7f2b2762c2a8
      Address: foo.test[0x000000000030a2a8] (foo.test..text + 1748200)
      Summary: foo.test`_cgo_sys_thread_start + 920 at gcc_linux_amd64.c:72
(lldb)

Some system details:

$ uname -a
Linux 43c41b292c47 4.0.9-boot2docker #1 SMP Thu Sep 10 20:39:20 UTC 2015 x86_64 GNU/Linux
$ go version
go version go1.6beta1 linux/amd64
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="/usr/bin/clang-3.6"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0"
CXX="/usr/bin/clang++-3.6"
CGO_ENABLED="1"

Note that I had to use:

cc @ianlancetaylor

@ianlancetaylor
Copy link
Contributor

On GNU/Linux you need to use at least clang 3.8.

This should be documented but I'm not sure where to do it.

@ianlancetaylor ianlancetaylor changed the title 1.6beta1: trivial invocation of go test -msan fails with use-of-uninitialized-value cmd/go: document that -msan requires clang 3.8 on GNU/Linux Jan 5, 2016
@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Jan 5, 2016
@ianlancetaylor ianlancetaylor self-assigned this Jan 5, 2016
@tamird
Copy link
Contributor Author

tamird commented Jan 5, 2016

I'm able to reproduce this with clang 3.8 as well.

It appears the magic that reproduces it is:

CGO_LDFLAGS='-fsanitize=memory' CGO_CPPFLAGS='-fsanitize=memory' go test -a -msan

I'm using CGO_{LDFLAGS,CPPFLAGS} to control compilation of my cgo stuff, but it appears that compiling something in the standard library with these environment variables causes this issue.

I'm using clang as provided by the Chromium team (https://github.com/google/sanitizers/wiki/AddressSanitizerHowToBuild#chrome). The exact version is:

$ clang --version
clang version 3.8.0 (trunk 255169)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /third_party/llvm-build/Release+Asserts/bin

@ianlancetaylor ianlancetaylor changed the title cmd/go: document that -msan requires clang 3.8 on GNU/Linux cmd/go: -msan failure when rebuilding runtime/cgo with -fsanitize=memory Jan 5, 2016
@ianlancetaylor
Copy link
Contributor

Thanks for the reproduction instructions. I will send a CL to fix this.

@gopherbot
Copy link

CL https://golang.org/cl/18263 mentions this issue.

gopherbot pushed a commit that referenced this issue Aug 29, 2016
The go tool used to avoid passing -fsanitize=memory when building
runtime/cgo. That was originally to avoid an msan error, but that error
was fixed anyhow for issue #13815. And building runtime/cgo with
-fsanitize=memory corrects the handling of the context traceback
function when the traceback function itself is built with
-fsanitize=memory.

Change-Id: I4bf5c3d21de6b2eb540600435ae47f5820d17464
Reviewed-on: https://go-review.googlesource.com/24855
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Jan 7, 2017
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

3 participants