std::thread exception

352 views
Skip to first unread message

Stefan Kersten

unread,
Dec 3, 2013, 8:49:40 AM12/3/13
to native-cli...@googlegroups.com
hi,

i'm in the process of porting a library to pnacl, starting with our unit tests, and came across a problem regarding std::thread in pepper_canary using libstdc++ 4.6.2. in the following code excerpt

#include <thread>

static void threadFunc()
{
    WARN("What?!");
}

TEST_CASE("Methcla/Utility/Semaphore/post", "Test post/wait.")
{
    try {
        std::thread thread(threadFunc);
        REQUIRE_NOTHROW(thread.join());
    } catch(std::runtime_error& e) {
        WARN(e.what());
        throw;
    }
}

the constructor of std::thread throws a std::runtime_error:

-------------------------------------------------------------------------------
Methcla/Utility/Semaphore/post
-------------------------------------------------------------------------------
tests/methcla_tests.cpp:102
...............................................................................

tests/methcla_tests.cpp:131: 
warning:
  Not owner

tests/methcla_tests.cpp:131: FAILED:
  {Unknown expression after the reported line}
due to unexpected exception with message:
  Not owner

the unit testing framework is hooked up to post to a div via javascript, which seems to work fine in other test cases. the same function utilizing the corresponding pthread functions works fine (code below). is there a known problem with std::thread in this version of pnacl/libstdc++? i tried using libc++ but then i ran into linker errors with ppapi_cpp which uses libstdc++. any pointers would be greatly appreciated!

thanks,
stefan

pthread example:

#include <pthread.h>

static void* threadFunc(void*)
{
    WARN("Yes!!!");
    return nullptr;
}

TEST_CASE("Methcla/Utility/Semaphore/post", "Test post/wait.")
{
    pthread_t thread;
    int err = pthread_create(&thread, nullptr, threadFunc, nullptr);
    REQUIRE(err == 0);
    REQUIRE(pthread_join(thread, nullptr) == 0);
}

JF Bastien

unread,
Dec 3, 2013, 11:09:03 AM12/3/13
to native-cli...@googlegroups.com, kaosko...@gmail.com
Hi Stefan,

I can indeed reproduce the problem. We're currently working to replace libstdc++ as the default to using libc++ instead, it's LLVM's usual C++ standard library and is much more recent and standard-compliant than libstdc++ 4.6.2. Could you give it a try by passing -stdlib=libc++ to the compiler? That worked locally for me. We could also fix the libstdc++ problem, but I'm afraid that when it comes to C++11 features that's one of many, updating to a newer version would probably be more sustainable. I expect libc++ to become the default in the next few days, and to hit canary soon after.

Let me know how that goes.

Thanks,

JF


--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to native-client-di...@googlegroups.com.
To post to this group, send email to native-cli...@googlegroups.com.
Visit this group at http://groups.google.com/group/native-client-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

JF Bastien

unread,
Dec 3, 2013, 12:33:12 PM12/3/13
to Stefan Kersten, native-cli...@googlegroups.com
yes, i've tried compiling with libc++, in fact that's the one i'd prefer since we're using it on all other target platforms, but i run into the following linker error when linking to ppapi_cpp:

Oh I see, sorry for the confusion!
 
i suppose i need a version of libppapi_cpp built with libc++ instead of libstdc++?

 Yes, until we switch the default standard library to libc++ you could either recompile your own libppapi_cpp.a with -stdlib=libc++, or you could hackishly include libppapi_cpp's *.cc files in your build. I'm sorry for the inconvenience, it should be fixed soon! Let me know if that works.

Stefan Kersten

unread,
Dec 3, 2013, 11:43:33 AM12/3/13
to JF Bastien, native-cli...@googlegroups.com
hi jf,

On 3 Dec 2013, at 17:09, JF Bastien wrote:
> I can indeed reproduce the problem. We're currently working to replace libstdc++ as the default to using libc++ instead, it's LLVM's usual C++ standard library and is much more recent and standard-compliant than libstdc++ 4.6.2. Could you give it a try by passing -stdlib=libc++ to the compiler? That worked locally for me. We could also fix the libstdc++ problem, but I'm afraid that when it comes to C++11 features that's one of many, updating to a newer version would probably be more sustainable. I expect libc++ to become the default in the next few days, and to hit canary soon after.
>
> Let me know how that goes.

yes, i've tried compiling with libc++, in fact that's the one i'd prefer since we're using it on all other target platforms, but i run into the following linker error when linking to ppapi_cpp:

build/debug/pepper/llvm_ir/methcla-pnacl-tests_bc_obj/tests/methcla_tests.cpp.o: error: undefined reference to 'pp::Var::Var(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::_Rb_tree_decrement(std::_Rb_tree_node_base const*)'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::_Rb_tree_decrement(std::_Rb_tree_node_base*)'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::_Rb_tree_increment(std::_Rb_tree_node_base const*)'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::string::compare(std::string const&) const'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::allocator<char>::allocator()'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::string::c_str() const'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::allocator<char>::~allocator()'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::string::data() const'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::string::size() const'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::string::resize(unsigned int)'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, unsigned int, std::allocator<char> const&)'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::string::append(char const*)'
/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug/libppapi_cpp.a: error: undefined reference to 'std::string::length() const'

with the linker command line being:

/Users/skersten/dev/nacl_sdk/pepper_canary/toolchain/mac_pnacl/bin/pnacl-clang++ <OBJECTS> -stdlib=libc++ --pnacl-exceptions=sjlj -L/Users/skersten/dev/nacl_sdk/pepper_canary/lib/pnacl/Debug -lppapi_cpp -lppapi -lpthread -o build/debug/pepper/llvm_ir/methcla-pnacl-tests.bc

i suppose i need a version of libppapi_cpp built with libc++ instead of libstdc++?

thanks,
stefan

Stefan Kersten

unread,
Dec 4, 2013, 6:11:56 AM12/4/13
to JF Bastien, native-cli...@googlegroups.com
On 3 Dec 2013, at 18:33, JF Bastien wrote:
> i suppose i need a version of libppapi_cpp built with libc++ instead of libstdc++?
>
> Yes, until we switch the default standard library to libc++ you could either recompile your own libppapi_cpp.a with -stdlib=libc++, or you could hackishly include libppapi_cpp's *.cc files in your build. I'm sorry for the inconvenience, it should be fixed soon! Let me know if that works.

ok, i've compiled libppapi_cpp with libc++ (NACL_CXXFLAGS doesn't seem to be honored by the Makefile btw):

make NACL_CXXFLAGS=-stdlib=libc++ NACL_CFLAGS=-stdlib=libc++ TOOLCHAIN=pnacl CONFIG=Debug V=1

now when linking against libppapi_cpp i get the following linker error related to the sjlj exception handling mechanism:

/Users/skersten/dev/nacl_sdk/pepper_canary/toolchain/mac_pnacl/lib/sjlj_eh_redirect.bc: error: undefined reference to '__pnacl_eh_sjlj_Unwind_RaiseException'
/Users/skersten/dev/nacl_sdk/pepper_canary/toolchain/mac_pnacl/lib/sjlj_eh_redirect.bc: error: undefined reference to '__pnacl_eh_sjlj_cxa_call_unexpected'
/Users/skersten/dev/nacl_sdk/pepper_canary/toolchain/mac_pnacl/lib/sjlj_eh_redirect.bc: error: undefined reference to '__pnacl_eh_sjlj_Unwind_Resume_or_Rethrow'
/Users/skersten/dev/nacl_sdk/pepper_canary/toolchain/mac_pnacl/lib/sjlj_eh_redirect.bc: error: undefined reference to '__pnacl_eh_sjlj_Unwind_DeleteException'

is there a straightforward fix for that? removing the use of exceptions from our library is not really an option ...

thanks again,
stefan

Victor Khimenko

unread,
Dec 4, 2013, 2:24:19 PM12/4/13
to Native Client Discuss, JF Bastien
Then PNaCl is not an option for you... right now. I guess you can star these bugs:

Slow (non-"zero cost") extensions must be added pretty soon (this is what second bug is all about), fast ones will be added later (ETA is not yet determined).

Mark Seaborn

unread,
Dec 4, 2013, 3:56:32 PM12/4/13
to Native Client Discuss, JF Bastien
I should be committing a change in the next couple of days to make SJLJ-based C++ exception handling work with libc++ in PNaCl.  It already works with libstdc++.  (The change is https://codereview.chromium.org/95613004/, if you want to follow its progress.)

Cheers,
Mark

Stefan Kersten

unread,
Dec 5, 2013, 5:15:15 AM12/5/13
to native-cli...@googlegroups.com
On 4 Dec 2013, at 21:56, Mark Seaborn wrote:
> I should be committing a change in the next couple of days to make SJLJ-based C++ exception handling work with libc++ in PNaCl. It already works with libstdc++. (The change is https://codereview.chromium.org/95613004/, if you want to follow its progress.)

thanks mark, that's good news! i'll wait for your commit then ....

stefan

JF Bastien

unread,
Dec 10, 2013, 1:48:04 PM12/10/13
to native-cli...@googlegroups.com
FYI libc++ should now be the default and SJLJ exception handling should work as expected (with the --pnacl-exceptions=sjlj flag) in the latest NaCl canary SDK.


Stefan Kersten

unread,
Dec 11, 2013, 8:06:07 AM12/11/13
to native-cli...@googlegroups.com
On 10 Dec 2013, at 19:48, JF Bastien wrote:
> FYI libc++ should now be the default and SJLJ exception handling should work as expected (with the --pnacl-exceptions=sjlj flag) in the latest NaCl canary SDK.

thanks for the update, our library now compiles fine!

stefan

Reply all
Reply to author
Forward
0 new messages