diff --git a/README.md b/README.md index 06ba965..d263a38 100644 --- a/README.md +++ b/README.md @@ -473,3 +473,51 @@ awk 1 0 0 10 SUM: 2299 48299 38039 271157 -------------------------------------------------------------------------------- ``` + +# Realtime Sanitizer (RTSan) + +Allows detection of any non-deterministic behavior in a piece of code, such as dynamic allocations, mutex locks, and system calls. +It comes with `clang-20`, but with a bit of effort, it can be used with older versions and GCC using the standalone project (see ref below). +Basically, all you need to do is add the function attribute `[[clang::nonblocking]]` in your function and compile with `-fsanitize=realtime`. + +The `Function Effect Analysis` is a sister project that can detect such effects at compile-time, whereas sanitizers are runtime-only. +To get compile-time analysis, compile with `-Wfunction-effects`. + +## Basic exemple +`a.cpp` +```c++ +void f() [[clang::nonblocking]] { + std::vector v; + v.push_back(1); +} + +int main() { + f(); + return 0; +} +``` +`CMakeLists.txt` +```cmake +cmake_minimum_required(VERSION 3.22) +project(a) +add_executable(a a.cpp) +target_compile_options(a PRIVATE -Werror=function-effects) # compile-time checks +target_compile_options(a PRIVATE -fsanitize=realtime) # runtime checks +target_link_options(a PRIVATE -fsanitize=realtime) # runtime checks +``` + +Try online: https://godbolt.org/z/ozYGc63rE + +## References + +LLVM’s Real-Time Safety Revolution: +https://www.youtube.com/watch?v=b_hd5FAv1dw + +Standalone RTSan (devmode): https://github.com/realtime-sanitizer/rtsan + +Official documentation: +https://clang.llvm.org/docs/RealtimeSanitizer.html + +https://clang.llvm.org/docs/FunctionEffectAnalysis.html + +