You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by ww...@apache.org on 2022/12/28 11:46:38 UTC

[incubator-brpc] branch master updated: fix rpc maybe error: " libbrpc.so: undefined symbol: pthread_mutex_lo… (#2049)

This is an automated email from the ASF dual-hosted git repository.

wwbmmm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new 630621f4 fix rpc maybe error: " libbrpc.so: undefined symbol: pthread_mutex_lo… (#2049)
630621f4 is described below

commit 630621f48cd7410222927c06b6bb989e08435b69
Author: co0l1ce <77...@users.noreply.github.com>
AuthorDate: Wed Dec 28 19:46:33 2022 +0800

    fix rpc maybe error: " libbrpc.so: undefined symbol: pthread_mutex_lo… (#2049)
    
    * fix rpc maybe error: " libbrpc.so: undefined symbol: pthread_mutex_lock "
    
    * fix rpc maybe error: " libbrpc.so: undefined symbol: pthread_mutex_lock "
    
    Co-authored-by: root <ya...@baidu.com>
---
 src/bthread/mutex.cpp | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/bthread/mutex.cpp b/src/bthread/mutex.cpp
index f0dfc044..4dc6598d 100644
--- a/src/bthread/mutex.cpp
+++ b/src/bthread/mutex.cpp
@@ -404,13 +404,27 @@ static pthread_once_t init_sys_mutex_lock_once = PTHREAD_ONCE_INIT;
 //   #23 0x00000000006fbb9a in tc_malloc ()
 // Call _dl_sym which is a private function in glibc to workaround the malloc
 // causing deadlock temporarily. This fix is hardly portable.
+
+/* refer dlsym implement
+ * https://codebrowser.dev/glibc/glibc/dlfcn/dlsym.c.html#78
+ * void *
+ * ___dlsym (void *handle, const char *name)
+ * {
+ *   return __dlsym (handle, name, RETURN_ADDRESS (0));
+ *   }
+ *
+ */
+
+#define RETURN_ADDRESS(nr) \
+    __builtin_extract_return_addr (__builtin_return_address (nr) )
+
 static void init_sys_mutex_lock() {
 #if defined(OS_LINUX)
     // TODO: may need dlvsym when GLIBC has multiple versions of a same symbol.
     // http://blog.fesnel.com/blog/2009/08/25/preloading-with-multiple-symbol-versions
     if (_dl_sym) {
-        sys_pthread_mutex_lock = (MutexOp)_dl_sym(RTLD_NEXT, "pthread_mutex_lock", (void*)init_sys_mutex_lock);
-        sys_pthread_mutex_unlock = (MutexOp)_dl_sym(RTLD_NEXT, "pthread_mutex_unlock", (void*)init_sys_mutex_lock);
+        sys_pthread_mutex_lock = (MutexOp)_dl_sym(RTLD_NEXT, "pthread_mutex_lock", RETURN_ADDRESS (0));
+        sys_pthread_mutex_unlock = (MutexOp)_dl_sym(RTLD_NEXT, "pthread_mutex_unlock", RETURN_ADDRESS (0));
     } else {
         // _dl_sym may be undefined reference in some system, fallback to dlsym
         sys_pthread_mutex_lock = (MutexOp)dlsym(RTLD_NEXT, "pthread_mutex_lock");


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org