starrysky9959 commented on issue #1086: URL: https://github.com/apache/brpc/issues/1086#issuecomment-1510918042
感觉本质是因为brpc通过`dlsym(RTLD_NEXT, "pthread_mutex_lock");`hook了`libpthread`中的`pthread_mutex_lock`方法导致的. `RTLD_NEXT`意味着在load dynamic libraries时, `libpthread`必须在`libbrpc`之后被load, 且两者中间不能有其他含有symbol为`pthread_mutex_lock`的library(虽然一般不会再有了). 以下几篇文章介绍了相关概念和实践. [https://optumsoft.com/dangers-of-using-dlsym-with-rtld_next/](https://optumsoft.com/dangers-of-using-dlsym-with-rtld_next/) [https://csstormq.github.io/blog/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%B3%BB%E7%BB%9F%E7%AF%87%E4%B9%8B%E9%93%BE%E6%8E%A5%EF%BC%8816%EF%BC%89%EF%BC%9A%E7%9C%9F%E6%AD%A3%E7%90%86%E8%A7%A3%20RTLD_NEXT%20%E7%9A%84%E4%BD%9C%E7%94%A8](https://csstormq.github.io/blog/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%B3%BB%E7%BB%9F%E7%AF%87%E4%B9%8B%E9%93%BE%E6%8E%A5%EF%BC%8816%EF%BC%89%EF%BC%9A%E7%9C%9F%E6%AD%A3%E7%90%86%E8%A7%A3%20RTLD_NEXT%20%E7%9A%84%E4%BD%9C%E7%94%A8) [https://zhuanlan.zhihu.com/p/44132805](https://zhuanlan.zhihu.com/p/44132805) 我的项目中不方便修改pthread的链接位置,可以利用`LD_PRELOAD`来提前加载`libbrpc`以满足这一要求. ```bash export LD_PRELOAD=/lib/libbrpc.so ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
