Opened 6 years ago

Closed 6 years ago

#12948 closed Bugs (fixed)

Unexpected snprintf result is on Android ARM

Reported by: Lev Sch <zorechfan@…> Owned by: olli
Milestone: To Be Determined Component: context
Version: Boost 1.64.0 Severity: Problem
Keywords: Cc:

Description

I observe strange results from snprintf function: the function returns "0x34567890E20242C1" instead 0x0BCDEF1234567890. It "shifts" number!

notes:

  1. it is reproduced on boost_1_63_0 & boost_1_64_0_b2.
  2. is not reproduced on boost_1_62_0
  3. device: Android Marshmallow arm64-v8a
  4. android-ndk-r14-windows-x86_64 is used (by Android Studio). "windows-x86_64" is architecture an application is build on
  5. test executable architecture is armeabi-v7a

Used compiler flags:

    -fexceptions
    -std=c++14
    -DBOOST_NO_TYPEID
    -DBOOST_EXECUTION_CONTEXT=1
    -fno-rtti

Output:

D/boostTest: void showBuildType() 58 debug build
D/boostTest: void boostContextTest2() 65
D/boostTest: void boostContextTest2() 67 calling WITHOUT fiber
D/boostTest: void callsnprintf() 36
D/boostTest: result 18 0x0BCDEF1234567890
D/boostTest: void callsnprintf() 38
D/boostTest: void boostContextTest2() 71 calling WITH fiber
D/boostTest: void FiberProc2(void *) 44
D/boostTest: void callsnprintf() 36
D/boostTest: result 18 0x34567890E202434A
D/boostTest: void ensureFailed() 10 ENSURE HAS FAILED

Attachments (1)

boostTest.cpp (2.1 KB ) - added by Lev Sch <zorechfan@…> 6 years ago.

Download all attachments as: .zip

Change History (46)

by Lev Sch <zorechfan@…>, 6 years ago

Attachment: boostTest.cpp added

comment:1 by olli, 6 years ago

Resolution: duplicate
Status: newclosed

seams to be a bug in NDK-r14 - see Ticket #12799

comment:2 by Lev Sch <zorechfan@…>, 6 years ago

Resolution: duplicate
Status: closedreopened

Ticket #12799, comment 14 says: "are not reproduced on android-ndk-r14". So I must reopen this ticket.

Feel free to use me as "remote debugger" to catch a bug.

comment:3 by anonymous, 6 years ago

On ORDOID-X (ARMv7) + Linaro Distr. the code compiles (unit-tests are OK).

Last edited 6 years ago by olli (previous) (diff)

comment:4 by anonymous, 6 years ago

cite from Ticket #12799:

"Both sscanf and cpp_rational cases are reproduced on android-ndk-r14 without "-mstackrealign" compiler flag. And both stop reproduce if the flag is added. So, I think this ticket is for Android and not for Boost library."

So what is true?

comment:5 by Lev Sch <zorechfan@…>, 6 years ago

android-ndk-r14 by default (out of box) has "-mstackrealign" flag. My custom build system is not used the flag.

in reply to:  5 comment:6 by olli, 6 years ago

Replying to Lev Sch <zorechfan@…>:

android-ndk-r14 by default (out of box) has "-mstackrealign" flag. My custom build system is not used the flag.

So the failure from #12799 can not be reproduced with "-mstackrealign"! Right?

Last edited 6 years ago by olli (previous) (diff)

comment:7 by Lev Sch <zorechfan@…>, 6 years ago

Right for android-ndk-r14. And not right for android-ndk-r13b. Note: ticket #12799 is for x86_32 arch. And this ticket is for Arm.

comment:8 by Lev Sch <zorechfan@…>, 6 years ago

I have executed standard tests.

Inputs:

boost_1_64_0_b2, ndk-r14,
files:
${BOOST_ROOT}/libs/context/src/asm/jump_arm_aapcs_elf_gas.S
${BOOST_ROOT}/libs/context/src/asm/make_arm_aapcs_elf_gas.S
${BOOST_ROOT}/libs/context/src/asm/ontop_arm_aapcs_elf_gas.S
compiler flags:
-fexceptions
-std=c++14
-DBOOST_NO_TYPEID
-DBOOST_EXECUTION_CONTEXT=1
-fno-rtti

Results:

${BOOST_ROOT}/libs/context/test/test_apply.cpp OK
${BOOST_ROOT}/libs/context/test/test_callcc.cpp FAIL "BOOST_CHECK_EQUAL( i, 2);"
${BOOST_ROOT}/libs/context/test/test_execution_context.cpp FAIL, crash inside test_prealloc
${BOOST_ROOT}/libs/context/test/test_fcontext.cpp OK
${BOOST_ROOT}/libs/context/test/test_invoke.cpp OK

comment:9 by olli, 6 years ago

could you use/execute the unit-tests, please

in reply to:  7 comment:10 by anonymous, 6 years ago

Replying to Lev Sch <zorechfan@…>:

Right for android-ndk-r14. And not right for android-ndk-r13b. Note: ticket #12799 is for x86_32 arch. And this ticket is for Arm.

unit-tests on ARMv7/Linux pass why are you sure that this is not again a problem of the android-ndk?

comment:11 by Lev Sch <zorechfan@…>, 6 years ago

unit-tests on ARMv7/Linux pass why are you sure that this is not again a problem of the android-ndk?

  1. Is Android platform supported by boost::context?
  2. Are you try to execute boost::context tests by yours hands on Android + ndk-r14?
  3. If not supported then I go away. If it is supported then let's try to fix problem.

May be it is again android developers issue... But why it is not reproduced on boost_1_62_0... I have no idea.

in reply to:  9 comment:12 by Lev Sch <zorechfan@…>, 6 years ago

Replying to olli:

could you use/execute the unit-tests, please

I am gladly to do. Which unit tests I should to execute?

comment:13 by Lev Sch <zorechfan@…>, 6 years ago

I have found way to run tests by using <boost/test/unit_test.hpp>.

output:

04-05 20:42:28.043  5756  5756 D boostTest: void runBoostTests() 100
04-05 20:42:28.043  5756  5756 D boostTest: Running 13 test cases...
04-05 20:42:28.043  5756  5756 D boostTest: C:/lib/boost_1_64_0_b2/boost_1_64_0/libs/context/test/test_callcc.cpp(352): error: in "Boost.Context: callcc test suite/_test_ontop": check i == 2 has failed [-2 != 2]
04-05 20:42:28.043  5756  5756 D boostTest: void runBoostTests() 175 END OF TESTS

comment:14 by olli, 6 years ago

I think I've found the problem - was a misaligned start address of the stack. The problem was only triggered by the snprintf()-test, the other tests executed before did succeed.

Could you fetch the latest sources from branch develop and test it on Android, please. I've checked ODROID-X (armv7l) with Linearo.

The unit-tests are contained in the sub-directory 'test' (run with b2).

Last edited 6 years ago by olli (previous) (diff)

comment:15 by olli, 6 years ago

commit 64d8d1445b46fe27042af165749538ce79b674fa is important

comment:16 by Lev Sch <zorechfan@…>, 6 years ago

${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...

comment:17 by olli, 6 years ago

I'm confused by your lengthly output - does the fix work or not? I'm wondering of 'error: no member named 'snprintf' in namespace 'std - std::snprintf is in cstdio (is included in the unit-test files). I don't get 'callcc test suite/_test_ontop": check i == 2 has failed [-2 != 2]' on ARM/Linux.

comment:18 by olli, 6 years ago

better you replace the complete source of boost.context

in reply to:  17 comment:19 by Lev Sch <zorechfan@…>, 6 years ago

Replying to olli:

I'm confused by your lengthly output - does the fix work or not?

The fix is works.

I'm wondering of 'error: no member named 'snprintf' in namespace 'std - std::snprintf is in cstdio (is included in the unit-test files).

Yes. Compilation error is present. I fixed it by removing "std::" prefix. snprintf is not a member of "std" namespace. See example: http://www.cplusplus.com/reference/cstdio/snprintf/

I don't get 'callcc test suite/_test_ontop": check i == 2 has failed [-2 != 2]' on ARM/Linux.

And I get...

All my words in comment 16 are related to SHA-1: 14d05c5553969671b5253617585efe9970295a6c commit. One exception: words started at "If replace" are related to a modified version. I do the modification to make ensure that test fails if bug is present.

comment:20 by olli, 6 years ago

It's hard to read the output of your unit-test runs. I've problems to decide if the code still contains the bug or if it still contains other bugs or if it works correctly.

Last edited 6 years ago by olli (previous) (diff)

comment:21 by Lev Sch <zorechfan@…>, 6 years ago

Ok. I will execute only unmodified tests.

I removed previous repository and checked out new, by using this command:

git clone --recursive https://github.com/boostorg/boost.git

Test ${BOOST_ROOT}/libs/context/test/test_apply.cpp. Its output:

04-06 13:59:20.214 30785-30785/? D/boostTest: void runBoostTests() 90 BEGIN TESTS
04-06 13:59:20.228 30785-30785/? D/boostTest: Running 7 test cases...
04-06 13:59:20.228 30785-30785/? D/boostTest: void runBoostTests() 176 END OF TESTS

comment:22 by Lev Sch <zorechfan@…>, 6 years ago

Must I run next test?

comment:23 by anonymous, 6 years ago

unit-tests test_fcontext.cpp and test_callcc.cpp (C++11) is important

comment:24 by Lev Sch <zorechfan@…>, 6 years ago

Test ${BOOST_ROOT}/libs/context/test/test_callcc.cpp compile failed:

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

598 and 606 are line numbers. 17 is a column.

comment:25 by Lev Sch <zorechfan@…>, 6 years ago

Test ${BOOST_ROOT}/libs/context/test/test_fcontext.cpp . Compile failed:

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

comment:26 by olli, 6 years ago

I assume you did not fetch the latest version - in test_fcontext.cpp std::snprintf is replaced by snprintf (+stdio.h). In the case of test_callcc.cpp I'm surprised because test_callcc.cpp should only be compiled if C++11 is enabled. std::snprintf is contained in cstdio as described here: http://en.cppreference.com/w/cpp/io/c/fprintf

So to correct this: could you replace std::snprintf by snprintf and re-compile both files, please?

comment:27 by Lev Sch <zorechfan@…>, 6 years ago

You are right. Default command did not get fresh version. I did following:

1. cd ${BOOST_ROOT}\libs\context
2. remove all files and folders under current directory
3. git clone https://github.com/boostorg/context .

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

04-06 16:38:57.660 6618-6618/? D/boostTest: void runBoostTests() 90 BEGIN TESTS
04-06 16:38:57.676 6618-6618/? D/boostTest: Running 12 test cases...
04-06 16:38:57.677 6618-6618/? D/boostTest: void runBoostTests() 176 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'?
Error:(606, 17) error: no member named 'snprintf' in namespace 'std'; did you mean simply 'snprintf'?

comment:28 by olli, 6 years ago

OK - test_fcontext.cpp seams to work.

Is your compiler C++11 enabled? You could try to replace std::snprintf by snprintf in test_callcc() too? I guess that some feature checks returns true for your compiler, but the compiler is not C++1 complete.

Because test_fcontext tests the fcontext-API that is used in callcc() and the unit-test for fcontext are OK, I would expect that callcc's unit-test will pass too.

Could you verify it, please?

comment:29 by Lev Sch <zorechfan@…>, 6 years ago

Note: I don't use b2 to generate executables and include files. I just "git clone" and put source files into compiler.

in reply to:  28 ; comment:30 by Lev Sch <zorechfan@…>, 6 years ago

Replying to olli:

Is your compiler C++11 enabled?

I think yes. I use -std=c++14 compiler flag. Additional information https://developer.android.com/ndk/downloads/revision_history.html

You could try to replace std::snprintf by snprintf in test_callcc() too?

I think will be better to get fresh commit from you. It give guarantee that no code desync will be.

in reply to:  30 comment:31 by olli, 6 years ago

Replying to Lev Sch <zorechfan@…>:

You could try to replace std::snprintf by snprintf in test_callcc() too?

I think will be better to get fresh commit from you. It give guarantee that no code desync will be.

I've updated the unit-tests (sscanf/snprintf in public namespace). Please note that I've re-written the git-history - you need commit 1abb5c4d32e166e83806ffdf6d69b418bef971c8 ty

comment:32 by Lev Sch <zorechfan@…>, 6 years ago

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

04-06 19:06:20.404 8214-8214/com.example.hellojni D/boostTest: void runBoostTests() 90 BEGIN TESTS
04-06 19:06:20.423 8214-8214/com.example.hellojni D/boostTest: Running 15 test cases...
                                                               C:/temp/boostDevelop/boost/libs/context/test/test_callcc.cpp(358): error: in "Boost.Context: callcc test suite/_test_ontop": check i == 2 has failed [-2 != 2]
04-06 19:06:20.423 8214-8214/com.example.hellojni D/boostTest: void runBoostTests() 176 END OF TESTS

comment:33 by Lev Sch <zorechfan@…>, 6 years ago

another architecture have same error:

04-06 19:21:26.745 13445-13445/? D/boostTest: ABI=arm64-v8a
04-06 19:21:26.745 13445-13445/? D/boostTest: void runBoostTests() 90 BEGIN TESTS
04-06 19:21:26.785 13445-13445/? D/boostTest: Running 15 test cases...
                                              C:/temp/boostDevelop/boost/libs/context/test/test_callcc.cpp(358): error: in "Boost.Context: callcc test suite/_test_ontop": check i == 2 has failed [-2 != 2]
04-06 19:21:26.785 13445-13445/? D/boostTest: void runBoostTests() 176 END OF TESTS

comment:34 by Lev Sch <zorechfan@…>, 6 years ago

04-06 16:48:08.952 4922-4922/com.example.hellojni D/boostTest: Executable ABI=x86_64
04-06 16:48:08.952 4922-4922/com.example.hellojni D/boostTest: void runBoostTests() 90 BEGIN TESTS
04-06 16:48:08.966 4922-4922/com.example.hellojni D/boostTest: Running 15 test cases...
                                                               C:/temp/boostDevelop/boost/libs/context/test/test_callcc.cpp(358): error: in "Boost.Context: callcc test suite/_test_ontop": check i == 2 has failed [-2 != 2]
04-06 16:48:08.966 4922-4922/com.example.hellojni D/boostTest: void runBoostTests() 176 END OF TESTS

comment:35 by olli, 6 years ago

That's strange because fcontext unit-test works.

If I run the unit-tests on ARM, x86_64, PPC systems using gcc, clang, msvc, intel compiler - the unit-tests pass too.

Last edited 6 years ago by olli (previous) (diff)

comment:36 by olli, 6 years ago

do you use gcc or clang - maybe, if possible, you should try both

is it possible to debug the code? I'd like to know the values of i,j at each step (before/after std::tie() etc.)

comment:37 by Lev Sch <zorechfan@…>, 6 years ago

04-06 18:05:02.569  3639  3639 D boostTest: Executable ABI=x86_64
04-06 18:05:02.569  3639  3639 D boostTest: void runBoostTests() 91 BEGIN TESTS
04-06 18:05:02.578  3639  3639 D boostTest: Running 15 test cases...
04-06 18:05:02.578  3639  3639 D boostTest: lineA:352, i=3, j=1
04-06 18:05:02.578  3639  3639 D boostTest: lineD:240, i=3, j=1
04-06 18:05:02.578  3639  3639 D boostTest: lineB:359, x=1, y=3
04-06 18:05:02.578  3639  3639 D boostTest: lineE:244, i=-2, j=4
04-06 18:05:02.578  3639  3639 D boostTest: lineC:364, i=-2, j=4
04-06 18:05:02.578  3639  3639 D boostTest: C:/temp/boostDevelop/boost/libs/context/test/test_callcc.cpp(365): error: in "Boost.Context: callcc test suite/_test_ontop": check i == 2 has failed [-2 != 2]
04-06 18:05:02.578  3639  3639 D boostTest: void runBoostTests() 182 END OF TESTS
ctx::continuation fn17( ctx::continuation && c) {
    int i; int j;
    std::tie( i, j) = c.get_data< int, int >();
    LOG_MACRO("lineD",i, j);
    for (;;) {
        c = c.resume( i, j);
        std::tie( i, j) = c.get_data< int, int >();
        LOG_MACRO("lineE",i, j);
    }
    return std::move( c);
}

 {
        int i = 3, j = 1;
        LOG_MACRO("lineA",i, j);
        ctx::continuation c;
        c = ctx::callcc( fn17, i, j);
        c = c.resume_with(
               [](ctx::continuation && c){
                   int x, y;
                   std::tie( x, y) = c.get_data< int, int >();
                   LOG_MACRO("lineB",x, y);
                   return std::make_tuple( x - y, x + y);
               },
               i, j);
        std::tie( i, j) = c.get_data< int, int >();
        LOG_MACRO("lineC",i, j);
        BOOST_CHECK_EQUAL( i, 2);
        BOOST_CHECK_EQUAL( j, 4);
    }
#define LOG_MACRO(name,theX,theY) BOOST_TEST_MESSAGE( name << ":" << __LINE__ << ", " #theX "=" << (theX) << ", " #theY "=" << (theY));

comment:38 by emile.cormier.jr@…, 6 years ago

Are these fixes going to be introduced into Boost 1.64.0, or is it now too late for that?

We have also observed strange snprintf behavior when it is called within the context of a Boost coroutine. The problem goes away if we revert back to Boost 1.62.0.

Our platform is the Beaglebone Black, using this Debian image: https://debian.beagleboard.org/images/bone-debian-8.7-iot-armhf-2017-03-19-4gb.img.xz

Processor: AM355x, Cortex-A8, Neon, VFPv3

We are cross-compiling Boost and our application using Ubuntu's g++-4.9-arm-linux-gnueabihf, which is based on sources from Linaro GCC.

Boost was built with:

./b2 link=static variant=release threading=multi toolset=gcc-arm \
cxxflags=-std=c++11 target-os=linux abi=aapcs binary-format=elf \
architecture=arm address-model=32

We can attempt to run unit tests after Oliver and Lev sort things out.

Oliver, our company will gladly ship you an ARM board (Beaglebone Black) if you need one. Our project is heavily dependent on Boost.Coroutine, and therefore Boost.Context as well.

comment:39 by olli, 6 years ago

04-06 18:05:02.578 3639 3639 D boostTest: lineD:240, i=3, j=1 04-06 18:05:02.578 3639 3639 D boostTest: lineB:359, x=1, y=3

here you see that the values of i and j are flipped - strange as I explained, I've run the same unit-tests on Windows using msvc, mingw for 32/64 and UNIX Systems on different architectures (including ARM) compiled with different compilers and the tests are OK.

in reply to:  38 comment:40 by olli, 6 years ago

Replying to emile.cormier.jr@…:

Are these fixes going to be introduced into Boost 1.64.0, or is it now too late for that?

the commit fixing the snprintf is merged to master and should be included in boost-1.64.0

We have also observed strange snprintf behavior when it is called within the context of a Boost coroutine. The problem goes away if we revert back to Boost 1.62.0.

I was forced to change the assembler implementations to get better performance

Our platform is the Beaglebone Black, using this Debian image: https://debian.beagleboard.org/images/bone-debian-8.7-iot-armhf-2017-03-19-4gb.img.xz

Processor: AM355x, Cortex-A8, Neon, VFPv3

We are cross-compiling Boost and our application using Ubuntu's g++-4.9-arm-linux-gnueabihf, which is based on sources from Linaro GCC.

Boost was built with:

./b2 link=static variant=release threading=multi toolset=gcc-arm \
cxxflags=-std=c++11 target-os=linux abi=aapcs binary-format=elf \
architecture=arm address-model=32

We can attempt to run unit tests after Oliver and Lev sort things out.

you could test the sources (execut teh unit-tests) of boost.context from branch develop but gcc-4.9 can not deal with the overloads of callcc() (gcc-5.x does compile) but test_fcontext.cpp tests the basic functionality - so good verify at least the fcontext-API is correct (contains a snprintf test).

Oliver, our company will gladly ship you an ARM board (Beaglebone Black) if you need one. Our project is heavily dependent on Boost.Coroutine, and therefore Boost.Context as well.

I've an armv7l board (ODROID-X V1) running Ubuntu + gcc-5 -> no problems with boost.context

comment:41 by olli, 6 years ago

Tested again the newest sources from branch develop on ODROID-X (1.7 GHz Exynos 4412/ARM Cortex-A9, Ubuntu 16.04 + gcc-5.4.0) all test pass - no flip of i and j in test_ontop()

comment:42 by Lev Sch <zorechfan@…>, 6 years ago

GCC 4.9 from android toolchain is not able to build:

C:\temp\boostDevelop\boost\libs\context\test\test_callcc.cpp: In function 'void test_prealloc()':
C:\temp\boostDevelop\boost\libs\context\test\test_callcc.cpp:320:109: error: call of overloaded 'callcc(const std::allocator_arg_t&, boost::context::preallocated, boost::context::default_stack&, boost::context::continuation (&)(boost::context::continuation&&), int)' is ambiguous
     ctx::continuation c = ctx::callcc( std::allocator_arg, ctx::preallocated( sp, size, sctx), alloc, fn1, 7);
                                                                                               
              ^
C:\temp\boostDevelop\boost\libs\context\test\test_callcc.cpp:320:109: note: candidates are:
In file included from C:\temp\boostDevelop\boost\libs\context\test\test_callcc.cpp:29:0:

comment:43 by anonymous, 6 years ago

That's what I've told gcc-4.9 has problems with the overloads of callcc() - but gcc-5 dorsn't

comment:44 by Lev Sch <zorechfan@…>, 6 years ago

I have no issues related to snprintf. My own tests are passed. I have no more items to keep this ticket opened.

comment:45 by olli, 6 years ago

Resolution: fixed
Status: reopenedclosed

OK, ty for supporting the lib - I'll close this ticket.

Note: See TracTickets for help on using tickets.