Compile protobuf without pthread

865 views
Skip to first unread message

Sam Van den Steen

unread,
Nov 23, 2016, 4:26:11 AM11/23/16
to Protocol Buffers
Dear all,

I'm developing some binary instrumentation tools where I use protobuf to save the output. I wrote a Pintool using this and everything works fine. However, I wanted to try DynamoRIO because Pin cannot be used to instrument ARM code. Apparently DynamoRIO cannot be linked against libpthread which protobuf needs.

Is it possible to compile a version of protobuf without pthreads so I don't have to link against it? I found at least one project where it seemed to work, but sadly, the modifications he made to the code are not available anymore.


I also found multiple > five year old threads in this discussion group (detailing it seemed to be impossible), but I was wondering if it was possible to compile without pthreads for the newer protobuf 3?

Kind regards,
Sam Van den Steen

Adam Cozzette

unread,
Nov 23, 2016, 4:41:47 PM11/23/16
to Sam Van den Steen, Protocol Buffers
I think it should be possible to build without pthreads if you just make a few minor tweaks. I fiddled around with this a little bit and got something that seems to mostly work on a branch here (though I have not really tested it): https://github.com/acozzette/protobuf/tree/without-pthread

I mostly just had to do the following:
- Update configure.ac to unset HAVE_PTHREAD
- Update stubs/common.cc to provide a no-op implementation of the Mutex class.

Of course this assumes that your application will be single-threaded; if you were to build the code in this configuration and then use threads anyway, things would go wrong because you have data races caused by the lack of real locking.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Sam Van den Steen

unread,
Nov 24, 2016, 5:55:02 AM11/24/16
to Protocol Buffers, samvand...@gmail.com
Hi Adam,

I checked out your updates and integrated them into my instrumentation tool. This seems to work perfectly, no strange crashes anymore. Of course I will test this more thoroughly in the next few days, but it's certainly promising.

Thanks for the help!

Best,
Sam

Op woensdag 23 november 2016 22:41:47 UTC+1 schreef Adam Cozzette:
I think it should be possible to build without pthreads if you just make a few minor tweaks. I fiddled around with this a little bit and got something that seems to mostly work on a branch here (though I have not really tested it): https://github.com/acozzette/protobuf/tree/without-pthread

I mostly just had to do the following:
- Update configure.ac to unset HAVE_PTHREAD
- Update stubs/common.cc to provide a no-op implementation of the Mutex class.

Of course this assumes that your application will be single-threaded; if you were to build the code in this configuration and then use threads anyway, things would go wrong because you have data races caused by the lack of real locking.
On Wed, Nov 23, 2016 at 1:26 AM, Sam Van den Steen <samvand...@gmail.com> wrote:
Dear all,

I'm developing some binary instrumentation tools where I use protobuf to save the output. I wrote a Pintool using this and everything works fine. However, I wanted to try DynamoRIO because Pin cannot be used to instrument ARM code. Apparently DynamoRIO cannot be linked against libpthread which protobuf needs.

Is it possible to compile a version of protobuf without pthreads so I don't have to link against it? I found at least one project where it seemed to work, but sadly, the modifications he made to the code are not available anymore.


I also found multiple > five year old threads in this discussion group (detailing it seemed to be impossible), but I was wondering if it was possible to compile without pthreads for the newer protobuf 3?

Kind regards,
Sam Van den Steen

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.

Adam Cozzette

unread,
Nov 28, 2016, 11:16:16 AM11/28/16
to Sam Van den Steen, Protocol Buffers
Great, I'm glad to hear that it worked! If you want to clean up those changes and make it easier to build in a single-threaded (pthread-free) mode, feel free to send out a pull request for it.

To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe@googlegroups.com.

Sam Van den Steen

unread,
Dec 5, 2016, 2:43:11 AM12/5/16
to Protocol Buffers, samvand...@gmail.com
When I have some time to do this properly, I will definitely do this as it can only help others. Thanks!

Op maandag 28 november 2016 17:16:16 UTC+1 schreef Adam Cozzette:
Reply all
Reply to author
Forward
0 new messages