From: Michael Anthony Knyszek Date: Thu, 31 Oct 2024 20:41:51 +0000 (+0000) Subject: [release-branch.go1.23] cmd/cgo/internal/testsanitizers: disable ASLR for TSAN tests X-Git-Tag: go1.23.12~5 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=cea5be7739cb572204e4f41dd19f8bbbfc634034;p=gostls13.git [release-branch.go1.23] cmd/cgo/internal/testsanitizers: disable ASLR for TSAN tests Ever since we had to upgrade from our COS image, we've been experiencing TSAN test failures. My best guess is that the ASLR randomization entropy increased, causing TSAN to fail. TSAN already re-execs itself in Clang 18+ with ASLR disabled, so just execute the tests with ASLR disabled on Linux. For #59418. Fixes #74726. Change-Id: Icb4536ddf0f2f5e7850734564d40f5a208ab8d01 Cq-Include-Trybots: luci.golang.try:go1.23-linux-386,go1.23-linux-386-clang15,go1.23-linux-amd64-clang15,go1.23-linux-amd64-boringcrypto,go1.23-linux-amd64-goamd64v3 Reviewed-on: https://go-review.googlesource.com/c/go/+/623956 Reviewed-by: Ian Lance Taylor Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI (cherry picked from commit b813e6fd73e0925ca57f5b3ff6b0d991bb2e5aea) Reviewed-on: https://go-review.googlesource.com/c/go/+/690035 Reviewed-by: Michael Knyszek Reviewed-by: Dmitri Shuralyov --- diff --git a/src/cmd/cgo/internal/testsanitizers/cshared_test.go b/src/cmd/cgo/internal/testsanitizers/cshared_test.go index f26c50a621..15409d0fca 100644 --- a/src/cmd/cgo/internal/testsanitizers/cshared_test.go +++ b/src/cmd/cgo/internal/testsanitizers/cshared_test.go @@ -11,6 +11,7 @@ import ( "internal/platform" "internal/testenv" "os" + "os/exec" "strings" "testing" ) @@ -90,7 +91,16 @@ func TestShared(t *testing.T) { cmd.Args = append(cmd.Args, "-o", dstBin, cSrc, lib) mustRun(t, cmd) - cmd = hangProneCmd(dstBin) + cmdArgs := []string{dstBin} + if tc.sanitizer == "thread" && GOOS == "linux" { + // Disable ASLR for TSAN. See #59418. + arch, err := exec.Command("uname", "-m").Output() + if err != nil { + t.Fatalf("failed to run `uname -m`: %v", err) + } + cmdArgs = []string{"setarch", strings.TrimSpace(string(arch)), "-R", dstBin} + } + cmd = hangProneCmd(cmdArgs[0], cmdArgs[1:]...) replaceEnv(cmd, "LD_LIBRARY_PATH", ".") mustRun(t, cmd) }) diff --git a/src/cmd/cgo/internal/testsanitizers/tsan_test.go b/src/cmd/cgo/internal/testsanitizers/tsan_test.go index 94c00ef7f4..74acde57f2 100644 --- a/src/cmd/cgo/internal/testsanitizers/tsan_test.go +++ b/src/cmd/cgo/internal/testsanitizers/tsan_test.go @@ -8,6 +8,7 @@ package sanitizers_test import ( "internal/testenv" + "os/exec" "strings" "testing" ) @@ -68,7 +69,16 @@ func TestTSAN(t *testing.T) { outPath := dir.Join(name) mustRun(t, config.goCmd("build", "-o", outPath, srcPath(tc.src))) - cmd := hangProneCmd(outPath) + cmdArgs := []string{outPath} + if goos == "linux" { + // Disable ASLR. See #59418. + arch, err := exec.Command("uname", "-m").Output() + if err != nil { + t.Fatalf("failed to run `uname -m`: %v", err) + } + cmdArgs = []string{"setarch", strings.TrimSpace(string(arch)), "-R", outPath} + } + cmd := hangProneCmd(cmdArgs[0], cmdArgs[1:]...) if tc.needsRuntime { config.skipIfRuntimeIncompatible(t) }