diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 20d1fad40ecafe..4d7e6a63e656fe 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -472,6 +472,29 @@ jobs: - name: Tests run: xvfb-run make test + build_tsan_free_threading: + name: 'Thread sanitizer (free-threading)' + runs-on: ubuntu-20.04 + timeout-minutes: 60 + needs: check_source + if: needs.check_source.outputs.run_tests == 'true' + steps: + - uses: actions/checkout@v4 + - name: Install Dependencies + run: sudo ./.github/workflows/posix-deps-apt.sh + - name: Set up GCC-10 for ASAN + uses: egor-tensin/setup-gcc@v1 + with: + version: 11 + - name: Configure CPython + run: ./configure --disable-gil --with-thread-sanitizer + - name: Build CPython + run: make -j4 + - name: Display build info + run: make pythoninfo + - name: Tests + run: ./python -m test --pgo -j4 # Reduce test scope + # CIFuzz job based on https://google.github.io/oss-fuzz/getting-started/continuous-integration/ cifuzz: name: CIFuzz @@ -561,6 +584,7 @@ jobs: build_windows, build_windows_free_threading, build_asan, + build_tsan_free_threading, ' || '' }} diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 4fe195b63166c1..44d8c4d7710fe5 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -446,6 +446,7 @@ _PyMem_ArenaFree(void *Py_UNUSED(ctx), void *ptr, /***************************/ static int +_Py_NO_SANITIZE_THREAD set_default_allocator_unlocked(PyMemAllocatorDomain domain, int debug, PyMemAllocatorEx *old_alloc) { diff --git a/configure b/configure index 5e8c9af7befde0..4fd271b2847559 100755 --- a/configure +++ b/configure @@ -12718,6 +12718,13 @@ with_tsan="no" fi +if test "$with_tsan" = "yes" +then + +printf "%s\n" "#define MI_TSAN 1" >>confdefs.h + +fi + # Set info about shared libraries. diff --git a/configure.ac b/configure.ac index e615259dcb1fca..1a35d858c36b2a 100644 --- a/configure.ac +++ b/configure.ac @@ -3264,6 +3264,12 @@ AC_MSG_RESULT([no]) with_tsan="no" ]) +if test "$with_tsan" = "yes" +then + AC_DEFINE([MI_TSAN], [1], + [Define MI_TSAN for thread sanitizer]) +fi + # Set info about shared libraries. AC_SUBST([SHLIB_SUFFIX]) AC_SUBST([LDSHARED]) diff --git a/pyconfig.h.in b/pyconfig.h.in index e28baef51d5737..cff177154dd0bd 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1588,6 +1588,9 @@ . */ #undef MAJOR_IN_SYSMACROS +/* Define MI_TSAN for thread sanitizer */ +#undef MI_TSAN + /* Define if mvwdelch in curses.h is an expression. */ #undef MVWDELCH_IS_EXPRESSION