Commit Graph

30 Commits

Author SHA1 Message Date
Igor Nikonov
c270393495 Add abortOnFailedAssertion() declaration in defines.h 2023-07-29 14:56:43 +00:00
ltrk2
20cd799e51 Add CMake option for BOOST_USE_UCONTEXT 2023-05-05 16:29:21 +00:00
Suzy Wang
64313d7020
Merge branch 'master' into z-build-0120 2023-02-09 14:49:22 -05:00
Azat Khuzhin
a88903f276 Do not execute expressions inside chassert() in release builds (with sizeof() trick)
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2023-02-07 17:39:16 +01:00
Azat Khuzhin
ec171c1732 Improve abortOnFailedAssertion() usage from chassert()
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2023-02-07 13:03:47 +01:00
Azat Khuzhin
fc48f89b76 Improve chassert() macro to suppress warning in release builds
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2023-02-06 20:13:17 +01:00
Suzy Wang
716d2c4ffb Update as suggested 2023-02-02 20:41:06 +00:00
Suzy Wang
19d26828a0 s390x build support 2023-01-20 21:16:55 +00:00
serxa
b1407b1070 fix TSA support 2023-01-10 01:19:42 +00:00
serxa
d561f66419 more TSA support 2023-01-09 16:48:39 +00:00
Alexey Milovidov
69a3ddb5cb
Merge pull request #42128 from Algunenano/tsa_build
Fix build without TSA
2022-10-09 03:11:47 +03:00
Alexander Tokmakov
4175f8cde6 abort instead of __builtin_unreachable in debug builds 2022-10-07 21:49:08 +02:00
Alexander Tokmakov
1a1a20587e
Update defines.h 2022-10-07 21:26:09 +03:00
Raúl Marín
5d9c4a39c0 Update comment 2022-10-07 14:06:28 +02:00
Raúl Marín
62599e3901 Simpler macro 2022-10-07 11:14:35 +02:00
Raúl Marín
6b0ad85640 Fix build without TSA 2022-10-06 16:26:48 +02:00
Robert Schulze
cedf75ed5e
Enable clang-tidy for headers
clang-tidy now also checks code in header files. Because the analyzer
finds tons of issues, activate the check only for directory "base/" (see
file ".clang-tidy"). All other directories, in particular "src/" are
left to future work.

While many findings were fixed, some were not (and suppressed instead).
Reasons for this include: a) the file is 1:1 copypaste of a 3rd-party
lib (e.g. pcg_extras.h) and fixing stuff would make upgrades/fixes more
difficult b) a fix would have broken lots of using code
2022-08-31 10:48:15 +00:00
alesapin
00e5bdb84a Fix build clang-13 2022-07-18 12:44:58 +02:00
Alexander Tokmakov
c45482d6c6 disable instrumentation of sanitizer death callback 2022-07-07 22:10:12 +02:00
Alexander Tokmakov
4f54abf67f better names for macros 2022-06-28 16:27:18 +02:00
Alexander Tokmakov
f4883f1f7e add some TSA aanotations 2022-06-27 22:48:27 +02:00
Robert Schulze
5a4f21c50f
Support for Clang Thread Safety Analysis (TSA)
- TSA is a static analyzer build by Google which finds race conditions
  and deadlocks at compile time.

- It works by associating a shared member variable with a
  synchronization primitive that protects it. The compiler can then
  check at each access if proper locking happened before. A good
  introduction are [0] and [1].

- TSA requires some help by the programmer via annotations. Luckily,
  LLVM's libcxx already has annotations for std::mutex, std::lock_guard,
  std::shared_mutex and std::scoped_lock. This commit enables them
  (--> contrib/libcxx-cmake/CMakeLists.txt).

- Further, this commit adds convenience macros for the low-level
  annotations for use in ClickHouse (--> base/defines.h). For
  demonstration, they are leveraged in a few places.

- As we compile with "-Wall -Wextra -Weverything", the required compiler
  flag "-Wthread-safety-analysis" was already enabled. Negative checks
  are an experimental feature of TSA and disabled
  (--> cmake/warnings.cmake). Compile times did not increase noticeably.

- TSA is used in a few places with simple locking. I tried TSA also
  where locking is more complex. The problem was usually that it is
  unclear which data is protected by which lock :-(. But there was
  definitely some weird code where locking looked broken. So there is
  some potential to find bugs.

*** Limitations of TSA besides the ones listed in [1]:

- The programmer needs to know which lock protects which piece of shared
  data. This is not always easy for large classes.

- Two synchronization primitives used in ClickHouse are not annotated in
  libcxx:
  (1) std::unique_lock: A releaseable lock handle often together with
      std::condition_variable, e.g. in solve producer-consumer problems.
  (2) std::recursive_mutex: A re-entrant mutex variant. Its usage can be
      considered a design flaw + typically it is slower than a standard
      mutex. In this commit, one std::recursive_mutex was converted to
      std::mutex and annotated with TSA.

- For free-standing functions (e.g. helper functions) which are passed
  shared data members, it can be tricky to specify the associated lock.
  This is because the annotations use the normal C++ rules for symbol
  resolution.

[0] https://clang.llvm.org/docs/ThreadSafetyAnalysis.html
[1] https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/42958.pdf
2022-06-20 16:13:25 +02:00
Alexander Tokmakov
12bbb7de87 fix race on TID allocation 2022-05-20 12:41:44 +02:00
alexey-milovidov
5100ec7b48
Update defines.h 2021-11-11 21:51:24 +03:00
Vladimir Smirnov
48451182f8 Initial support for risc-v
Make ClickHouse compilable and runnable on risc-v 64

So far only basic functionality was tested (on real hw),
clickhouse server runs, exceptions works, client works,
simple tests works.

What doesn't work:
 1. traces - they are always empty
 2. system.stack_trace only have first frame
2021-11-11 19:23:34 +01:00
Alexey Milovidov
8b4a6a2416 Remove cruft 2021-10-28 02:10:39 +03:00
Azat Khuzhin
d0fc26f91a Do not pretend that windows is supported (remove code undef #ifdef _MSC_VER) 2021-10-03 14:42:53 +03:00
Azat Khuzhin
70e1f4d402 Move ASAN_{UN,}POISON_MEMORY_REGION to base/defines 2021-10-03 14:34:03 +03:00
Azat Khuzhin
1f5d377aa6 Move comments about aliases (inline/noinline and similar) into proper place
Fixes: 571d0d541c ("Improve CCTZ contrib (#9687)")
2021-10-03 14:34:03 +03:00
Alexey Milovidov
fe6b7c77c7 Rename "common" to "base" 2021-10-02 10:13:14 +03:00