diff options
| author | Fangming.Fang <fangming.fang@arm.com> | 2018-04-08 07:32:43 +0000 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2018-05-02 17:52:14 +0000 |
| commit | e8d417d272290027e10e348f81cbc6bb5fe0ec13 (patch) | |
| tree | 394e28ae3d04021ddffc8c6c22d16abd71c1479f /src/runtime/cgo | |
| parent | eff1e68528fc9052a7ff1ac7afe222696f85db8c (diff) | |
| download | go-e8d417d272290027e10e348f81cbc6bb5fe0ec13.tar.xz | |
runtime: enable memory sanitizer on arm64
Changes include:
1. open compilation option -msan for arm64
2. modify doc to explain -msan is also supported on linux/arm64
3. wrap msan lib API in msan_arm64.s
4. use libc for sigaction syscalls when cgo is enabled
5. use libc for mmap syscalls when cgo is enabled
Change-Id: I26ebe61ff7ce1906125f54a0182a720f9d58ec11
Reviewed-on: https://go-review.googlesource.com/109255
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/cgo')
| -rw-r--r-- | src/runtime/cgo/gcc_linux_arm64.c | 32 | ||||
| -rw-r--r-- | src/runtime/cgo/gcc_mmap.c | 2 | ||||
| -rw-r--r-- | src/runtime/cgo/gcc_sigaction.c | 2 | ||||
| -rw-r--r-- | src/runtime/cgo/mmap.go | 2 | ||||
| -rw-r--r-- | src/runtime/cgo/sigaction.go | 2 |
5 files changed, 31 insertions, 9 deletions
diff --git a/src/runtime/cgo/gcc_linux_arm64.c b/src/runtime/cgo/gcc_linux_arm64.c index b328407f39..8630f2f03e 100644 --- a/src/runtime/cgo/gcc_linux_arm64.c +++ b/src/runtime/cgo/gcc_linux_arm64.c @@ -3,8 +3,10 @@ // license that can be found in the LICENSE file. #include <pthread.h> +#include <errno.h> #include <string.h> #include <signal.h> +#include <stdlib.h> #include "libcgo.h" #include "libcgo_unix.h" @@ -59,14 +61,34 @@ threadentry(void *v) void x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase) { - pthread_attr_t attr; + pthread_attr_t *attr; size_t size; + /* The memory sanitizer distributed with versions of clang + before 3.8 has a bug: if you call mmap before malloc, mmap + may return an address that is later overwritten by the msan + library. Avoid this problem by forcing a call to malloc + here, before we ever call malloc. + + This is only required for the memory sanitizer, so it's + unfortunate that we always run it. It should be possible + to remove this when we no longer care about versions of + clang before 3.8. The test for this is + misc/cgo/testsanitizers. + + GCC works hard to eliminate a seemingly unnecessary call to + malloc, so we actually use the memory we allocate. */ + setg_gcc = setg; - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - g->stacklo = (uintptr)&attr - size + 4096; - pthread_attr_destroy(&attr); + attr = (pthread_attr_t*)malloc(sizeof *attr); + if (attr == NULL) { + fatalf("malloc failed: %s", strerror(errno)); + } + pthread_attr_init(attr); + pthread_attr_getstacksize(attr, &size); + g->stacklo = (uintptr)&size - size + 4096; + pthread_attr_destroy(attr); + free(attr); if (x_cgo_inittls) { x_cgo_inittls(tlsg, tlsbase); diff --git a/src/runtime/cgo/gcc_mmap.c b/src/runtime/cgo/gcc_mmap.c index 5cf6bdf8cf..e6a621d5a3 100644 --- a/src/runtime/cgo/gcc_mmap.c +++ b/src/runtime/cgo/gcc_mmap.c @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build linux,amd64 +// +build linux,amd64 linux,arm64 #include <errno.h> #include <stdint.h> diff --git a/src/runtime/cgo/gcc_sigaction.c b/src/runtime/cgo/gcc_sigaction.c index 72fb08d720..05dee2affe 100644 --- a/src/runtime/cgo/gcc_sigaction.c +++ b/src/runtime/cgo/gcc_sigaction.c @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build linux,amd64 +// +build linux,amd64 linux,arm64 #include <errno.h> #include <stddef.h> diff --git a/src/runtime/cgo/mmap.go b/src/runtime/cgo/mmap.go index ad5f6df70a..00fb7fced6 100644 --- a/src/runtime/cgo/mmap.go +++ b/src/runtime/cgo/mmap.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build linux,amd64 +// +build linux,amd64 linux,arm64 package cgo diff --git a/src/runtime/cgo/sigaction.go b/src/runtime/cgo/sigaction.go index e25f4ff2f3..076fbc1a0a 100644 --- a/src/runtime/cgo/sigaction.go +++ b/src/runtime/cgo/sigaction.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build linux,amd64 freebsd,amd64 +// +build linux,amd64 freebsd,amd64 linux,arm64 package cgo |
