Skip to content

Commit b813e6f

Browse files
committed
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. 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 <[email protected]> Reviewed-by: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 7240c6c commit b813e6f

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"internal/platform"
1212
"internal/testenv"
1313
"os"
14+
"os/exec"
1415
"strings"
1516
"testing"
1617
)
@@ -90,7 +91,16 @@ func TestShared(t *testing.T) {
9091
cmd.Args = append(cmd.Args, "-o", dstBin, cSrc, lib)
9192
mustRun(t, cmd)
9293

93-
cmd = hangProneCmd(dstBin)
94+
cmdArgs := []string{dstBin}
95+
if tc.sanitizer == "thread" && GOOS == "linux" {
96+
// Disable ASLR for TSAN. See #59418.
97+
arch, err := exec.Command("uname", "-m").Output()
98+
if err != nil {
99+
t.Fatalf("failed to run `uname -m`: %v", err)
100+
}
101+
cmdArgs = []string{"setarch", strings.TrimSpace(string(arch)), "-R", dstBin}
102+
}
103+
cmd = hangProneCmd(cmdArgs[0], cmdArgs[1:]...)
94104
replaceEnv(cmd, "LD_LIBRARY_PATH", ".")
95105
mustRun(t, cmd)
96106
})

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package sanitizers_test
88

99
import (
1010
"internal/testenv"
11+
"os/exec"
1112
"strings"
1213
"testing"
1314
)
@@ -68,7 +69,16 @@ func TestTSAN(t *testing.T) {
6869
outPath := dir.Join(name)
6970
mustRun(t, config.goCmd("build", "-o", outPath, srcPath(tc.src)))
7071

71-
cmd := hangProneCmd(outPath)
72+
cmdArgs := []string{outPath}
73+
if goos == "linux" {
74+
// Disable ASLR. See #59418.
75+
arch, err := exec.Command("uname", "-m").Output()
76+
if err != nil {
77+
t.Fatalf("failed to run `uname -m`: %v", err)
78+
}
79+
cmdArgs = []string{"setarch", strings.TrimSpace(string(arch)), "-R", outPath}
80+
}
81+
cmd := hangProneCmd(cmdArgs[0], cmdArgs[1:]...)
7282
if tc.needsRuntime {
7383
config.skipIfRuntimeIncompatible(t)
7484
}

0 commit comments

Comments
 (0)