bench_bitcoin crashes on FreeBSD and OpenBSD #8910

issue laanwj opened this issue on October 11, 2016
  1. laanwj commented at 10:59 AM on October 11, 2016: member

    bench_bitcoin crashes at startup, even before getting to main. It seems to have to do with the registration system:

    // BENCHMARK(foo) expands to:  benchmark::BenchRunner bench_11foo("foo", foo);
    #define BENCHMARK(n) \
        benchmark::BenchRunner BOOST_PP_CAT(bench_, BOOST_PP_CAT(__LINE__, n))(BOOST_PP_STRINGIZE(n), n);
    

    I don't know how the BOOST_PP_CAT stuff is working internally. This is likely an upstream issue with boost, to do with initialization order. (FreeBSD 10.3, Boost 1.55)

  2. laanwj added the label Tests on Oct 11, 2016
  3. laanwj commented at 6:36 AM on October 13, 2016: member

    I managed to install a newer version of gdb (just pkg install gdb really), which valiantly generates a stack trace...

    [#0](/bitcoin-bitcoin/0/)  0x000000000103d710 in std::__1::__tree<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >, std::__1::__map_value_compare<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> > > >::__insert_node_at(std::__1::__tree_node_base<void*>*, std::__1::__tree_node_base<void*>*&, std::__1::__tree_node_base<void*>*) (__parent=<optimized out>, __child=<optimized out>, 
        __new_node=<optimized out>, this=<optimized out>, __parent=<optimized out>, __child=<optimized out>, __new_node=<optimized out>) at /usr/include/c++/v1/__tree:1715
    [#1](/bitcoin-bitcoin/1/)  std::__1::__tree<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >, std::__1::__map_value_compare<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> > > >::__node_insert_unique(std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >, void*>*) (
        this=<optimized out>, this=<optimized out>, __nd=<optimized out>) at /usr/include/c++/v1/__tree:1928
    [#2](/bitcoin-bitcoin/2/)  std::__1::__tree<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >, std::__1::__map_value_compare<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> > > >::__insert_unique<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> > >(std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >&&) (this=0x130a358 <benchmark::BenchRunner::benchmarks>, __v=<optimized out>)
        at /usr/include/c++/v1/__tree:1805
    [#3](/bitcoin-bitcoin/3/)  0x000000000103c149 in benchmark::BenchRunner::BenchRunner (this=<optimized out>, name=..., func=...) at /usr/local/include/boost/function/function_template.hpp:909
    [#4](/bitcoin-bitcoin/4/)  0x000000000103f287 in global constructors keyed to a ()
    [#5](/bitcoin-bitcoin/5/)  0x00000000010d5752 in __do_global_ctors_aux ()
    [#6](/bitcoin-bitcoin/6/)  0x000000000103b1d6 in _init ()
    

    I have the feeling is is as useless as it is intimidating, though. Will get one without optimization.

  4. laanwj commented at 6:51 AM on October 13, 2016: member
    [#0](/bitcoin-bitcoin/0/)  0x0000000001042096 in std::__1::__tree<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >, std::__1::__map_value_compare<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> > > >::__insert_node_at(std::__1::__tree_node_base<void*>*, std::__1::__tree_node_base<void*>*&, std::__1::__tree_node_base<void*>*) (this=0x13ac378 <benchmark::BenchRunner::benchmarks>, 
        __parent=0x13ac380 <benchmark::BenchRunner::benchmarks+8>, __child=@0x13ac380: 0x804431080, __new_node=0x804431080) at /usr/include/c++/v1/__tree:1715
    [#1](/bitcoin-bitcoin/1/)  0x0000000001040ea4 in std::__1::__tree<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >, std::__1::__map_value_compare<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> > > >::__node_insert_unique(std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >, void*>*) (this=0x13ac378 <benchmark::BenchRunner::benchmarks>, __nd=0x804431080) at /usr/include/c++/v1/__tree:1928
    [#2](/bitcoin-bitcoin/2/)  0x000000000104009c in std::__1::__tree<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >, std::__1::__map_value_compare<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> > > >::__insert_unique<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> > >(std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::function<void (benchmark::State&)> >&&) (this=0x13ac378 <benchmark::BenchRunner::benchmarks>, 
        __v=<unknown type in /usr/home/user/bitcoin/src/bench/bench_bitcoin, CU 0x3857, DIE 0xc501>) at /usr/include/c++/v1/__tree:1805
    [#3](/bitcoin-bitcoin/3/)  0x000000000103cfa8 in benchmark::BenchRunner::BenchRunner (this=0x13ac3d8 <bench_54Base58Encode>, name=..., func=...) at /usr/include/c++/v1/utility:308
    

    That didn't really help, except that we can see that at least the this pointers aren't 0.

    Adding an "upstream" tag. It's becoming clear at least that this is an upstream bug. Whether in the compiler or boost is not apparent to me.

  5. laanwj added the label Upstream on Oct 13, 2016
  6. theuni commented at 6:15 PM on October 24, 2016: member
  7. laanwj commented at 6:39 PM on October 24, 2016: member

    Thanks! But unfortunately no, with that patch it still segfaults:

    Program received signal SIGSEGV, Segmentation fault.
    0x0000000001074fe6 in std::__1::__tree<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::function<void (benchmark::State&)> >, std::__1::__map_value_compare<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::function<void (benchmark::State&)> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::function<void (benchmark::State&)> > > >::__insert_node_at(std::__1::__tree_node_base<void*>*, std::__1::__tree_node_base<void*>*&, std::__1::__tree_node_base<void*>*) (this=0x1d23e78 <benchmark::BenchRunner::benchmarks>, __parent=0x1d23e80 <benchmark::BenchRunner::benchmarks+8>, 
        __child=@0x1d23e80: 0x805187080, __new_node=0x805187080) at /usr/include/c++/v1/__tree:1715
    1715        if (__begin_node()->__left_ != nullptr)
    ...
    [#3](/bitcoin-bitcoin/3/)  0x0000000001071678 in benchmark::BenchRunner::BenchRunner (this=0x1d23fe0 <bench_62CoinSelection>, name=..., func=...)
        at /usr/include/c++/v1/utility:308
    [#4](/bitcoin-bitcoin/4/)  0x000000000109ddfd in __cxx_global_var_init12 () at bench/coin_selection.cpp:62
    [#5](/bitcoin-bitcoin/5/)  0x000000000109eba5 in global constructors keyed to a () at ./bench/coin_selection.cpp:355
    [#6](/bitcoin-bitcoin/6/)  0x000000000195dc72 in __do_global_ctors_aux ()
    [#7](/bitcoin-bitcoin/7/)  0x000000000106ec3e in _init ()
    [#8](/bitcoin-bitcoin/8/)  0x00007fffffffe050 in ?? ()
    [#9](/bitcoin-bitcoin/9/)  0x0000000801d16a9f in ?? () from /libexec/ld-elf.so.1
    [#10](/bitcoin-bitcoin/10/) 0x0000000801d160ee in ?? () from /libexec/ld-elf.so.1
    [#11](/bitcoin-bitcoin/11/) 0x0000000801d14439 in ?? () from /libexec/ld-elf.so.1
    [#12](/bitcoin-bitcoin/12/) 0x0000000000000000 in ?? ()`
    
  8. kazcw commented at 10:12 PM on October 26, 2016: contributor

    I don't think this is an upstream bug.

    The BENCHMARK macro is used at namespace scope, so the BenchRunner variables it declares (in various files) have static storage duration. BenchRunner's ctor requires benchmarks to have been initialized, but benchmarks is also a static variable. Initialization order of static variables declared in different translation units is unspecified. This would only work for compilers that happen to perform the initializations from bench.cpp (including initializing benchmarks) before the initializations of any translation unit that initializes BenchRunners.

  9. laanwj commented at 6:58 AM on October 27, 2016: member

    Yes, would probably be better to just add a list of benchmarks in bench.cpp and skip on the boost magic completely.

  10. laanwj commented at 1:36 PM on February 7, 2017: member

    Still the case as of FreeBSD 11.0-RELEASE-p2 with current master, boost 1_63. Also fails on OpenBSD 6.0.

  11. laanwj renamed this:
    bench_bitcoin crashes on FreeBSD
    bench_bitcoin crashes on FreeBSD and OpenBSD
    on Feb 7, 2017
  12. laanwj referenced this in commit 29c53289a9 on Feb 7, 2017
  13. MarcoFalke closed this on Feb 8, 2017

  14. HashUnlimited referenced this in commit ee9ec6155d on Feb 27, 2018
  15. lateminer referenced this in commit 2cbc56569d on Jan 5, 2019
  16. random-zebra referenced this in commit 46211e25cd on May 27, 2020
  17. random-zebra referenced this in commit e681717345 on May 27, 2020
  18. random-zebra referenced this in commit e94cf15919 on May 28, 2020
  19. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me