Repository: go
Issue: gccgo: TestShared/tsan_shared fails with GCC 5.5.0
Labels: NeedsInvestigation

Please answer these questions before submitting your issue. Thanks!


### What version of Go are you using (`go version`)?
Go 1.10

### Does this issue reproduce with the latest release?
Yes

### What operating system and processor architecture are you using (`go env`)?
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/leo/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/leo/go"
GORACE=""
GOROOT="/gnu/store/h4gwja8863p3jhkav8ja7s710acckzy1-go-1.10"
GOTMPDIR=""
GOTOOLDIR="/gnu/store/h4gwja8863p3jhkav8ja7s710acckzy1-go-1.10/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="/gnu/store/cfdn69spjc44x4sd0acrwhxq6yay3rbc-gcc-5.5.0/bin/gcc"
CXX="g++"
CGO_ENABLED="1"
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-build244943669=/tmp/go-build -gno-record-gcc-switches"


### What did you do?
I am testing the update of Go from 1.9.4 to 1.10 in GNU Guix. We bootstrap from Go 1.4.3 using GCC 5.5.0. I invoke the build with `sh all.bash`.

### What did you expect to see?
A successful compilation and test of Go 1.10, as with Go 1.9.4.

### What did you see instead?
There is a test failure. If I understand correctly, GCC 5.5.0's ThreadSanitizer finds a race. When I rebuild Go 1.4.3 with GCC 6.4.0, and build Go 1.10 using that bootstrap Go and version of GCC, the race is not detected. The test fails consistently with GCC 5.5.0.
```
##### ../misc/cgo/testsanitizers
--- FAIL: TestShared (0.03s)
    --- FAIL: TestShared/tsan_shared (2.54s)
    	cshared_test.go:71: `/tmp/guix-build-go-1.10.drv-0/TestShared367937240/tsan_shared` exited with exit status 66
    		==================
    		WARNING: ThreadSanitizer: data race (pid=28778)
    		  Write of size 8 at 0x7ffff5495c30 by thread T1:
    		    #0 pthread_attr_getstacksize <null> (tsan_shared+0x00000041be82)
    		    #1 x_cgo_init <null> (libtsan_shared.so+0x00000008aeaf)
    		    #2 runtime.rt0_go /tmp/guix-build-go-1.10.drv-0/go/src/runtime/asm_amd64.s:199 (libtsan_shared.so+0x000000081586)
    		
    		  Previous write of size 8 at 0x7ffff5495c30 by main thread:
    		    #0 <null> <null> (0x000000000001)
    		
    		  Location is stack of thread T1.
    		
    		  Thread T1 (tid=28786, running) created by main thread at:
    		    #0 pthread_create <null> (tsan_shared+0x00000040c794)
    		    #1 _cgo_try_pthread_create <null> (libtsan_shared.so+0x00000008ad70)
    		    #2 x_cgo_sys_thread_create <null> (libtsan_shared.so+0x00000008ab12)
    		    #3 _rt0_amd64_lib /tmp/guix-build-go-1.10.drv-0/go/src/runtime/asm_amd64.s:56 (libtsan_shared.so+0x0000000813b6)
    		
    		SUMMARY: ThreadSanitizer: data race ??:0 __interceptor_pthread_attr_getstacksize
    		==================
    		==================
    		WARNING: ThreadSanitizer: data race (pid=28778)
    		  Read of size 8 at 0x7d080000dfe0 by thread T2:
    		    #0 threadentry <null> (libtsan_shared.so+0x00000008b0d2)
    		
    		  Previous write of size 8 at 0x7d080000dfe0 by thread T1:
    		    #0 malloc <null> (tsan_shared+0x00000040aba3)
    		    #1 x_cgo_thread_start <null> (libtsan_shared.so+0x00000008b730)
    		    #2 runtime.asmcgocall /tmp/guix-build-go-1.10.drv-0/go/src/runtime/asm_amd64.s:718 (libtsan_shared.so+0x000000082fc6)
    		
    		  Location is heap block of size 24 at 0x7d080000dfe0 allocated by thread T1:
    		    #0 malloc <null> (tsan_shared+0x00000040aba3)
    		    #1 x_cgo_thread_start <null> (libtsan_shared.so+0x00000008b730)
    		    #2 runtime.asmcgocall /tmp/guix-build-go-1.10.drv-0/go/src/runtime/asm_amd64.s:718 (libtsan_shared.so+0x000000082fc6)
    		
    		  Thread T2 (tid=28791, running) created by thread T1 at:
    		    #0 pthread_create <null> (tsan_shared+0x00000040c794)
    		    #1 _cgo_try_pthread_create <null> (libtsan_shared.so+0x00000008ad70)
    		    #2 _cgo_sys_thread_start <null> (libtsan_shared.so+0x00000008b011)
    		    #3 x_cgo_thread_start <null> (libtsan_shared.so+0x00000008b7be)
    		    #4 runtime.asmcgocall /tmp/guix-build-go-1.10.drv-0/go/src/runtime/asm_amd64.s:718 (libtsan_shared.so+0x000000082fc6)
    		
    		  Thread T1 (tid=28786, running) created by main thread at:
    		    #0 pthread_create <null> (tsan_shared+0x00000040c794)
    		    #1 _cgo_try_pthread_create <null> (libtsan_shared.so+0x00000008ad70)
    		    #2 x_cgo_sys_thread_create <null> (libtsan_shared.so+0x00000008ab12)
    		    #3 _rt0_amd64_lib /tmp/guix-build-go-1.10.drv-0/go/src/runtime/asm_amd64.s:56 (libtsan_shared.so+0x0000000813b6)
    		
    		SUMMARY: ThreadSanitizer: data race ??:0 threadentry
    		==================
    		==================
    		WARNING: ThreadSanitizer: data race (pid=28778)
    		  Read of size 8 at 0x7ffff7dd54f8 by thread T2:
    		    #0 threadentry <null> (libtsan_shared.so+0x00000008b105)
    		
    		  Previous write of size 8 at 0x7ffff7dd54f8 by thread T1:
    		    #0 x_cgo_init <null> (libtsan_shared.so+0x00000008ae43)
    		    #1 runtime.rt0_go /tmp/guix-build-go-1.10.drv-0/go/src/runtime/asm_amd64.s:199 (libtsan_shared.so+0x000000081586)
    		
    		  Location is global 'setg_gcc' of size 8 at 0x7ffff7dd54f8 (libtsan_shared.so+0x0000003134f8)
    		
    		  Thread T2 (tid=28791, running) created by thread T1 at:
    		    #0 pthread_create <null> (tsan_shared+0x00000040c794)
    		    #1 _cgo_try_pthread_create <null> (libtsan_shared.so+0x00000008ad70)
    		    #2 _cgo_sys_thread_start <null> (libtsan_shared.so+0x00000008b011)
    		    #3 x_cgo_thread_start <null> (libtsan_shared.so+0x00000008b7be)
    		    #4 runtime.asmcgocall /tmp/guix-build-go-1.10.drv-0/go/src/runtime/asm_amd64.s:718 (libtsan_shared.so+0x000000082fc6)
    		
    		  Thread T1 (tid=28786, running) created by main thread at:
    		    #0 pthread_create <null> (tsan_shared+0x00000040c794)
    		    #1 _cgo_try_pthread_create <null> (libtsan_shared.so+0x00000008ad70)
    		    #2 x_cgo_sys_thread_create <null> (libtsan_shared.so+0x00000008ab12)
    		    #3 _rt0_amd64_lib /tmp/guix-build-go-1.10.drv-0/go/src/runtime/asm_amd64.s:56 (libtsan_shared.so+0x0000000813b6)
    		
    		SUMMARY: ThreadSanitizer: data race ??:0 threadentry
    		==================
    		==================
    		WARNING: ThreadSanitizer: data race (pid=28778)
    		  Read of size 8 at 0x7d080000df80 by thread T6:
    		    #0 threadentry <null> (libtsan_shared.so+0x00000008b0d2)
    		
    		  Previous write of size 8 at 0x7d080000df80 by thread T1:
    		    #0 malloc <null> (tsan_shared+0x00000040aba3)
    		    #1 x_cgo_thread_start <null> (libtsan_shared.so+0x00000008b730)
    		    #2 runtime.asmcgocall /tmp/guix-build-go-1.10.drv-0/go/src/runtime/asm_amd64.s:688 (libtsan_shared.so+0x000000082f87)
    		
    		  Location is heap block of size 24 at 0x7d080000df80 allocated by thread T1:
    		    #0 malloc <null> (tsan_shared+0x00000040aba3)
    		    #1 x_cgo_thread_start <null> (libtsan_shared.so+0x00000008b730)
    		    #2 runtime.asmcgocall /tmp/guix-build-go-1.10.drv-0/go/src/runtime/asm_amd64.s:688 (libtsan_shared.so+0x000000082f87)
    		
    		  Thread T6 (tid=28796, running) created by thread T1 at:
    		    #0 pthread_create <null> (tsan_shared+0x00000040c794)
    		    #1 _cgo_try_pthread_create <null> (libtsan_shared.so+0x00000008ad70)
    		    #2 _cgo_sys_thread_start <null> (libtsan_shared.so+0x00000008b011)
    		    #3 x_cgo_thread_start <null> (libtsan_shared.so+0x00000008b7be)
    		    #4 runtime.asmcgocall /tmp/guix-build-go-1.10.drv-0/go/src/runtime/asm_amd64.s:688 (libtsan_shared.so+0x000000082f87)
    		
    		  Thread T1 (tid=28786, running) created by main thread at:
    		    #0 pthread_create <null> (tsan_shared+0x00000040c794)
    		    #1 _cgo_try_pthread_create <null> (libtsan_shared.so+0x00000008ad70)
    		    #2 x_cgo_sys_thread_create <null> (libtsan_shared.so+0x00000008ab12)
    		    #3 _rt0_amd64_lib /tmp/guix-build-go-1.10.drv-0/go/src/runtime/asm_amd64.s:56 (libtsan_shared.so+0x0000000813b6)
    		
    		SUMMARY: ThreadSanitizer: data race ??:0 threadentry
    		==================
    		ThreadSanitizer: reported 4 warnings
FAIL
2018/02/22 05:28:09 Failed: exit status 1
```