Skip to content
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++: PrintDebugString() causes core dump #6939

Closed
mberaha opened this issue Nov 24, 2019 · 5 comments
Closed

C++: PrintDebugString() causes core dump #6939

mberaha opened this issue Nov 24, 2019 · 5 comments

Comments

@mberaha
Copy link

mberaha commented Nov 24, 2019

What version of protobuf and what language are you using?
Version: master
Language: C++

What operating system (Linux, Windows, ...) and version?
Linux, Ubuntu 18.04

What runtime / compiler are you using (e.g., python version or gcc version)
g++ v7.4.0

What did you do?
in file main.cpp

#include <google/protobuf/text_format.h>
#include <my_msg.pb.h>

int main() {
   MyMsg msg;
   msg.set_id(1);
   msg.PrintDebugString();
}

from the terminal

> /usr/bin/protoc --proto_path=./ --cpp_out=./ my_msg.proto
> c++ -g main.cpp my_msg.pb.cc `pkg-config --cflags g --libs protobuf`

The produced error is

terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1
Aborted (core dumped)

Also, gdb didn't produce any better explanation.

At first it doesn't seem to me a problem of library mismatch since protoc an my executable al loading the same shared object

mario@mario-XPS:~$ ldd /usr/bin/protoc
	linux-vdso.so.1 (0x00007ffce0fdf000)
	libprotoc.so.22 => /usr/lib/libprotoc.so.22 (0x00007f0f454b8000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f0f4512f000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0f44f17000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f0f44cf8000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0f44907000)
	libprotobuf.so.22 => /usr/lib/libprotobuf.so.22 (0x00007f0f4445c000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f0f45b6f000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0f440be000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f0f43ea1000)

mario@mario-XPS:~$ ldd ./main
	linux-vdso.so.1 (0x00007ffc2adfb000)
	libprotobuf.so.22 => /usr/lib/libprotobuf.so.22 (0x00007f4604b20000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f4604797000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f460457f000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f460418e000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f4603f71000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f46051da000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4603bd3000)

Also, the same problem arises if I use any of the metod from TextFormat like PrintToString

@Riccardopeli
Copy link

I have just installed from master and got the same issue! Any fixes?

@rafi-kamal
Copy link
Contributor

@gerben-s @haberman

@haberman
Copy link
Member

I reproduced this and got the following stack trace:

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff76b88ad in __GI_abort () at abort.c:79
#2  0x00007ffff7ed1983 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff7ed78c6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff7ed7901 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff7ed7b34 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff7ed3a55 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x00005555555970c8 in std::call_once<void (&)(google::protobuf::internal::DescriptorTable const*), google::protobuf::internal::DescriptorTable const*&> (
    __once=...,
    __f=@0x5555555960e0: {void (const struct google::protobuf::internal::DescriptorTable *)} 0x5555555960e0 <google::protobuf::(anonymous namespace)::AssignDescriptorsImpl(google::protobuf::internal::
DescriptorTable const*)>, __args#0=@0x7fffffffddc8: 0x55555567de00 <descriptor_table_test_2eproto>)
    at /usr/include/x86_64-linux-gnu/c++/8/bits/gthr-default.h:699
#8  0x000055555558c8fe in google::protobuf::internal::AssignDescriptors (table=<optimized out>) at google/protobuf/generated_message_reflection.cc:2407
#9  0x000055555556c8ba in MyMessage::GetMetadataStatic () at test.pb.h:168
#10 0x000055555556bd3d in MyMessage::GetMetadata (this=0x7fffffffe040) at test.pb.cc:270
#11 0x00005555555b2103 in google::protobuf::Message::GetReflection (this=0x7fffffffe040) at ./google/protobuf/message.h:333
#12 google::protobuf::TextFormat::Printer::Print (this=0x7fffffffdf40, message=..., generator=0x7fffffffdec0) at google/protobuf/text_format.cc:1969
#13 0x00005555555b2946 in google::protobuf::TextFormat::Printer::Print (this=<optimized out>, message=..., output=<optimized out>)
    at google/protobuf/text_format.cc:1883
#14 0x00005555555b29a8 in google::protobuf::TextFormat::Printer::PrintToString (this=this@entry=0x7fffffffdf40, message=..., output=output@entry=0x7fffffffe000)
    at google/protobuf/text_format.cc:1867
#15 0x00005555555b2a04 in google::protobuf::Message::DebugString[abi:cxx11]() const (this=0x7fffffffe040) at google/protobuf/text_format.cc:90
#16 0x00005555555b2a74 in google::protobuf::Message::PrintDebugString (this=<optimized out>) at google/protobuf/text_format.cc:123
#17 0x000055555556b047 in main () at test.cc:7

Digging in now.

@haberman
Copy link
Member

I think the problem is that the pthread library is not linked: https://stackoverflow.com/questions/51584960/stdcall-once-throws-stdsystem-error-unknown-error-1

If I change the command line above to add -lpthread at the end, it works.

@mberaha
Copy link
Author

mberaha commented Nov 26, 2019

Thank you, it works!!

@mberaha mberaha closed this as completed Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants