aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/cgo
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2016-05-19 16:27:23 -0700
committerIan Lance Taylor <iant@golang.org>2016-05-25 23:22:24 +0000
commita5d1a72a40b59db0d2f3f5d3fbb2ed60aafb7fdf (patch)
treeb6edf8790228d3dfe3381b2d1764b0c1e61b863d /src/runtime/cgo
parent10c8b2374f413ef6225555893cad5d2a530f77d5 (diff)
downloadgo-a5d1a72a40b59db0d2f3f5d3fbb2ed60aafb7fdf.tar.xz
cmd/cgo, runtime, runtime/cgo: TSAN support for malloc
Acquire and release the TSAN synchronization point when calling malloc, just as we do when calling any other C function. If we don't do this, TSAN will report false positive errors about races calling malloc and free. We used to have a special code path for malloc and free, going through the runtime functions cmalloc and cfree. The special code path for cfree was no longer used even before this CL. This CL stops using the special code path for malloc, because there is no place along that path where we could conditionally insert the TSAN synchronization. This CL removes the support for the special code path for both functions. Instead, cgo now automatically generates the malloc function as though it were referenced as C.malloc. We need to automatically generate it even if C.malloc is not called, even if malloc and size_t are not declared, to support cgo-provided functions like C.CString. Change-Id: I829854ec0787a80f33fa0a8a0dc2ee1d617830e2 Reviewed-on: https://go-review.googlesource.com/23260 Reviewed-by: Dmitry Vyukov <dvyukov@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/cgo')
-rw-r--r--src/runtime/cgo/callbacks.go12
-rw-r--r--src/runtime/cgo/gcc_util.c25
2 files changed, 0 insertions, 37 deletions
diff --git a/src/runtime/cgo/callbacks.go b/src/runtime/cgo/callbacks.go
index d0f63fb4ff..9bde5a933f 100644
--- a/src/runtime/cgo/callbacks.go
+++ b/src/runtime/cgo/callbacks.go
@@ -52,18 +52,6 @@ func _cgo_panic(a unsafe.Pointer, n int32) {
var x_cgo_init byte
var _cgo_init = &x_cgo_init
-//go:cgo_import_static x_cgo_malloc
-//go:linkname x_cgo_malloc x_cgo_malloc
-//go:linkname _cgo_malloc _cgo_malloc
-var x_cgo_malloc byte
-var _cgo_malloc = &x_cgo_malloc
-
-//go:cgo_import_static x_cgo_free
-//go:linkname x_cgo_free x_cgo_free
-//go:linkname _cgo_free _cgo_free
-var x_cgo_free byte
-var _cgo_free = &x_cgo_free
-
//go:cgo_import_static x_cgo_thread_start
//go:linkname x_cgo_thread_start x_cgo_thread_start
//go:linkname _cgo_thread_start _cgo_thread_start
diff --git a/src/runtime/cgo/gcc_util.c b/src/runtime/cgo/gcc_util.c
index e20d206be6..4111fe1195 100644
--- a/src/runtime/cgo/gcc_util.c
+++ b/src/runtime/cgo/gcc_util.c
@@ -4,31 +4,6 @@
#include "libcgo.h"
-/* Stub for calling malloc from Go */
-void
-x_cgo_malloc(void *p)
-{
- struct a {
- long long n;
- void *ret;
- } *a = p;
-
- a->ret = malloc(a->n);
- if(a->ret == NULL && a->n == 0)
- a->ret = malloc(1);
-}
-
-/* Stub for calling free from Go */
-void
-x_cgo_free(void *p)
-{
- struct a {
- void *arg;
- } *a = p;
-
- free(a->arg);
-}
-
/* Stub for creating a new thread */
void
x_cgo_thread_start(ThreadStart *arg)