From 378c2515aeec0e23662631dc6ba63148594ad92b Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 19 Nov 2014 15:25:33 -0500 Subject: runtime: remove assumption that noptrdata data bss noptrbss are ordered and contiguous The assumption can be violated by external linkers reordering them or inserting non-Go sections in between them. I looked briefly at trying to write out the _go_.o in external linking mode in a way that forced the ordering, but no matter what there's no way to force Go's data and Go's bss to be next to each other. If there is any data or bss from non-Go objects, it's very likely to get stuck in between them. Instead, rewrite the two places we know about that make the assumption. I grepped for noptrdata to look for more and didn't find any. The added race test (os/exec in external linking mode) fails without the changes in the runtime. It crashes with an invalid pointer dereference. Fixes #9133. LGTM=dneil R=dneil CC=dvyukov, golang-codereviews, iant https://golang.org/cl/179980043 --- src/run.bash | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/run.bash') diff --git a/src/run.bash b/src/run.bash index 3c9430c87e..9a0e1cb0f2 100755 --- a/src/run.bash +++ b/src/run.bash @@ -70,9 +70,10 @@ case "$GOHOSTOS-$GOOS-$GOARCH-$CGO_ENABLED" in linux-linux-amd64-1 | freebsd-freebsd-amd64-1 | darwin-darwin-amd64-1) echo echo '# Testing race detector.' - go test -race -i runtime/race flag + go test -race -i runtime/race flag os/exec go test -race -run=Output runtime/race - go test -race -short flag + go test -race -short flag os/exec + go test -race -short -ldflags=-linkmode=external flag os/exec esac xcd() { -- cgit v1.3-6-g1900 From 361199749d81d06cc1007db9f7da5818b6f830b2 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 19 Nov 2014 20:52:58 -0500 Subject: build: disable race external linking test on OS X 10.6 and earlier External linking doesn't work there at all. LGTM=bradfitz R=adg, bradfitz CC=golang-codereviews https://golang.org/cl/176070043 --- src/run.bash | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'src/run.bash') diff --git a/src/run.bash b/src/run.bash index 9a0e1cb0f2..5f20451a2d 100755 --- a/src/run.bash +++ b/src/run.bash @@ -64,18 +64,6 @@ echo echo '# sync -cpu=10' go test sync -short -timeout=$(expr 120 \* $timeout_scale)s -cpu=10 -# Race detector only supported on Linux, FreeBSD and OS X, -# and only on amd64, and only when cgo is enabled. -case "$GOHOSTOS-$GOOS-$GOARCH-$CGO_ENABLED" in -linux-linux-amd64-1 | freebsd-freebsd-amd64-1 | darwin-darwin-amd64-1) - echo - echo '# Testing race detector.' - go test -race -i runtime/race flag os/exec - go test -race -run=Output runtime/race - go test -race -short flag os/exec - go test -race -short -ldflags=-linkmode=external flag os/exec -esac - xcd() { echo echo '#' $1 @@ -121,6 +109,7 @@ go run $GOROOT/test/run.go - . || exit 1 [ "$CGO_ENABLED" != 1 ] || (xcd ../misc/cgo/test # cgo tests inspect the traceback for runtime functions +extlink=0 export GOTRACEBACK=2 go test -ldflags '-linkmode=auto' || exit 1 # linkmode=internal fails on dragonfly since errno is a TLS relocation. @@ -129,19 +118,24 @@ case "$GOHOSTOS-$GOARCH" in openbsd-386 | openbsd-amd64) # test linkmode=external, but __thread not supported, so skip testtls. go test -ldflags '-linkmode=external' || exit 1 + extlink=1 ;; darwin-386 | darwin-amd64) # linkmode=external fails on OS X 10.6 and earlier == Darwin # 10.8 and earlier. case $(uname -r) in [0-9].* | 10.*) ;; - *) go test -ldflags '-linkmode=external' || exit 1;; + *) + go test -ldflags '-linkmode=external' || exit 1 + extlink=1 + ;; esac ;; android-arm | dragonfly-386 | dragonfly-amd64 | freebsd-386 | freebsd-amd64 | freebsd-arm | linux-386 | linux-amd64 | linux-arm | netbsd-386 | netbsd-amd64) go test -ldflags '-linkmode=external' || exit 1 go test -ldflags '-linkmode=auto' ../testtls || exit 1 go test -ldflags '-linkmode=external' ../testtls || exit 1 + extlink=1 case "$GOHOSTOS-$GOARCH" in netbsd-386 | netbsd-amd64) ;; # no static linking @@ -165,6 +159,23 @@ android-arm | dragonfly-386 | dragonfly-amd64 | freebsd-386 | freebsd-amd64 | fr esac ) || exit $? +# Race detector only supported on Linux, FreeBSD and OS X, +# and only on amd64, and only when cgo is enabled. +# Delayed until here so we know whether to try external linking. +case "$GOHOSTOS-$GOOS-$GOARCH-$CGO_ENABLED" in +linux-linux-amd64-1 | freebsd-freebsd-amd64-1 | darwin-darwin-amd64-1) + echo + echo '# Testing race detector.' + go test -race -i runtime/race flag os/exec + go test -race -run=Output runtime/race + go test -race -short flag os/exec + + # Test with external linking; see issue 9133. + if [ "$extlink" = 1 ]; then + go test -race -short -ldflags=-linkmode=external flag os/exec + fi +esac + # This tests cgo -cdefs. That mode is not supported, # so it's okay if it doesn't work on some systems. # In particular, it works badly with clang on OS X. -- cgit v1.3-6-g1900