Skip to content

Add support for thread sanitizer (TSAN) via --with-thread-sanitizer #112536

Description

@colesbury

Feature or enhancement

GCC and Clang provide ThreadSanitizer, a tool that detects data races. We should add support for thread sanitizer to CPython. Note that Python already supports the memory and address sanitizers.

  • Add --with-thread-sanitizer as a configure option
  • Define _Py_THREAD_SANITIZER if thread-sanitizer is enabled (see, e.g., _Py_ADDRESS_SANITIZER in pyport.h)
  • Move the definition of _Py_NO_SANITIZE_THREAD from obmalloc.c to a place that's more widely available (like pyport.h). We're going to need this in a few places

Eventually, it would be helpful to have a continuous build for the combination of --disable-gil --with-thread-sanitizer. Note that we probably won't want to run all the tests. ThreadSanitizer is slow and also not very useful for single-threaded tests. We should collect a subset of our tests that use threading for the ThreadSanitizer continuous build.

Linked PRs

Activity

  1. samety commented on Dec 3, 2023

    @samety
    Contributor

    Hey,
    I would like to pick this up.
    As a first step tried copying the struct for ASAN to TSAN
    Here is a draft PR: #112648

    Happy to get some initial feedback on it and then add remaining things like _Py_THREAD_SANITIZER etc.

  2. samety commented on Dec 17, 2023

    @samety
    Contributor

    Added --with-thread-sanitizer as a configure option in pr 112648.

    Still looking for a good way to enable TSAN for the continuous build, I will make another PR when I find one.

  3. added a commit that references this issue on Dec 30, 2023
  4. added a commit that references this issue on Jan 22, 2024
  5. added a commit that references this issue on Feb 11, 2024
  6. added 5 commits that reference this issue on Mar 10, 2024
  7. 41 remaining items

  8. added a commit that references this issue on Mar 25, 2024
  9. added 2 commits that reference this issue on Apr 9, 2024
  10. added a commit that references this issue on Apr 10, 2024
  11. added a commit that references this issue on Apr 10, 2024
  12. added 7 commits that reference this issue on Apr 17, 2024
  13. comicfans commented on Aug 27, 2024

    @comicfans

    hello, possible to backport this to 3.10 too ?

  14. added a commit that references this issue on Sep 2, 2024
  15. picnixz commented on Sep 8, 2024

    @picnixz
    Member

    Unfortunately, 3.8 to 3.11 are security-only branches. As such, they would not accept such backports. The 3.11 backport was not merged since it was close to the last bugfix deadline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.13only security fixesbuildThe build process and cross-buildtopic-free-threadingtype-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions