aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/cgo
diff options
context:
space:
mode:
authorChressie Himpel <chressie@google.com>2023-05-05 14:17:38 +0000
committerChressie Himpel <chressie@google.com>2023-05-05 14:37:29 +0000
commit72c33a5ef0eea8663328375d9d339ed150310ebb (patch)
treea4272daf751239fcb9b2f1b8e1730800629f738c /src/runtime/cgo
parentf379e78951a405e7e99a60fb231eeedbf976c108 (diff)
downloadgo-72c33a5ef0eea8663328375d9d339ed150310ebb.tar.xz
Revert "runtime/cgo: store M for C-created thread in pthread key"
This reverts CL 485500. Reason for revert: This breaks internal tests at Google, see b/280861579 and b/280820455. Change-Id: I426278d400f7611170918fc07c524cb059b9cc55 Reviewed-on: https://go-review.googlesource.com/c/go/+/492995 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Chressie Himpel <chressie@google.com>
Diffstat (limited to 'src/runtime/cgo')
-rw-r--r--src/runtime/cgo/asm_386.s8
-rw-r--r--src/runtime/cgo/asm_amd64.s8
-rw-r--r--src/runtime/cgo/asm_arm.s8
-rw-r--r--src/runtime/cgo/asm_arm64.s8
-rw-r--r--src/runtime/cgo/asm_loong64.s8
-rw-r--r--src/runtime/cgo/asm_mips64x.s8
-rw-r--r--src/runtime/cgo/asm_mipsx.s8
-rw-r--r--src/runtime/cgo/asm_ppc64x.s23
-rw-r--r--src/runtime/cgo/asm_riscv64.s8
-rw-r--r--src/runtime/cgo/asm_s390x.s8
-rw-r--r--src/runtime/cgo/asm_wasm.s3
-rw-r--r--src/runtime/cgo/callbacks.go45
-rw-r--r--src/runtime/cgo/gcc_libinit.c35
-rw-r--r--src/runtime/cgo/gcc_libinit_windows.c9
-rw-r--r--src/runtime/cgo/gcc_stack_darwin.c19
-rw-r--r--src/runtime/cgo/gcc_stack_unix.c39
-rw-r--r--src/runtime/cgo/gcc_stack_windows.c7
-rw-r--r--src/runtime/cgo/libcgo.h5
18 files changed, 0 insertions, 257 deletions
diff --git a/src/runtime/cgo/asm_386.s b/src/runtime/cgo/asm_386.s
index 086e20b02f..2e7e9512e2 100644
--- a/src/runtime/cgo/asm_386.s
+++ b/src/runtime/cgo/asm_386.s
@@ -4,14 +4,6 @@
#include "textflag.h"
-// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
-// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
-TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
- MOVL _crosscall2_ptr(SB), AX
- MOVL $crosscall2(SB), BX
- MOVL BX, (AX)
- RET
-
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
diff --git a/src/runtime/cgo/asm_amd64.s b/src/runtime/cgo/asm_amd64.s
index f254622f23..e223a6c870 100644
--- a/src/runtime/cgo/asm_amd64.s
+++ b/src/runtime/cgo/asm_amd64.s
@@ -5,14 +5,6 @@
#include "textflag.h"
#include "abi_amd64.h"
-// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
-// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
-TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
- MOVQ _crosscall2_ptr(SB), AX
- MOVQ $crosscall2(SB), BX
- MOVQ BX, (AX)
- RET
-
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
diff --git a/src/runtime/cgo/asm_arm.s b/src/runtime/cgo/asm_arm.s
index f7f99772a6..ea55e173c1 100644
--- a/src/runtime/cgo/asm_arm.s
+++ b/src/runtime/cgo/asm_arm.s
@@ -4,14 +4,6 @@
#include "textflag.h"
-// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
-// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
-TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
- MOVW _crosscall2_ptr(SB), R1
- MOVW $crosscall2(SB), R2
- MOVW R2, (R1)
- RET
-
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
diff --git a/src/runtime/cgo/asm_arm64.s b/src/runtime/cgo/asm_arm64.s
index ce8909b492..e808dedcfc 100644
--- a/src/runtime/cgo/asm_arm64.s
+++ b/src/runtime/cgo/asm_arm64.s
@@ -5,14 +5,6 @@
#include "textflag.h"
#include "abi_arm64.h"
-// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
-// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
-TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
- MOVD _crosscall2_ptr(SB), R1
- MOVD $crosscall2(SB), R2
- MOVD R2, (R1)
- RET
-
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
diff --git a/src/runtime/cgo/asm_loong64.s b/src/runtime/cgo/asm_loong64.s
index 3b514ffc4a..aea4f8e6b9 100644
--- a/src/runtime/cgo/asm_loong64.s
+++ b/src/runtime/cgo/asm_loong64.s
@@ -5,14 +5,6 @@
#include "textflag.h"
#include "abi_loong64.h"
-// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
-// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
-TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
- MOVV _crosscall2_ptr(SB), R5
- MOVV $crosscall2(SB), R6
- MOVV R6, (R5)
- RET
-
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
diff --git a/src/runtime/cgo/asm_mips64x.s b/src/runtime/cgo/asm_mips64x.s
index 0a8fbbbef0..904f781d87 100644
--- a/src/runtime/cgo/asm_mips64x.s
+++ b/src/runtime/cgo/asm_mips64x.s
@@ -6,14 +6,6 @@
#include "textflag.h"
-// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
-// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
-TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
- MOVV _crosscall2_ptr(SB), R5
- MOVV $crosscall2(SB), R6
- MOVV R6, (R5)
- RET
-
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
diff --git a/src/runtime/cgo/asm_mipsx.s b/src/runtime/cgo/asm_mipsx.s
index a57ae97d7e..5e2db0b56e 100644
--- a/src/runtime/cgo/asm_mipsx.s
+++ b/src/runtime/cgo/asm_mipsx.s
@@ -6,14 +6,6 @@
#include "textflag.h"
-// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
-// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
-TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
- MOVW _crosscall2_ptr(SB), R5
- MOVW $crosscall2(SB), R6
- MOVW R6, (R5)
- RET
-
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
diff --git a/src/runtime/cgo/asm_ppc64x.s b/src/runtime/cgo/asm_ppc64x.s
index c258c7c2a0..cba053deb7 100644
--- a/src/runtime/cgo/asm_ppc64x.s
+++ b/src/runtime/cgo/asm_ppc64x.s
@@ -8,25 +8,6 @@
#include "asm_ppc64x.h"
#include "abi_ppc64x.h"
-#ifdef GO_PPC64X_HAS_FUNCDESC
-// crosscall2 is marked with go:cgo_export_static. On AIX, this creates and exports
-// the symbol name and descriptor as the AIX linker expects, but does not work if
-// referenced from within Go. Create and use an aliased descriptor of crosscall2
-// to workaround this.
-DEFINE_PPC64X_FUNCDESC(_crosscall2<>, crosscall2)
-#define CROSSCALL2_FPTR $_crosscall2<>(SB)
-#else
-#define CROSSCALL2_FPTR $crosscall2(SB)
-#endif
-
-// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
-// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
-TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
- MOVD _crosscall2_ptr(SB), R5
- MOVD CROSSCALL2_FPTR, R6
- MOVD R6, (R5)
- RET
-
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
@@ -46,12 +27,8 @@ TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
#ifdef GO_PPC64X_HAS_FUNCDESC
// Load the real entry address from the first slot of the function descriptor.
- // The first argument fn might be null, that means dropm in pthread key destructor.
- CMP R3, $0
- BEQ nil_fn
MOVD 8(R3), R2
MOVD (R3), R3
-nil_fn:
#endif
MOVD R3, FIXED_FRAME+0(R1) // fn unsafe.Pointer
MOVD R4, FIXED_FRAME+8(R1) // a unsafe.Pointer
diff --git a/src/runtime/cgo/asm_riscv64.s b/src/runtime/cgo/asm_riscv64.s
index 08c4ed8466..45151bf02b 100644
--- a/src/runtime/cgo/asm_riscv64.s
+++ b/src/runtime/cgo/asm_riscv64.s
@@ -4,14 +4,6 @@
#include "textflag.h"
-// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
-// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
-TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
- MOV _crosscall2_ptr(SB), X7
- MOV $crosscall2(SB), X8
- MOV X8, (X7)
- RET
-
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
diff --git a/src/runtime/cgo/asm_s390x.s b/src/runtime/cgo/asm_s390x.s
index bb0dfc1e31..8bf16e75e2 100644
--- a/src/runtime/cgo/asm_s390x.s
+++ b/src/runtime/cgo/asm_s390x.s
@@ -4,14 +4,6 @@
#include "textflag.h"
-// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
-// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
-TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
- MOVD _crosscall2_ptr(SB), R1
- MOVD $crosscall2(SB), R2
- MOVD R2, (R1)
- RET
-
// Called by C code generated by cmd/cgo.
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
// Saves C callee-saved registers and calls cgocallback with three arguments.
diff --git a/src/runtime/cgo/asm_wasm.s b/src/runtime/cgo/asm_wasm.s
index e7f01bdc56..cb140eb7b8 100644
--- a/src/runtime/cgo/asm_wasm.s
+++ b/src/runtime/cgo/asm_wasm.s
@@ -4,8 +4,5 @@
#include "textflag.h"
-TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
- UNDEF
-
TEXT crosscall2(SB), NOSPLIT, $0
UNDEF
diff --git a/src/runtime/cgo/callbacks.go b/src/runtime/cgo/callbacks.go
index 3c246a88b6..e7c8ef3e07 100644
--- a/src/runtime/cgo/callbacks.go
+++ b/src/runtime/cgo/callbacks.go
@@ -71,42 +71,6 @@ var _cgo_thread_start = &x_cgo_thread_start
var x_cgo_sys_thread_create byte
var _cgo_sys_thread_create = &x_cgo_sys_thread_create
-// Indicates whether a dummy thread key has been created or not.
-//
-// When calling go exported function from C, we register a destructor
-// callback, for a dummy thread key, by using pthread_key_create.
-
-//go:cgo_import_static x_cgo_pthread_key_created
-//go:linkname x_cgo_pthread_key_created x_cgo_pthread_key_created
-//go:linkname _cgo_pthread_key_created _cgo_pthread_key_created
-var x_cgo_pthread_key_created byte
-var _cgo_pthread_key_created = &x_cgo_pthread_key_created
-
-// Export crosscall2 to a c function pointer variable.
-// Used to dropm in pthread key destructor, while C thread is exiting.
-
-//go:cgo_import_static x_crosscall2_ptr
-//go:linkname x_crosscall2_ptr x_crosscall2_ptr
-//go:linkname _crosscall2_ptr _crosscall2_ptr
-var x_crosscall2_ptr byte
-var _crosscall2_ptr = &x_crosscall2_ptr
-
-// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
-// It's for the runtime package to call at init time.
-func set_crosscall2()
-
-//go:linkname _set_crosscall2 runtime.set_crosscall2
-var _set_crosscall2 = set_crosscall2
-
-// Store the g into the thread-specific value.
-// So that pthread_key_destructor will dropm when the thread is exiting.
-
-//go:cgo_import_static x_cgo_bindm
-//go:linkname x_cgo_bindm x_cgo_bindm
-//go:linkname _cgo_bindm _cgo_bindm
-var x_cgo_bindm byte
-var _cgo_bindm = &x_cgo_bindm
-
// Notifies that the runtime has been initialized.
//
// We currently block at every CGO entry point (via _cgo_wait_runtime_init_done)
@@ -141,12 +105,3 @@ var _cgo_yield unsafe.Pointer
//go:cgo_export_static _cgo_topofstack
//go:cgo_export_dynamic _cgo_topofstack
-
-// x_cgo_getstackbound gets the thread's C stack size and
-// set the G's stack bound based on the stack size.
-
-//go:cgo_import_static x_cgo_getstackbound
-//go:linkname x_cgo_getstackbound x_cgo_getstackbound
-//go:linkname _cgo_getstackbound _cgo_getstackbound
-var x_cgo_getstackbound byte
-var _cgo_getstackbound = &x_cgo_getstackbound
diff --git a/src/runtime/cgo/gcc_libinit.c b/src/runtime/cgo/gcc_libinit.c
index 9676593211..57620fe4de 100644
--- a/src/runtime/cgo/gcc_libinit.c
+++ b/src/runtime/cgo/gcc_libinit.c
@@ -17,14 +17,6 @@ static pthread_cond_t runtime_init_cond = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t runtime_init_mu = PTHREAD_MUTEX_INITIALIZER;
static int runtime_init_done;
-// pthread_g is a pthread specific key, for storing the g that binded to the C thread.
-// The registered pthread_key_destructor will dropm, when the pthread-specified value g is not NULL,
-// while a C thread is exiting.
-static pthread_key_t pthread_g;
-static void pthread_key_destructor(void* g);
-uintptr_t x_cgo_pthread_key_created;
-void (*x_crosscall2_ptr)(void (*fn)(void *), void *, int, size_t);
-
// The context function, used when tracing back C calls into Go.
static void (*cgo_context_function)(struct context_arg*);
@@ -47,12 +39,6 @@ _cgo_wait_runtime_init_done(void) {
pthread_cond_wait(&runtime_init_cond, &runtime_init_mu);
}
- // The key and x_cgo_pthread_key_created are for the whole program,
- // whereas the specific and destructor is per thread.
- if (x_cgo_pthread_key_created == 0 && pthread_key_create(&pthread_g, pthread_key_destructor) == 0) {
- x_cgo_pthread_key_created = 1;
- }
-
// TODO(iant): For the case of a new C thread calling into Go, such
// as when using -buildmode=c-archive, we know that Go runtime
// initialization is complete but we do not know that all Go init
@@ -75,16 +61,6 @@ _cgo_wait_runtime_init_done(void) {
return 0;
}
-// Store the g into a thread-specific value associated with the pthread key pthread_g.
-// And pthread_key_destructor will dropm when the thread is exiting.
-void x_cgo_bindm(void* g) {
- // We assume this will always succeed, otherwise, there might be extra M leaking,
- // when a C thread exits after a cgo call.
- // We only invoke this function once per thread in runtime.needAndBindM,
- // and the next calls just reuse the bound m.
- pthread_setspecific(pthread_g, g);
-}
-
void
x_cgo_notify_runtime_init_done(void* dummy __attribute__ ((unused))) {
pthread_mutex_lock(&runtime_init_mu);
@@ -134,14 +110,3 @@ _cgo_try_pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*p
}
return EAGAIN;
}
-
-static void
-pthread_key_destructor(void* g) {
- if (x_crosscall2_ptr != NULL) {
- // fn == NULL means dropm.
- // We restore g by using the stored g, before dropm in runtime.cgocallback,
- // since the g stored in the TLS by Go might be cleared in some platforms,
- // before this destructor invoked.
- x_crosscall2_ptr(NULL, g, 0, 0);
- }
-}
diff --git a/src/runtime/cgo/gcc_libinit_windows.c b/src/runtime/cgo/gcc_libinit_windows.c
index 9a8c65ea29..fdcf027424 100644
--- a/src/runtime/cgo/gcc_libinit_windows.c
+++ b/src/runtime/cgo/gcc_libinit_windows.c
@@ -30,9 +30,6 @@ static CRITICAL_SECTION runtime_init_cs;
static HANDLE runtime_init_wait;
static int runtime_init_done;
-uintptr_t x_cgo_pthread_key_created;
-void (*x_crosscall2_ptr)(void (*fn)(void *), void *, int, size_t);
-
// Pre-initialize the runtime synchronization objects
void
_cgo_preinit_init() {
@@ -94,12 +91,6 @@ _cgo_wait_runtime_init_done(void) {
return 0;
}
-// Should not be used since x_cgo_pthread_key_created will always be zero.
-void x_cgo_bindm(void* dummy) {
- fprintf(stderr, "unexpected cgo_bindm on Windows\n");
- abort();
-}
-
void
x_cgo_notify_runtime_init_done(void* dummy) {
_cgo_maybe_run_preinit();
diff --git a/src/runtime/cgo/gcc_stack_darwin.c b/src/runtime/cgo/gcc_stack_darwin.c
deleted file mode 100644
index 700d2eb5a5..0000000000
--- a/src/runtime/cgo/gcc_stack_darwin.c
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2023 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-#include <pthread.h>
-#include "libcgo.h"
-
-void
-x_cgo_getstackbound(uintptr *low)
-{
- void* addr;
- size_t size;
- pthread_t p;
-
- p = pthread_self();
- addr = pthread_get_stackaddr_np(p); // high address (!)
- size = pthread_get_stacksize_np(p);
- *low = (uintptr)addr - size;
-}
diff --git a/src/runtime/cgo/gcc_stack_unix.c b/src/runtime/cgo/gcc_stack_unix.c
deleted file mode 100644
index 6fe46c56d7..0000000000
--- a/src/runtime/cgo/gcc_stack_unix.c
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2023 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build unix && !darwin
-
-#ifndef _GNU_SOURCE // pthread_getattr_np
-#define _GNU_SOURCE
-#endif
-
-#include <pthread.h>
-#include "libcgo.h"
-
-void
-x_cgo_getstackbound(uintptr *low)
-{
- pthread_attr_t attr;
- void *addr;
- size_t size;
-
-#if defined(__GLIBC__) || (defined(__sun) && !defined(__illumos__))
- // pthread_getattr_np is a GNU extension supported in glibc.
- // Solaris is not glibc but does support pthread_getattr_np
- // (and the fallback doesn't work...). Illumos does not.
- pthread_getattr_np(pthread_self(), &attr); // GNU extension
- pthread_attr_getstack(&attr, &addr, &size); // low address
-#elif defined(__illumos__)
- pthread_attr_init(&attr);
- pthread_attr_get_np(pthread_self(), &attr);
- pthread_attr_getstack(&attr, &addr, &size); // low address
-#else
- pthread_attr_init(&attr);
- pthread_attr_getstacksize(&attr, &size);
- addr = __builtin_frame_address(0) + 4096 - size;
-#endif
- pthread_attr_destroy(&attr);
-
- *low = (uintptr)addr;
-}
diff --git a/src/runtime/cgo/gcc_stack_windows.c b/src/runtime/cgo/gcc_stack_windows.c
deleted file mode 100644
index 14604e1e4f..0000000000
--- a/src/runtime/cgo/gcc_stack_windows.c
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2023 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-#include "libcgo.h"
-
-void x_cgo_getstackbound(uintptr *low) {} // no-op for now
diff --git a/src/runtime/cgo/libcgo.h b/src/runtime/cgo/libcgo.h
index 04755f0f20..af4960e7e9 100644
--- a/src/runtime/cgo/libcgo.h
+++ b/src/runtime/cgo/libcgo.h
@@ -52,11 +52,6 @@ extern void (*_cgo_thread_start)(ThreadStart *ts);
extern void (*_cgo_sys_thread_create)(void* (*func)(void*), void* arg);
/*
- * Indicates whether a dummy pthread per-thread variable is allocated.
- */
-extern uintptr_t *_cgo_pthread_key_created;
-
-/*
* Creates the new operating system thread (OS, arch dependent).
*/
void _cgo_sys_thread_start(ThreadStart *ts);