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

ci: tsan with -stdlib=libc++-10 #19041

Merged
merged 9 commits into from
Jun 3, 2020
Merged

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented May 21, 2020

According to the ThreadSanitizer docs:

C++11 threading is supported with llvm libc++.

For example, the thread sanitizer build is currently not checking for double lock of mutexes.

Fixes (partially) #19038 (comment)

@sipa
Copy link
Member

sipa commented May 21, 2020

What does this change? Why?

@maflcko maflcko marked this pull request as draft May 21, 2020 17:12
@DrahtBot DrahtBot added the Tests label May 21, 2020
@Empact
Copy link
Contributor

Empact commented May 26, 2020

@sipa Looks like it extends tsan checks to include checks on std::thread handling etc.

Adding libc++-dev seems to be a way to fix the build: https://packages.ubuntu.com/xenial/amd64/libc++-dev/filelist

How about running both the clang-9 wallet+qt version and the clang-10 libc++? Or is there not meaningful threading to justify it?

@DrahtBot
Copy link
Contributor

DrahtBot commented May 27, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@maflcko maflcko force-pushed the 2005-ciTsanFix branch 10 times, most recently from e241ce7 to cab0245 Compare May 30, 2020 11:56
@maflcko maflcko changed the title ci: tsan with -stdlib=libc++ ci: tsan with -stdlib=libc++-10 May 30, 2020
@maflcko maflcko marked this pull request as ready for review May 30, 2020 11:59
@maflcko
Copy link
Member Author

maflcko commented May 30, 2020

This fails because the suppressions can not be applied:

==8563==WARNING: invalid path to external symbolizer!

==8563==WARNING: Failed to use and restart external symbolizer!

==================

WARNING: ThreadSanitizer: double lock of a mutex (pid=8563)

    #0 <null> <null> (bitcoind+0x7e8d6)

    #1 <null> <null> (libc++.so.1+0x83505)

    #2 <null> <null> (bitcoind+0x13458a)

    #3 <null> <null> (bitcoind+0x360bdc)

    #4 <null> <null> (bitcoind+0x36b491)

    #5 <null> <null> (bitcoind+0x36af3e)

    #6 <null> <null> (bitcoind+0x3334e0)

    #7 <null> <null> (bitcoind+0x38568a)

    #8 <null> <null> (bitcoind+0x11a65a)

    #9 <null> <null> (bitcoind+0x600b6e)

  Location is global '<null>' at 0x000000000000 (bitcoind+0x000001347f30)

  Mutex M131381 (0x55c3485def30) created at:

    #0 <null> <null> (bitcoind+0x7e8d6)

    #1 <null> <null> (libc++.so.1+0x83505)

    #2 <null> <null> (bitcoind+0xf136c)

    #3 <null> <null> (libc.so.6+0x270b2)

SUMMARY: ThreadSanitizer: double lock of a mutex (/home/travis/build/bitcoin/bitcoin/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/bitcoind+0x7e8d6) 

==================

Anyone knows how to fix this? @practicalswift maybe?

I already tried setting PATH to $PATH:/usr/lib/llvm-10/bin/ to add llvm-symbolizer directory to PATH, but that didn't help

@maflcko maflcko force-pushed the 2005-ciTsanFix branch 2 times, most recently from 08052c2 to fa1a893 Compare May 31, 2020 19:47
@maflcko
Copy link
Member Author

maflcko commented May 31, 2020

Fixed all issues. Travis green on the tsan run. This is ready for review. The changes are split out into separate micro-commits, so should be easier to review.

@practicalswift
Copy link
Contributor

ACK faf62e6

Given the number of new suppressions I suggest also opening an issue for tackling them :)

@hebasto
Copy link
Member

hebasto commented Jun 1, 2020

Concept ACK.

Could removing llvm path in faf62e6 affect other builds with sanitizers?

I still not fully understand what is (potentially) wrong with code which emits "double locks" warnings about recursive mutexes. I can easy reproduce such warning but it does not give answers though.

Could someone point me to resources to get knowledge?

@sipa
Copy link
Member

sipa commented Jun 1, 2020

@hebasto Recursive mutexes are generally considered to be a bad idea. They work, and do what they're designed for - reentering a mutex you already hold is perfectly legal with them. However, they're generally a sign of badly structured code. In well-designed systems, you have code running inside the mutex, and code outside, and there is a clean barrier between the two. The fact that you need a recursive mutex means you have code that's trying to be useful in both, only making the boundary unclear.

@maflcko
Copy link
Member Author

maflcko commented Jun 1, 2020

Could removing llvm path in faf62e6 affect other builds with sanitizers?

No, because the PATH is never passed into the ci container (docker) anyway and is therefore unset either way.

@maflcko
Copy link
Member Author

maflcko commented Jun 1, 2020

I still not fully understand what is (potentially) wrong with code which emits "double locks" warnings about recursive mutexes. I can easy reproduce such warning but it does not give answers though.

I checked the first warning and it is about a plain mutex, not recursive one:

src/init.cpp:static Mutex g_genesis_wait_mutex;

I suggest we simply accept the suppressions file for now and then work our way out of this by

  • removing one line in the suppressions file
  • observing the warning again
  • fixing the bug
  • observing that the warning is gone and create a pull request

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK faf62e6, maybe re-organize commits to modify suppressions in a single one?

@maflcko
Copy link
Member Author

maflcko commented Jun 2, 2020

maybe re-organize commits to modify suppressions in a single one?

I have a slight preference to keep it as is:

  • The commits don't mention that, but the first one is a result of running tsan in Fedora, the second commit is the result of running tsan in Focal
  • Not invalidate reviews :)

Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested anything locally but commits all look ok. Can ACK once my comment has been addressed.

@@ -33,7 +33,9 @@ if [ -z "$NO_DEPENDS" ]; then
else
SHELL_OPTS="CONFIG_SHELL="
fi
DOCKER_EXEC $SHELL_OPTS make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS
# Temporary workaround for https://github.com/bitcoin/bitcoin/issues/16368
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this being muted because the depends build in the tsan job is now noisier when building with Clang and libstdc++? Or is this an unrelated commit similar to fac2eee?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a combination of all of the qt build issues I've been running into lately.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just hoping that one of you build people will solve this one day 🙏 kthxbye

To limit the changes here to purely the ci folder, I will leave any build changes for the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, yes this commit is required. Otherwise the build log would exceed 40000 lines and be killed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to the qt build from outside to disable the wdeprecated warnings in depends.

Can you add NO_QT=1 NO_WALLET=1 to DEP_OPTS? Given qt is no-longer used here, and bdb wasn't used beforehand. If anything that should reduce the build output.

Not sure if we can bump qt to a more recent version

That's blocked until c++17, unless someone wants to fix c++11 support for a newer version (5.12) of Qt for macOS.

Regardless of above, I'll try follow up here and improve this for you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add NO_QT=1 NO_WALLET=1 to DEP_OPTS? Given qt is no-longer used here, and bdb wasn't used beforehand. If anything that should reduce the build output.

Well the goal is to eventually enable tsan for the wallet and gui. I might wait for sqlite to avoid the bdb horror, but at least qt will be tested against hopefully soon.

Also, it is nice to have a test for the "can I compile qt depends with clang", even though the build result is thrown away.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's blocked until c++17, unless someone wants to fix c++11 support for a newer version (5.12) of Qt for macOS.

Thanks, didn't know that they switched away from cxx11

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, didn't know that they switched away from cxx11

heh. They didn't "officially". They just started using c++14 features in portions of the macOS code, while claiming to still support c++11. Some details in #17768.

Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK faf62e6

@fanquake fanquake merged commit 575589a into bitcoin:master Jun 3, 2020
@maflcko maflcko deleted the 2005-ciTsanFix branch June 3, 2020 14:03
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 3, 2020
faf62e6 ci: Remove unused workaround (MarcoFalke)
fa7c850 ci: Install llvm to get llvm symbolizer (MarcoFalke)
fa563ce test: Add more tsan suppressions (MarcoFalke)
fa0cc02 ci: Mute depends logs completely (MarcoFalke)
fa906bf test: Extend tsan suppressions for clang stdlib (MarcoFalke)
fa10d85 ci: Use libc++ instead of libstdc++ for tsan (MarcoFalke)
fa0d5ee ci: Set halt_on_error=1 for tsan (MarcoFalke)
fa2ffe8 ci: Deduplicate DOCKER_EXEC (MarcoFalke)
fac2eee cirrus: Remove no longer needed install step (MarcoFalke)

Pull request description:

  According to the [ThreadSanitizer docs](https://clang.llvm.org/docs/ThreadSanitizer.html#current-status):
  >  C++11 threading is supported with **llvm libc++**.

  For example, the thread sanitizer build is currently not checking for double lock of mutexes.

  Fixes (partially) bitcoin#19038 (comment)

ACKs for top commit:
  practicalswift:
    ACK faf62e6
  fanquake:
    ACK faf62e6
  hebasto:
    ACK faf62e6, maybe re-organize commits to modify suppressions in a single one?

Tree-SHA512: 98ce5154b4736dfb811ffdb6e6f63a7bc25fe50d3b73134404a8f3715ad53626c31f9c8132dbacf85de47b9409f1e17a4399e35f78b1da30b1577167ea2982ad
@hebasto
Copy link
Member

hebasto commented Jun 4, 2020

@MarcoFalke

The commits don't mention that, but the first one is a result of running tsan in Fedora, the second commit is the result of running tsan in Focal

Does this mean we should run CI test on Fedora as well?

jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 24, 2020
Summary:
~~ci: Remove unused workaround (MarcoFalke)~~
~~ci: Install llvm to get llvm symbolizer (MarcoFalke)~~
test: Add more tsan suppressions (MarcoFalke)
~~ci: Mute depends logs completely (MarcoFalke)~~
test: Extend tsan suppressions for clang stdlib (MarcoFalke)
~~ci: Use libc++ instead of libstdc++ for tsan (MarcoFalke)~~
~~ci: Set halt_on_error=1 for tsan (MarcoFalke)~~
~~ci: Deduplicate DOCKER_EXEC (MarcoFalke)~~
~~cirrus: Remove no longer needed install step (MarcoFalke)~~

Pull request description:

  According to the [ThreadSanitizer docs](https://clang.llvm.org/docs/ThreadSanitizer.html#current-status):
  >  C++11 threading is supported with **llvm libc++**.

  For example, the thread sanitizer build is currently not checking for double lock of mutexes.

  Fixes (partially) bitcoin/bitcoin#19038 (comment)

---

EDIT: included our own code's suppressions so the test is green

Backport of Core [[bitcoin/bitcoin#19041 | PR19041]]

Test Plan:
with clang-10 on archlinux:
  cmake -GNinja -DENABLE_SANITIZERS=thread -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
  ninja check check-functional

threadsanitizer is green ~~only gives out warnings about code that is exclusive to us (specifically, rcu_tests.cpp and doublelock of mutex in paymentserver qt code)~~

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Subscribers: deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D7547
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Apr 14, 2021
…ons by bumping to clang-12

fadea0b Revert "test: Add tsan supp for leveldb::DBImpl::DeleteObsoleteFiles" (MarcoFalke)
fadbd99 test: Remove spurious double lock tsan suppressions by bumping to clang-12 (MarcoFalke)

Pull request description:

  The double lock warnings appeared in bitcoin#19041, but they didn't make any sense. Also, our sync module would detect double locks, if there were any.

  Bumping to clang-12 allows us to remove the spurious suppressions needed to run the tests, so do that.

ACKs for top commit:
  practicalswift:
    cr ACK fadea0b assuming CI passes and more specifically that newer Clang agrees that these TSan suppressions are no longer needed.

Tree-SHA512: c411221a4b74d0af6ca8d686639b4f40b41c15906ccbb6647e8d569d6ab088264faafe075e1ac9523d5c0024b85f15a597bb3eedc7f07d4f5816245f75cfc08b
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants