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

crash when protocol buffers are used in .so #206

fkusche opened this Issue Feb 11, 2015 · 5 comments


None yet
5 participants
Copy link

fkusche commented Feb 11, 2015

Consider the following foo.cpp:

#include <dlfcn.h>
#include <stdio.h>
#include "p.pb.h"

int main()
    void* soHandle = dlopen( "./", RTLD_NOW );
    if( !soHandle ) {
        fprintf( stderr, "couldn't load\n" );
        return 1;
    dlclose( soHandle );
    printf( "shutting down protobuf\n" );

    return 0;

and bar.cpp:

int bar()
    return 0;

and p.proto:

package FooCfg;
message Msg {
     required int32 dummy = 2;

Compile the proto file: protoc --cpp_out=. p.proto
Compile foo to an executable: g++ -fPIC foo.cpp -ofoo -lprotobuf -ldl
Compile bar to a dll: g++ -fPIC -Wl,--unresolved-symbols=ignore-in-shared-libs -shared -o bar.cpp -lprotobuf

running foo will produce a segmentation fault in ShutdownProtobufLibrary():

> gdb ./foo
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
Find the GDB manual and other documentation resources online at:
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./foo...(no debugging symbols found)...done.
(gdb) r
Starting program: /home/pasu/devel/test/foo 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/".
shutting down protobuf

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6698441 in ?? ()
(gdb) bt
#0  0x00007ffff6698441 in ?? ()
#1  0x00007ffff7af868b in google::protobuf::ShutdownProtobufLibrary() () from /usr/lib/x86_64-linux-gnu/
#2  0x00000000004008b1 in main ()

Without dlopening, there will be no segfault.
Also, when is not compiled into

Is this because of global constructors/destructors being executed?
How can this be solved?


This comment has been minimized.

Copy link

KjellKod commented Jul 30, 2015

@fkusche did you find out what it was? Any work around? I believe a project that I am working on is experiencing a very similar issue.

If we use .so then we see this crash. If we create it as a .a (static) then it doesn't happen.


This comment has been minimized.

Copy link

fkusche commented Aug 28, 2015

@KjellKod sorry for the late answer. No I did not find out anything more, unfortunately.


This comment has been minimized.

Copy link

xfxyjwf commented Jan 20, 2016

As protobuf has used some global variables, linking protobuf dynamically with dlopen across several modules are very problematic. I'm not aware of any good solution here.

@xfxyjwf xfxyjwf closed this Jan 20, 2016


This comment has been minimized.

Copy link

LocutusOfBorg commented May 18, 2017

Hello, if I'm correct this is making the vlc build segfault now


This comment has been minimized.

Copy link

RaghavanSanthanam commented Mar 30, 2018

I encountered this issue when building VLC v3.0.1 using clang/LLVM on Ubuntu 17.10 x86_64 when using protobuf 3.0.0 and found a resolution for the same by taking latest protobuf v3.5.1 source and building it using clang/LLVM and installing, using it instead of protobuf 3.0.0(default one from Ubuntu repo). Here's my complete report for the interested ones :

Raghavan Santhanam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment