]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo/internal/testsanitizers: disable ASLR for TSAN tests
authorMichael Anthony Knyszek <mknyszek@google.com>
Thu, 31 Oct 2024 20:41:51 +0000 (20:41 +0000)
committerMichael Knyszek <mknyszek@google.com>
Fri, 1 Nov 2024 15:35:54 +0000 (15:35 +0000)
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.

Fixes #59418.

Change-Id: Icb4536ddf0f2f5e7850734564d40f5a208ab8d01
Cq-Include-Trybots: luci.golang.try:gotip-linux-386,gotip-linux-386-clang15,gotip-linux-amd64-clang15,gotip-linux-amd64-boringcrypto,gotip-linux-amd64-aliastypeparams,gotip-linux-amd64-asan-clang15,gotip-linux-amd64-msan-clang15,gotip-linux-amd64-goamd64v3
Reviewed-on: https://go-review.googlesource.com/c/go/+/623956
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/cgo/internal/testsanitizers/cshared_test.go
src/cmd/cgo/internal/testsanitizers/tsan_test.go

index f26c50a6219a5128183f014f04465da9acc459cf..15409d0fca04fddc315eb3f1f6e208a68c19df4c 100644 (file)
@@ -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)
                })
index 49b9b3877a6c9d26311778f0b57c360d2c516593..9a1924968c9434df8cf105e4f37e96ae641ef71c 100644 (file)
@@ -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)
                        }