[PATCH] D44071: [TSan] fix Go runtime test on amd64 with PIE

Martin Pelikán via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 15 05:13:27 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL327621: [TSan] fix Go runtime test on amd64 with PIE (authored by pelikan, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D44071

Files:
  compiler-rt/trunk/lib/tsan/go/test.c


Index: compiler-rt/trunk/lib/tsan/go/test.c
===================================================================
--- compiler-rt/trunk/lib/tsan/go/test.c
+++ compiler-rt/trunk/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 @@
   }
 }
 
-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 @@
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44071.138532.patch
Type: text/x-patch
Size: 1336 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180315/e65d24b8/attachment.bin>


More information about the llvm-commits mailing list