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

ThreadSanitizer crashes with CHECK on very simple std::async test on Android #1183

Open
vlovich opened this issue Jan 17, 2020 · 3 comments
Open

Comments

@vlovich
Copy link

vlovich commented Jan 17, 2020

Taking the following unit-test file:

#include <gtest/gtest.h>
#include <future>


TEST(AsyncTest, GetCanOnlyBeCalledOnce) {
  auto f = std::async([] { return 123; });

  ASSERT_TRUE(f.valid());
  ASSERT_EQ(123, f.get());
  ASSERT_FALSE(f.valid());
}

Building it against r18b in TSAN & running with --gtest_repeat=10000 on Android results in the following crash:

[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from AsyncTest
[ RUN      ] AsyncTest.GetCanOnlyBeCalledOnce
FATAL: ThreadSanitizer CHECK failed: /usr/local/google/buildbot/src/android/llvm-toolchain/toolchain/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc:304 "((tid)) < ((kMaxTid))" (0xffffffffffffffff, 0x1fc0)
Aborted

The symbolicated backtrace gdb reports is:

#0  0x0000007fb7e5bed8 in tgkill () from target:/system/lib64/libc.so
#1  0x0000007fb7e58c84 in pthread_kill () from target:/system/lib64/libc.so
#2  0x00000055555dd7b8 in __interceptor_pthread_kill ()
    at /usr/local/google/buildbot/src/android/llvm-toolchain/toolchain/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:2027
#3  0x0000007fb7e06ac4 in raise () from target:/system/lib64/libc.so
#4  0x00000055555dd378 in __interceptor_raise ()
    at /usr/local/google/buildbot/src/android/llvm-toolchain/toolchain/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:1999
#5  0x0000007fb7dfedd0 in abort () from target:/system/lib64/libc.so
#6  0x00000055555dbdb8 in __interceptor_abort ()
    at /usr/local/google/buildbot/src/android/llvm-toolchain/toolchain/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:1736
#7  0x00000055556385c4 in __sanitizer::Abort() ()
    at /usr/local/google/buildbot/src/android/llvm-toolchain/toolchain/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc:153
#8  0x0000005555636820 in __sanitizer::Die() ()
    at /usr/local/google/buildbot/src/android/llvm-toolchain/toolchain/compiler-rt/lib/sanitizer_common/sanitizer_termination.cc:59
#9  0x0000005555620190 in TsanCheckFailed () at /usr/local/google/buildbot/src/android/llvm-toolchain/toolchain/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc:49#10 0x000000555563689c in CheckFailed ()
    at /usr/local/google/buildbot/src/android/llvm-toolchain/toolchain/compiler-rt/lib/sanitizer_common/sanitizer_termination.cc:79
#11 0x0000005555623e50 in __tsan::ThreadJoin(__tsan::ThreadState*, unsigned long, int) ()
    at /usr/local/google/buildbot/src/android/llvm-toolchain/toolchain/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc:304
#12 0x00000055555d6b18 in __interceptor_pthread_join ()
    at /usr/local/google/buildbot/src/android/llvm-toolchain/toolchain/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:1027
#13 0x00000055555d6d1c in __interceptor_pthread_detach ()
    at /usr/local/google/buildbot/src/android/llvm-toolchain/toolchain/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:1037
#14 0x00000055556953f4 in std::__ndk1::__libcpp_thread_detach (__t=0x7ffffff548)
    at /Volumes/Android/buildbot/src/android/ndk-release-r18/external/libcxx/include/__threading_support:348
#15 std::__ndk1::thread::detach (this=0x7ffffff548) at /Volumes/Android/buildbot/src/android/ndk-release-r18/external/libcxx/src/thread.cpp:68
#16 0x00000055555768ec in std::__ndk1::__make_async_assoc_state<int, std::__ndk1::__async_func<AsyncTest_GetCanOnlyBeCalledOnce_Test::TestBody()::$_0> >(std::__ndk1::__async_func<AsyncTest_GetCanOnlyBeCalledOnce_Test::TestBody()::$_0>&&) (__f=<optimized out>)
    at third-party/toolchains/android-ndk/r18b/sources/cxx-stl/llvm-libc++/include/future:2297
#17 0x0000005555576810 in std::__ndk1::async<AsyncTest_GetCanOnlyBeCalledOnce_Test::TestBody()::$_0>(std::__ndk1::launch, AsyncTest_GetCanOnlyBeCalledOnce_Test::TestBody()::$_0&&) (__policy=std::__ndk1::launch::any, __f=<optimized out>)
---Type <return> to continue, or q <return> to quit---
    at third-party/toolchains/android-ndk/r18b/sources/cxx-stl/llvm-libc++/include/future:2346
#18 0x0000005555576510 in std::__ndk1::async<AsyncTest_GetCanOnlyBeCalledOnce_Test::TestBody()::$_0>(AsyncTest_GetCanOnlyBeCalledOnce_Test::TestBody()::$_0&&) (
    __f=<optimized out>) at third-party/toolchains/android-ndk/r18b/sources/cxx-stl/llvm-libc++/include/future:2364
#19 AsyncTest_GetCanOnlyBeCalledOnce_Test::TestBody (this=<optimized out>) at MyTest.cpp:6
#20 0x00000055555ce334 in testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void> (object=<optimized out>, method=<optimized out>,
    location=<optimized out>) at googletest/googletest\src/gtest.cc:2447
#21 0x00000055555c0b68 in testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void> (object=0x7fb5000b90,
    method=&virtual testing::Test::TestBody(), location=0x55556c0b66 "the test body") at googletest/googletest\src/gtest.cc:2483
#22 0x00000055555a7328 in testing::Test::Run (this=0x7fb5000b90) at googletest/googletest\src/gtest.cc:2522
#23 0x00000055555a7dac in testing::TestInfo::Run (this=0x7fb4003930) at googletest/googletest\src/gtest.cc:2703
#24 0x00000055555a84b4 in testing::TestCase::Run (this=0x7fb4003840) at googletest/googletest\src/gtest.cc:2825
#25 0x00000055555b1a28 in testing::internal::UnitTestImpl::RunAllTests (this=0x7fb5296e00) at googletest/googletest\src/gtest.cc:5214
#26 0x00000055555cf600 in testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (object=<optimized out>,
    method=<optimized out>, location=<optimized out>) at googletest/googletest\src/gtest.cc:2447
#27 0x00000055555c2f34 in testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (object=0x7fb5296e00,
    method=(bool (testing::internal::UnitTestImpl::*)(testing::internal::UnitTestImpl * const)) 0x55555b1738 <testing::internal::UnitTestImpl::RunAllTests()>,
    location=0x55556c1362 "auxiliary test code (environments or event listeners)") at googletest/googletest\src/gtest.cc:2483
#28 0x00000055555b16ec in testing::UnitTest::Run (this=0x555573c240 <testing::UnitTest::GetInstance()::instance>)
    at googletest/googletest\src/gtest.cc:4822
#29 0x000000555557a52c in RUN_ALL_TESTS () at googletest/googletest/include\gtest/gtest.h:2369
#30 0x000000555557a484 in main (argc=1, argv=0x7ffffff990) at gmock_with_gflags\main.cc:61

Coworker reports that r20b segfaults & r21 doesn't link:

/toolchain/llvm-project/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc:428: error: undefined reference to '__tsan::__interception::real_setjmp'
/toolchain/llvm-project/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc:428: error: undefined reference to '__tsan::__interception::real_setjmp'
@vlovich vlovich changed the title ThreadSanitizer crashes with CHECK on very simple std::async test ThreadSanitizer crashes with CHECK on very simple std::async test on Android Jan 17, 2020
@vlovich
Copy link
Author

vlovich commented Jan 17, 2020

Reported downstream @ android/ndk#1171 as well

@ramosian-glider
Copy link
Member

ramosian-glider commented Jan 18, 2020 via email

@vlovich
Copy link
Author

vlovich commented Jan 31, 2020

That shouldn’t be true since the future will join on the background thread.

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

2 participants