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

terminate called after throwing an instance of 'std::system_error' - after switching to version 3.6.0 (from 3.5.1) #4958

Closed
ujmedia opened this issue Jul 23, 2018 · 8 comments
Assignees

Comments

@ujmedia
Copy link

ujmedia commented Jul 23, 2018

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

What operating system (Linux, Windows, ...) and version?
Debian Linux 9.5

What runtime / compiler are you using (e.g., python version or gcc version)
g++ (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
Linux version 4.9.0-6-amd64 ([email protected]) (gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1) ) #1 SMP Debian 4.9.82-1+deb9u3 (2018-03-02)

What did you do?
Steps to reproduce the behavior:
Just recompiled my source after changed to version 3.6.0

What did you expect to see
No runtime error!

What did you see instead?
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

gdb ./proto_test_Config
GNU gdb (Debian 7.12-6) 7.12.0.20161007-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
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:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./proto_test_Config...done.
(gdb) run
Starting program: /mnt/application/sources/txt-autocontent-news/libtxt-autocontent/proto_test_Config
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1

Program received signal SIGABRT, Aborted.
0x000000000060527e in raise ()
(gdb) where
#0 0x000000000060527e in raise ()
#1 0x000000000060544a in abort ()
#2 0x00000000005e4f1d in __gnu_cxx::__verbose_terminate_handler() ()
#3 0x000000000055b446 in __cxxabiv1::__terminate(void (*)()) ()
#4 0x000000000055b491 in std::terminate() ()
#5 0x000000000055c6d9 in __cxa_throw ()
#6 0x00000000005660be in std::__throw_system_error(int) ()
#7 0x000000000042757c in std::call_once<void (&)()> (__once=..., __f=@0x4028fc: {void (void)} 0x4028fc <protobuf_news_2econfig_2eproto::AddDescriptorsImpl()>) at /usr/include/c++/6/mutex:622
#8 0x0000000000421d7c in google::protobuf::internal::call_once<std::once_flag&, void (&)()> (args#0=..., args#1=@0x4028fc: {void (void)} 0x4028fc <protobuf_news_2econfig_2eproto::AddDescriptorsImpl()>)
at /usr/local/include/google/protobuf/stubs/once.h:91
#9 0x0000000000402943 in protobuf_news_2econfig_2eproto::AddDescriptors () at news.config.pb.cc:808
#10 0x0000000000420fb1 in protobuf_news_2econfig_2eproto::StaticDescriptorInitializer::StaticDescriptorInitializer (this=0x96aeb8 <protobuf_news_2econfig_2eproto::static_descriptor_initializer>) at news.config.pb.cc:813
#11 0x000000000041d15c in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at news.config.pb.cc:815
#12 0x000000000041d172 in _GLOBAL__sub_I__ZN4NEWS53_SourceXmlFiles_FilesEntry_DoNotUse_default_instance_E () at news.config.pb.cc:7783
#13 0x00000000005fd897 in __libc_csu_init ()
#14 0x00000000005fce2b in generic_start_main ()
#15 0x00000000005fd242 in __libc_start_main ()
#16 0x0000000000401c1a in _start ()

Anything else we should know about your project / environment
Just a protobuf object tester executable (nothing complicated)!

@gerben-s
Copy link
Contributor

I think you are missing threading support. Maybe -pthread as an option

@ujmedia
Copy link
Author

ujmedia commented Jul 31, 2018

I checked your suggestion but -pthread is not missed!

I'm using pkg-config to add the right things to the build command and there is a difference
by 3.6.0! In case of 3.5.1 you can see that there is -lpthread option, but it is missing by 3.6.0!

root@um-deb8-dev:/protobuf/protobuf-3.5.1# protoc --version
libprotoc 3.5.1
root@um-deb8-dev:/protobuf/protobuf-3.5.1# pkg-config --libs --cflags protobuf
-pthread -I/usr/local/include -L/usr/local/lib -lprotobuf -pthread -lpthread

root@um-deb8-dev:/protobuf/protobuf-3.6.0# protoc --version
libprotoc 3.6.0
root@um-deb8-dev:/protobuf/protobuf-3.6.0# pkg-config --libs --cflags protobuf
-pthread -I/usr/local/include -L/usr/local/lib -lprotobuf -pthread

But still you were right!
I realized that this error only happens when I build it as static!

I tried to build the binary by static flags:

g++ -g -std=c++11 -static -static-libstdc++ news.config.pb.cc proto_test_Config.cpp -o proto_test_Config $(pkg-config --libs --cflags protobuf) -lpthread

Not worked!
But it was not enough to add -lpthread to the end of the command!
I have found that linking with -lpthread can cause application crash and other interesting things in static builds! So I had to extend the build command and now works fine:

g++ -g -std=c++11 -static -static-libstdc++ news.config.pb.cc proto_test_Config.cpp -o proto_test_Config $(pkg-config --libs --cflags protobuf) -Wl,--whole-archive -lpthread -Wl,--no-whole-archive

So I can close this issue for now!

@askypeck
Copy link

This issue shouldn't be closed. You haven't found a root cause. I had the same problem linking 3.6.1 on CentOS7. Your own examples failed to work. Falling back on 3.4.1..

@m4rkusxxl
Copy link

Got the same error when building bitcoin-qt:
/usr/bin/protoc --cpp_out=qt --proto_path=qt qt/paymentrequest.proto
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1

Rebuilding protobuf-3.6.1 with old bfd linker fixed it.
=> ld.gold is not supported by protobuf!

@rchav
Copy link

rchav commented Nov 28, 2018

Getting the same error on ubuntu 14 with 3.6.1. rolling back to pre 3.6 fixes it.

@branens
Copy link

branens commented Jun 16, 2019

set(CMAKE_EXE_LINKER_FLAGS "-static -pthread")

@rambattu
Copy link

I faced the same issue when I compiled protobuf-3.6.1 to build a library and use it for one of my custom binary. It used to work fine with protobuf-3.2.0 fine, but the binary started failing with this error after protobuf-3.6.1 upgrade.

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

Suggestion by 'Vaphell' in this thread https://ubuntuforums.org/showthread.php?t=2183408 pointed to g++ bug which has the workaround here https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1228201.

For me, after I added linker flags using
LDFLAGS += -pthread -Wl,--no-as-needed
in my Makefile the binary started working fine.

esuarezsantana added a commit to esuarezsantana/worr-exheres that referenced this issue Feb 13, 2020
This is a workaround as shown in the link to the error below.

protocolbuffers/protobuf#4958 (comment)

Error message:
```
...
/usr/x86_64-pc-linux-gnu/bin/protoc --plugin=protoc-gen-c=./protoc-c/protoc-gen-c -I. --c_out=. ./t/test.proto
/usr/x86_64-pc-linux-gnu/bin/protoc --plugin=protoc-gen-c=./protoc-c/protoc-gen-c -I. --c_out=. ./t/test.proto
/usr/x86_64-pc-linux-gnu/bin/protoc --plugin=protoc-gen-c=./protoc-c/protoc-gen-c -I. --c_out=. ./t/test-full.proto
[libprotobuf WARNING google/protobuf/compiler/parser.cc:564] No syntax specified for the proto file: t/test.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
[libprotobuf WARNING google/protobuf/compiler/parser.cc:564] No syntax specified for the proto file: t/test.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1
[libprotobuf WARNING google/protobuf/compiler/parser.cc:564] No syntax specified for the proto file: t/test-full.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1
--c_out: protoc-gen-c: Plugin killed by signal 6.
make: *** [Makefile:2395: t/test.pb-c.c] Error 1
make: *** Waiting for unfinished jobs....
--c_out: protoc-gen-c: Plugin killed by signal 6.
make: *** [Makefile:2395: t/test.pb-c.h] Error 1
--c_out: protoc-gen-c: Plugin killed by signal 6.
make: *** [Makefile:2401: t/test-full.pb-c.c] Error 1

Error:
  * In program cave --colour yes perform install --hooks --managed-output --output-exclusivity with-others =dev-libs/protobuf-c-1.3.2-r1:0::worr --destination installed --replacing =dev-libs/protobuf-c-1.3.2:0::installed --x-of-y 1 of 1:
  * When installing 'dev-libs/protobuf-c-1.3.2-r1:0::worr' replacing { 'dev-libs/protobuf-c-1.3.2:0::installed' }:
  * When running an ebuild command on 'dev-libs/protobuf-c-1.3.2-r1:0::worr':
  * Install failed for 'dev-libs/protobuf-c-1.3.2-r1:0::worr' (paludis::ActionFailedError)


!!! ERROR in dev-libs/protobuf-c-1.3.2-r1::worr:
!!! In /usr/x86_64-pc-linux-gnu/libexec/paludis/utils/exheres-0/emake at line 30
!!! emake returned error 2

!!! Call stack:
!!!    * paludis_die_or_error_func (/usr/x86_64-pc-linux-gnu/libexec/paludis/die_functions.bash:82)
!!!    * main (/usr/x86_64-pc-linux-gnu/libexec/paludis/utils/exheres-0/emake:30)

diefunc: making ebuild PID 381047 exit with error
die trap: exiting with error.

Failed install to / for dev-libs/protobuf-c-1.3.2-r1:0::worr replacing 1.3.2:0::installed
```
ragnorc added a commit to ragnorc/fly-typedb that referenced this issue Feb 23, 2022
On Alpine, TypeDB Studio causes the following error:
terminate called after throwing an instance of 'std::system_error'
  what():  No error information
Issue likely due to a bug in gcc.
See: protocolbuffers/protobuf#4958
@iysheng
Copy link

iysheng commented Aug 14, 2024

I meet the same problem when cross compile tensorflow, the protobuf version is v3.21.9, I meet error like:

  bazel-out/aarch64-opt/bin/external/com_google_protobuf/protoc '--plugin=protoc-gen-PLUGIN=bazel-out/aarch64-opt/bin/external/com_github_grpc_grpc/src/compiler/grpc_cpp_plug
in' '--PLUGIN_out=services_namespace=grpc,generate_mock_code=true:bazel-out/aarch64-opt/bin' '--proto_path=.' '--proto_path=.' '--proto_path=bazel-out/aarch64-opt/bin/externa
l/com_google_protobuf/_virtual_imports/any_proto' '--proto_path=bazel-out/aarch64-opt/bin/external/com_google_protobuf/_virtual_imports/api_proto' '--proto_path=bazel-out/aar
ch64-opt/bin/external/com_google_protobuf/_virtual_imports/source_context_proto' '--proto_path=bazel-out/aarch64-opt/bin/external/com_google_protobuf/_virtual_imports/type_pr
oto' '--proto_path=bazel-out/aarch64-opt/bin/external/com_google_protobuf/_virtual_imports/compiler_plugin_proto' '--proto_path=bazel-out/aarch64-opt/bin/external/com_google_
protobuf/_virtual_imports/descriptor_proto' '--proto_path=bazel-out/aarch64-opt/bin/external/com_google_protobuf/_virtual_imports/duration_proto' '--proto_path=bazel-out/aarc
h64-opt/bin/external/com_google_protobuf/_virtual_imports/empty_proto' '--proto_path=bazel-out/aarch64-opt/bin/external/com_google_protobuf/_virtual_imports/field_mask_proto'
 '--proto_path=bazel-out/aarch64-opt/bin/external/com_google_protobuf/_virtual_imports/struct_proto' '--proto_path=bazel-out/aarch64-opt/bin/external/com_google_protobuf/_vir
tual_imports/timestamp_proto' '--proto_path=bazel-out/aarch64-opt/bin/external/com_google_protobuf/_virtual_imports/wrappers_proto' '--proto_path=.' '--proto_path=bazel-out/a
arch64-opt/bin' tensorflow/compiler/xla/xla.proto)
# Configuration: 856d3467963c2196440904db574c3cab726f62efccb7d2fd17a44448f8886295
# Execution platform: @local_execution_config_platform//:platform
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1
Target //tensorflow:libtensorflow.so failed to build

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

No branches or pull requests

9 participants