-
Notifications
You must be signed in to change notification settings - Fork 15.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C++] Intermittent Segmentation fault Mutex MacOS #2943
Comments
PS Note that simply compiling generated C++ files into the shared library libbar.dylib (not instantiating anything) and dloading the library will cause the seg fault. Same issue if actually instantiating a message. |
Does "make check" work for you when you install protobuf? Can you provide the .proto file in question and an example .cc program that can reproduce the issue? |
OK, this is part of a commercial application, and I have stripped out a lot of code, hence it may seem a bit random. Creating a dylib with these files however will cause the issue every time that dylib is dlopened on MacOS. Linux and Windows DLL's have no problem at all. |
I can reproduce this with Xcode 8.3 onwards but with 8.2 and earlier I don't suffer the problem. For us the failure is permanent and we are using protobuf 2.6.0. make check passes for protobuf 2.7.0 and 2.6.0 for me, that said it doesn't cover the situation where libprotobuf.a is statically linked into another dynamic library. |
I experience the same problem on Mac OS 10.12.5, XCode 8.3.3 (both AppleClang 8.1.0 and Apple LLVM version 8.1.0 (clang-802.0.42)) Both program and a .so link libprotobufd statically. The program executes InitShutdownFunctions() at startup. When .so is loaded it doesn't execute InitShutdownFunctions() which causes a crash when OnShutdown() is called from generated InitGeneratedPool() (see stack trace below).
|
Has there been any resolution or work arounds for this defect? I just reproduced it in version 3.5.0 running on High Sierra. I encounter this immediately when loading a library statically linked to libprotobuf. Here is what is causing the crash. No idea what the root cause is. Process 11289 launched: '/Users/gatkinso/work/test/mytest' (x86_64)
|
Are you sure the proto library is only linked in once? This seems like the proto lib is included twice in the final executable. Resulting in weird behavior like this. |
After a few tries I was able to reproduce the segfault on my macosx laptop. These don't segfault and will work:
These will segfault:
The stack trace I got for the crash case looks exactly the same as reported here. So if you get the same stack trace, you are likely linking in more than one copy of protobuf and the only working solution is to dynamically link with protobuf everywhere. |
The initialization code is sloppy beyond belief, yet this is what passes as a fix? Fine. I'll fix it myself. |
There is no fix for this problem as we have no plan to support double linking protobuf. |
To work around this problem I made void InitShutdownFunctionsOnce() (in src/google/stubs/common.cc) not inlined. I hope it helps! |
Pretty-wise that is basically the approach I am looking at as well. However for me it is not a complete solution. The issue for me is that I am writing an application that can load plugins developed by third parties. Since I statically link to libprotobuf... this will prevent any third parties from doing likewise (which is how this defect was discovered to begin with, and shipping a shared library along with a plugin is a can of worms nobody wants to open). Do I have to have third parties fork PB as well in order to get it to work? Well, I guess the caveat "Do not use Google Protocol Buffers in your plugin" has to go in Doxygen. But at least I can provide this link to explain why - which basically boils down to "they don't feel like fixing it." |
That's my feeling too. In my experience protobufs is supporting static linking to multiple libraries. It looks like MacOS specific issue to me. I am building a similar application except I develop all the plugins myself. I am testing it on MacOS and CentOS and everything is working well on CentOS - only MacOS has the problem. |
Yup - Windows and various flavors of Linux seem to be fine.... and the 2.x lineage didn't seem to have this issue. Oh well, what's done is done. |
Version 3.2.0
C++
MacOS Sierra
Intermittent Segmentation fault when statically linking to libprotobufd. Same code is fine on Linux and Windows.
Debugger output:
hostname:testfolder gat$ lldb ./foo
(lldb) target create "foo"
Current executable set to 'foo' (x86_64).
(lldb) run
Process 18781 launched: '/Users/gat/work/testfolder/foo' (x86_64)
Process 18781 stopped
frame #0: 0x0000000102560d33 libbar.dylib`google::protobuf::internal::Mutex::Lock(this=0x0000000000000000) at common.cc:375
372 }
373
374 void Mutex::Lock() {
-> 375 int result = pthread_mutex_lock(&mInternal->mutex);
376 if (result != 0) {
377 GOOGLE_LOG(FATAL) << "pthread_mutex_lock: " << strerror(result);
378 }
(lldb)
The text was updated successfully, but these errors were encountered: