summaryrefslogtreecommitdiff
path: root/lib/tsan
diff options
context:
space:
mode:
authorMartin Pelikan <martin.pelikan@gmail.com>2018-03-15 12:10:43 +0000
committerMartin Pelikan <martin.pelikan@gmail.com>2018-03-15 12:10:43 +0000
commitbc44f95c352f593a12e211f129f2952fa876ded6 (patch)
treeee6b53b611f30e526425a567bf7efcc5b1b6fb9f /lib/tsan
parent5e073b42727f893199a07e7bd0e76c662314e29f (diff)
[TSan] fix Go runtime test on amd64 with PIE
Summary: Without this diff, the test segfaults. Examining the generated executable (which gets auto-deleted likely by cmake/ninja) yields this error message: ThreadSanitizer failed to allocate 0x4000 (16384) bytes at address 1755558480000 (errno: 12) Note that the address has more than 47 bits, which on amd64 means special treatment and therefore points out an overflow. The allocation came from __tsan_map_shadow on a .data pointer, which (on my work Debian-based box) means the 0x550000000000 range. This doesn't correspond to the constants mentioned in tsan_platform.h for Go binaries on Linux/amd64. The diff therefore allocates memory in the sort of area Go programs would, and prevents the test from crashing. It would be nice if reviewers kindly considered other setups and architectures :-) Reviewers: kcc, dvyukov Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D44071 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@327621 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/tsan')
-rw-r--r--lib/tsan/go/test.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/tsan/go/test.c b/lib/tsan/go/test.c
index b3e31b1fe..c484774ca 100644
--- a/lib/tsan/go/test.c
+++ b/lib/tsan/go/test.c
@@ -11,6 +11,8 @@
//
//===----------------------------------------------------------------------===//
+#include <sys/mman.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -44,7 +46,13 @@ void symbolize_cb(long cmd, void *ctx) {
}
}
-char buf0[100<<10];
+/*
+ * See lib/tsan/rtl/tsan_platform.h for details of what the memory layout
+ * of Go programs looks like. To prevent running over existing mappings,
+ * we pick an address slightly inside the Go heap region.
+ */
+void *go_heap = (void *)0xC011110000;
+char *buf0;
void foobar() {}
void barfoo() {}
@@ -54,6 +62,15 @@ int main(void) {
void *proc0 = 0;
__tsan_init(&thr0, &proc0, symbolize_cb);
current_proc = proc0;
+
+ // Allocate something resembling a heap in Go.
+ buf0 = mmap(go_heap, 16384, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_FIXED | MAP_ANON, -1, 0);
+ if (buf0 == MAP_FAILED) {
+ fprintf(stderr, "failed to allocate Go-like heap at %p; errno %d\n",
+ go_heap, errno);
+ return 1;
+ }
char *buf = (char*)((unsigned long)buf0 + (64<<10) - 1 & ~((64<<10) - 1));
__tsan_map_shadow(buf, 4096);
__tsan_malloc(thr0, (char*)&barfoo + 1, buf, 10);