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

std::system_error on calc example #23

Closed
mattulbrich opened this issue Nov 10, 2016 · 7 comments
Closed

std::system_error on calc example #23

mattulbrich opened this issue Nov 10, 2016 · 7 comments

Comments

@mattulbrich
Copy link

Hi! I tried to run calc.cc from the example directory. Unfortunately, I received an error message

     $ cd example/
     $ g++ -I .. -std=c++11 calc.cc
     $ ./a.out 2+3*4
     Terminate called after throwing an instance of 'std::system_error'
       what():  Unknown error -1
     Aborted (core dumped)

This is both with g++ and with clang++. Apparently this call to std::call_once is responsible
https://github.com/yhirose/cpp-peglib/blob/21934dd1ce/peglib.h#L1483

@yhirose
Copy link
Owner

yhirose commented Nov 11, 2016

@mattulbrich, thanks for the report.

I have tried 'g++ -I .. -std=c++11 calc.cc' and 'clang++ -I .. -std=c++11 calc.cc' on my MacBook. But both worked fine, gave me '14' as a result.

Which OS or environment are you working on?

Thank you!

@mattulbrich
Copy link
Author

Thanks for looking into it!
I was running (x)Ubuntu 14.04 at the time, but have now updated to Ubuntu 16.04. I still receive the same problem

$ ./a.out 2+3*4
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1
Aborted (core dumped)
$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

Also on another (opensuse) machine with g++ (SUSE Linux) 4.8.3 20140627 [gcc-4_8-branch revision 212064] I get the same error message.

@mattulbrich
Copy link
Author

And I can provide a stacktrace for you. Perhaps it helps a little ...

(gdb) bt
#0  0x00007ffff72400a7 in raise () from /lib64/libc.so.6
#1  0x00007ffff7241458 in abort () from /lib64/libc.so.6
#2  0x00007ffff7b32975 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib64/libstdc++.so.6
#3  0x00007ffff7b309f6 in ?? () from /usr/lib64/libstdc++.so.6
#4  0x00007ffff7b30a41 in std::terminate() () from /usr/lib64/libstdc++.so.6
#5  0x00007ffff7b30c58 in __cxa_throw () from /usr/lib64/libstdc++.so.6
#6  0x00007ffff7b86dbf in std::__throw_system_error(int) () from /usr/lib64/libstdc++.so.6
#7  0x000000000041590a in std::call_once<peg::DefinitionReference::get_rule() const::{lambda()#1}>(std::once_flag&, peg::DefinitionReference::get_rule() const::{lambda()#1}&&) (__once=..., __f=<unknown type in /amd.home/home/i57/mulbrich/tmp/cpp-peglib-master/example/a.out, CU 0x15b, DIE 0x5f779>)
    at /usr/include/c++/4.8/mutex:794
#8  0x0000000000408684 in peg::DefinitionReference::get_rule (this=0x66fba8) at ../peglib.h:1485
#9  0x0000000000409df0 in peg::ParserGenerator::DetectLeftRecursion::visit (this=0x7fffffffd8d0, ope=...) at ../peglib.h:1744
#10 0x0000000000408a00 in peg::DefinitionReference::accept (this=0x66fba8, v=...) at ../peglib.h:1507

@yhirose
Copy link
Owner

yhirose commented Nov 17, 2016

I installed Ubuntu 16.04 on VirtualBox on my MacBook. I am now able to reproduce the problem.

I googled and found some helpful information:
http://stackoverflow.com/questions/15311469/throwing-an-exception-from-stdcall-once
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60662
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58929

According to the suggestion on the above, I tried the following and it worked!

g++ -I .. -std=c++11 calc.cc -pthread

Could you please try it again with -pthread?

@mattulbrich
Copy link
Author

It works!

The resulting executable now links against libpthread.so.0.
Astonishingly, no linker error was produced due to a missing function pointer in __gthread_once, this seems to be deferred to runtime.

Thank you very much for finding this out!

@yhirose
Copy link
Owner

yhirose commented Nov 17, 2016

Thanks for the good report!

@aixi
Copy link

aixi commented May 17, 2019

very helpful, I encounter a bug in protobuf::Message::DebugString(), this function will call std::call_once and throw std::system_error

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

3 participants