diff options
| author | Cherry Mui <cherryyz@google.com> | 2023-03-31 19:16:12 +0000 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2023-03-31 19:26:35 +0000 |
| commit | bfe3c678ab70d9a033b219276636c3f4669c1dc9 (patch) | |
| tree | 26b80494f04e11f926350aaf9d19eff0bc0d6fae /src/runtime/cgo | |
| parent | 99276aeb5e8b40ff9cd3cafd47ce11c58ba0130c (diff) | |
| download | go-bfe3c678ab70d9a033b219276636c3f4669c1dc9.tar.xz | |
Revert "runtime/cgo: store M for C-created thread in pthread key"
This reverts CL 392854.
Reason for revert: caused #59294, which was derived from google
internal tests. The attempted fix of #59294 caused more breakage.
Change-Id: I5a061561ac2740856b7ecc09725ac28bd30f8bba
Reviewed-on: https://go-review.googlesource.com/c/go/+/481060
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/cgo')
| -rw-r--r-- | src/runtime/cgo/asm_386.s | 8 | ||||
| -rw-r--r-- | src/runtime/cgo/asm_amd64.s | 8 | ||||
| -rw-r--r-- | src/runtime/cgo/asm_arm.s | 8 | ||||
| -rw-r--r-- | src/runtime/cgo/asm_arm64.s | 8 | ||||
| -rw-r--r-- | src/runtime/cgo/asm_loong64.s | 8 | ||||
| -rw-r--r-- | src/runtime/cgo/asm_mips64x.s | 8 | ||||
| -rw-r--r-- | src/runtime/cgo/asm_mipsx.s | 8 | ||||
| -rw-r--r-- | src/runtime/cgo/asm_ppc64x.s | 24 | ||||
| -rw-r--r-- | src/runtime/cgo/asm_riscv64.s | 8 | ||||
| -rw-r--r-- | src/runtime/cgo/asm_s390x.s | 8 | ||||
| -rw-r--r-- | src/runtime/cgo/asm_wasm.s | 3 | ||||
| -rw-r--r-- | src/runtime/cgo/callbacks.go | 36 | ||||
| -rw-r--r-- | src/runtime/cgo/gcc_libinit.c | 35 | ||||
| -rw-r--r-- | src/runtime/cgo/gcc_libinit_windows.c | 9 | ||||
| -rw-r--r-- | src/runtime/cgo/libcgo.h | 5 |
15 files changed, 0 insertions, 184 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 8eb4a42157..fea749670b 100644 --- a/src/runtime/cgo/asm_ppc64x.s +++ b/src/runtime/cgo/asm_ppc64x.s @@ -7,26 +7,6 @@ #include "textflag.h" #include "asm_ppc64x.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), R5 -#ifdef GOARCH_ppc64 - MOVD $_crosscall2<>(SB), R6 -#else - MOVD $crosscall2(SB), R6 -#endif - MOVD R6, (R5) - RET - -#ifdef GO_PPC64X_HAS_FUNCDESC -// _crosscall2<> is a function descriptor to the real crosscall2. -DATA _crosscall2<>+0(SB)/8, $crosscall2(SB) -DATA _crosscall2<>+8(SB)/8, $TOC(SB) -DATA _crosscall2<>+16(SB)/8, $0 -GLOBL _crosscall2<>(SB), NOPTR, $24 -#endif - // 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. @@ -52,12 +32,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 792dd7d086..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) 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/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); |
