Re: [Boost-bugs] [Boost C++ Libraries] #12948: Unexpected snprintf result is on Android ARM

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #12948: Unexpected snprintf result is on Android ARM
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-04-05 21:23:16


#12948: Unexpected snprintf result is on Android ARM
------------------------------------+----------------------
  Reporter: Lev Sch <zorechfan@…> | Owner: olli
      Type: Bugs | Status: reopened
 Milestone: To Be Determined | Component: context
   Version: Boost 1.64.0 | Severity: Problem
Resolution: | Keywords:
------------------------------------+----------------------

Comment (by Lev Sch <zorechfan@…>):

 ${BOOST_ROOT}/libs/context/test/test_apply.cpp

 {{{
 04-05 23:21:31.035 20005-20005/com.example.hellojni D/boostTest: void
 runBoostTests() 91 BEGIN TESTS
 04-05 23:21:31.049 20005-20005/com.example.hellojni D/boostTest: void
 runBoostTests() 100
                                                                  Running 7
 test cases...
 04-05 23:21:31.049 20005-20005/com.example.hellojni D/boostTest: void
 runBoostTests() 175 END OF TESTS
 }}}



 ${BOOST_ROOT}/libs/context/test/test_callcc.cpp

 {{{
 Error:(598, 17) error: no member named 'snprintf' in namespace 'std'; did
 you mean simply 'snprintf'?
 }}}

 after compile error is fixed and BOOST_STATIC_ASSERT is added:

 {{{
 04-05 23:27:49.215 21852-21852/? D/boostTest: void runBoostTests() 91
 BEGIN TESTS
 04-05 23:27:49.233 21852-21852/? D/boostTest: void runBoostTests() 100
                                               Running 15 test cases...
 C:/temp/boostDevelop/boost/libs/context/test/test_callcc.cpp(355): error:
 in "Boost.Context: callcc test suite/_test_ontop": check i == 2 has failed
 [-2 != 2]
 04-05 23:27:49.233 21852-21852/? D/boostTest: void runBoostTests() 175 END
 OF TESTS
 }}}

 changed function text:

 {{{
 void test_snprintf() {
     ctx::continuation c = ctx::callcc(
                 []( ctx::continuation && c) {
             {
                 const char *fmt = "sqrt(2) = %f";
                 char buf[15];
                 snprintf( buf, sizeof( buf), fmt, std::sqrt( 2) );
                 BOOST_CHECK( 0 < sizeof( buf) );
                 BOOST_ASSERT( std::string("sqrt(2) = 1.41") ==
 std::string( buf) );
             }
             {
                 std::uint64_t n = 0xbcdef1234567890;
                 const char *fmt = "0x%016llX";
                 BOOST_STATIC_ASSERT(sizeof(unsigned long long
 int)==sizeof(std::uint64_t)); // llX format
                 char buf[100];
                 snprintf( buf, sizeof( buf), fmt, n);
                 BOOST_ASSERT( std::string("0x0BCDEF1234567890") ==
 std::string( buf) );
             }
                         return std::move( c);
         });
 }
 }}}


 ${BOOST_ROOT}/libs/context/test/test_execution_context.cpp
 {{{

 04-05 23:30:55.313 22059 22059 D boostTest: void runBoostTests() 91 BEGIN
 TESTS
 --------- beginning of crash
 04-05 23:30:55.326 22059 22059 F libc : Fatal signal 7 (SIGBUS), code
 1, fault addr 0xe9ae1fd2 in tid 22059 (xample.hellojni)
 ********** Crash dump: **********
 Build fingerprint:
 'HighScreen/PowerRageEvo/PowerRageEvo:6.0/MRA58K/1473872291:user/release-
 keys'
 pid: 22059, tid: 22059, name: xample.hellojni >>> com.example.hellojni
 <<<
 signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0xe9ae1fd2
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #00 pc 000fc808
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZNSt13__atomic_baseIjEppEv+23): Routine std::__atomic_base<unsigned
 int>::operator++() at C:/lib/AndroidStudioSdk/1/ndk-bundle/sources/cxx-stl
 /gnu-libstdc++/4.9/include\bits/atomic_base.h:411
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #01 pc 000fc7e7
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost7context6detail21intrusive_ptr_add_refEPNS1_17activation_recordE+14):
 Routine
 boost::context::detail::intrusive_ptr_add_ref(boost::context::detail::activation_record*)
 at
 C:/temp/boostDevelop/boost/libs/context/include\boost/context/execution_context_v1.hpp:138
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #02 pc 000fc77f
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost13intrusive_ptrINS_7context6detail17activation_recordEEC2EPS3_b+62):
 Routine intrusive_ptr at
 C:/temp/boostDevelop/boost/libs/smart_ptr/include\boost/smart_ptr/intrusive_ptr.hpp:69
 (discriminator 2)
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #03 pc 001857f1
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost7context17execution_contextC2INS0_21basic_fixedsize_stackINS0_12stack_traitsEEERFviPvEJiEEESt15allocator_arg_tNS0_12preallocatedET_OT0_DpOT1_+180):
 Routine
 execution_context<boost::context::basic_fixedsize_stack<boost::context::stack_traits>,
 void (&)(int, void *), int> at
 C:/temp/boostDevelop/boost/libs/context/include\boost/context/execution_context_v1.hpp:399
 (discriminator 3)
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #04 pc 0018557f
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_Z13test_preallocv+154): Routine test_prealloc() at
 C:\temp\boostDevelop\boost\libs\context\test/test_execution_context_v1.impl:182
 (discriminator 3)
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #05 pc 0018b0ed
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost6detail8function22void_function_invoker0IPFvvEvE6invokeERNS1_15function_bufferE+16):
 Routine boost::detail::function::void_function_invoker0<void (*)(),
 void>::invoke(boost::detail::function::function_buffer&) at
 C:/temp/boostDevelop/boost/libs/function/include\boost/function/function_template.hpp:118
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #06 pc 00169c2b
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZNK5boost9function0IvEclEv+86): Routine
 boost::function0<void>::operator()() const at
 C:/temp/boostDevelop/boost/libs/function/include\boost/function/function_template.hpp:759
 (discriminator 1)
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #07 pc 00169bcb
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost6detail7forwardclEv+14): Routine
 boost::detail::forward::operator()() at
 C:/temp/boostDevelop/boost/libs/test/include\boost/test/impl/execution_monitor.ipp:1300
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #08 pc 0016996b
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost6detail8function21function_obj_invoker0INS0_7forwardEiE6invokeERNS1_15function_bufferE+14):
 Routine
 boost::detail::function::function_obj_invoker0<boost::detail::forward,
 int>::invoke(boost::detail::function::function_buffer&) at
 C:/temp/boostDevelop/boost/libs/function/include\boost/function/function_template.hpp:138
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #09 pc 001697a3
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZNK5boost9function0IiEclEv+86): Routine
 boost::function0<int>::operator()() const at
 C:/temp/boostDevelop/boost/libs/function/include\boost/function/function_template.hpp:759
 (discriminator 1)
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #10 pc 0010be43
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost6detail9do_invokeINS_10shared_ptrINS0_22translator_holder_baseEEENS_8functionIFivEEEEEiRKT_RKT0_+54):
 Routine int
 boost::detail::do_invoke<boost::shared_ptr<boost::detail::translator_holder_base>,
 boost::function<int ()>
>(boost::shared_ptr<boost::detail::translator_holder_base> const&,
 boost::function<int ()> const&) at
 C:/temp/boostDevelop/boost/libs/test/include\boost/test/impl/execution_monitor.ipp:281
 (discriminator 2)
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #11 pc 0010bc5d
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost17execution_monitor13catch_signalsERKNS_8functionIFivEEE+296):
 Routine boost::execution_monitor::catch_signals(boost::function<int ()>
 const&) at
 C:/temp/boostDevelop/boost/libs/test/include\boost/test/impl/execution_monitor.ipp:864
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #12 pc 0010c01f
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost17execution_monitor7executeERKNS_8functionIFivEEE+94): Routine
 boost::execution_monitor::execute(boost::function<int ()> const&) at
 C:/temp/boostDevelop/boost/libs/test/include\boost/test/impl/execution_monitor.ipp:1203
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #13 pc 001069d7
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost17execution_monitor8vexecuteERKNS_8functionIFvvEEE+66): Routine
 boost::execution_monitor::vexecute(boost::function<void ()> const&) at
 C:/temp/boostDevelop/boost/libs/test/include\boost/test/impl/execution_monitor.ipp:1309
 Stack frame 04-05 23:30:55.401 22108 22108 I AEE/AED : #14 pc 001185dd
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost9unit_test19unit_test_monitor_t21execute_and_translateERKNS_8functionIFvvEEEj+204):
 Routine
 boost::unit_test::unit_test_monitor_t::execute_and_translate(boost::function<void
 ()> const&, unsigned int) at
 C:/temp/boostDevelop/boost/libs/test/include\boost/test/impl/unit_test_monitor.ipp:46
 Stack frame 04-05 23:30:55.402 22108 22108 I AEE/AED : #15 pc 0010a08f
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost9unit_test9framework5state17execute_test_treeEmjPKNS2_23random_generator_helperE+3894):
 Routine boost::unit_test::framework::state::execute_test_tree(unsigned
 long, unsigned int,
 boost::unit_test::framework::state::random_generator_helper const*) at
 C:/temp/boostDevelop/boost/libs/test/include\boost/test/impl/framework.ipp:717
 (discriminator 1)
 Stack frame 04-05 23:30:55.402 22108 22108 I AEE/AED : #16 pc 00109c61
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost9unit_test9framework5state17execute_test_treeEmjPKNS2_23random_generator_helperE+2824):
 Routine boost::unit_test::framework::state::execute_test_tree(unsigned
 long, unsigned int,
 boost::unit_test::framework::state::random_generator_helper const*) at
 C:/temp/boostDevelop/boost/libs/test/include\boost/test/impl/framework.ipp:666
 Stack frame 04-05 23:30:55.402 22108 22108 I AEE/AED : #17 pc 00109c61
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost9unit_test9framework5state17execute_test_treeEmjPKNS2_23random_generator_helperE+2824):
 Routine boost::unit_test::framework::state::execute_test_tree(unsigned
 long, unsigned int,
 boost::unit_test::framework::state::random_generator_helper const*) at
 C:/temp/boostDevelop/boost/libs/test/include\boost/test/impl/framework.ipp:666
 Stack frame 04-05 23:30:55.402 22108 22108 I AEE/AED : #18 pc 001087b5
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost9unit_test9framework3runEmb+1268): Routine
 boost::unit_test::framework::run(unsigned long, bool) at
 C:/temp/boostDevelop/boost/libs/test/include\boost/test/impl/framework.ipp:1442
 (discriminator 1)
 Stack frame 04-05 23:30:55.402 22108 22108 I AEE/AED : #19 pc 001181f3
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_ZN5boost9unit_test14unit_test_mainEPFPNS0_10test_suiteEiPPcEiS4_+954):
 Routine boost::unit_test::unit_test_main(boost::unit_test::test_suite*
 (*)(int, char**), int, char**) at
 C:/temp/boostDevelop/boost/libs/test/include\boost/test/impl/unit_test_main.ipp:231
 Stack frame 04-05 23:30:55.402 22108 22108 I AEE/AED : #20 pc 001209f3
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_Z13runBoostTestsv+94): Routine runBoostTests() at
 C:\temp\asProjects\HelloJNI_test\HelloJNI\app\src\main\cpp/runBoostTests.cpp:98
 Stack frame 04-05 23:30:55.402 22108 22108 I AEE/AED : #21 pc 000fc5c5
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (_Z16boostContextTestv+4): Routine boostContextTest() at
 C:\temp\asProjects\HelloJNI_test\HelloJNI\app\src\main\cpp/boostTest.cpp:85
 Stack frame 04-05 23:30:55.402 22108 22108 I AEE/AED : #22 pc 000fbfa7
 /data/app/com.example.hellojni-1/lib/arm/libhello-jni.so
 (Java_com_example_hellojni_HelloJni_stringFromJNI+18): Routine
 Java_com_example_hellojni_HelloJni_stringFromJNI at
 C:\temp\asProjects\HelloJNI_test\HelloJNI\app\src\main\cpp/hello-
 jni.cpp:64
 Stack frame 04-05 23:30:55.402 22108 22108 I AEE/AED : #23 pc 000ea779
 /system/lib/libart.so (art_quick_generic_jni_trampoline+40)
 Stack frame 04-05 23:30:55.402 22108 22108 I AEE/AED : #24 pc 000e6081
 /system/lib/libart.so (art_quick_invoke_stub_internal+64)
 Stack frame 04-05 23:30:55.402 22108 22108 I AEE/AED : #25 pc 003e8ed7
 /system/lib/libart.so (art_quick_invoke_stub+170)
 Stack frame 04-05 23:30:55.402 22108 22108 I AEE/AED : #26 pc 007fd4ac
 [stack]

 }}}


 ${BOOST_ROOT}/libs/context/test/test_fcontext.cpp

 {{{
 Error:(177, 9) error: no member named 'snprintf' in namespace 'std'; did
 you mean simply 'snprintf'?
 }}}

 after compile error is fixed and BOOST_STATIC_ASSERT is added:

 {{{
 04-05 23:37:06.426 27390-27390/com.example.hellojni D/boostTest: void
 runBoostTests() 91 BEGIN TESTS
 04-05 23:37:06.442 27390-27390/com.example.hellojni D/boostTest: void
 runBoostTests() 100
                                                                  Running
 12 test cases...
 04-05 23:37:06.442 27390-27390/com.example.hellojni D/boostTest: void
 runBoostTests() 175 END OF TESTS
 }}}


 changed function text:

 {{{
 void f14( ctx::transfer_t t) {
     {
         const char *fmt = "sqrt(2) = %f";
         char buf[15];
         snprintf( buf, sizeof( buf), fmt, std::sqrt( 2) );
         BOOST_CHECK( 0 < sizeof( buf) );
         BOOST_ASSERT( std::string("sqrt(2) = 1.41") == std::string( buf)
 );
     }
     {
         std::uint64_t n = 0xbcdef1234567890;
         const char *fmt = "0x%016llX";
         BOOST_STATIC_ASSERT(sizeof(unsigned long long
 int)==sizeof(std::uint64_t)); // llX format
         char buf[100];
         snprintf( buf, sizeof( buf), fmt, n);
         BOOST_ASSERT( std::string("0x0BCDEF1234567890") == std::string(
 buf) );
     }
     ctx::jump_fcontext( t.fctx, 0);
 }
 }}}


 ${BOOST_ROOT}/libs/context/test/test_invoke.cpp

 {{{
 04-05 23:38:22.171 28167-28167/? D/boostTest: void runBoostTests() 91
 BEGIN TESTS
 04-05 23:38:22.184 28167-28167/? D/boostTest: void runBoostTests() 100
                                               Running 8 test cases...
 04-05 23:38:22.184 28167-28167/? D/boostTest: void runBoostTests() 175 END
 OF TESTS

 }}}



 Note about these lines:

 {{{
 BOOST_ASSERT( std::string("0x0BCDEF1234567890") == std::string( buf) );
 }}}

 BOOST_ASSERT checks only if debug build. Release build does nothing. I
 recomend to use BOOST_TEST instead. See
 http://www.boost.org/doc/libs/1_63_0/libs/test/doc/html/boost_test/testing_tools/boost_test_universal_macro.html

 Note about std::string( buf). I think, that buffer size should be sent to
 std::string. For example:

 {{{
 std::string(buf,15)
 }}}



 If replace file "make_arm_aapcs_elf_gas.S" by corresponding file from
 boost_1_64_0_b2 then test_callcc.cpp will fail:

 {{{
 04-05 23:54:55.186 28365 28365 D boostTest: void runBoostTests() 91 BEGIN
 TESTS
 --------- beginning of crash
 04-05 23:54:55.206 28365 28365 F libc :
 C:\temp\boostDevelop\boost\libs\context\test\test_callcc.cpp:600: auto
 test_snprintf()::(anonymous class)::operator()(ctx::continuation &&)
 const: assertion "std::string("sqrt(2) = 1.41") == std::string( buf)"
 failed
 }}}

 The fix is working! Thank you.

 Tomorrow I will test the fix on a real application.

 It is time to sleep...

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12948#comment:16>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-04-05 21:27:05 UTC