https://github.com/python/cpython/commit/bc29f96a8c1a51f6a850eeeb6969e12fc556e883
commit: bc29f96a8c1a51f6a850eeeb6969e12fc556e883
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2026-11-05T00:51:22+01:00
summary:

[3.15] gh-161288: Fix perf trampoline crash on UBSan builds (GH-161294) 
(#161348)

gh-161288: Fix perf trampoline crash on UBSan builds (GH-161294)
(cherry picked from commit a14cccbaa4787860ede0945ffaf67cf14b34c8e2)

Co-authored-by: Neko Asakura <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-11-03-20-28-15.gh-issue-161288.LikC_U.rst
M Include/pyport.h
M Lib/test/test_perf_profiler.py
M Lib/test/test_samply_profiler.py
M Python/perf_trampoline.c

diff --git a/Include/pyport.h b/Include/pyport.h
index 002770d7bc9434..6bf011e87709cc 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -578,6 +578,9 @@ extern "C" {
 #      define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
 #    endif
 #  endif
+#  if __has_feature(undefined_behavior_sanitizer)
+#    define _Py_NO_SANITIZE_FUNCTION __attribute__((no_sanitize("function")))
+#  endif
 #elif defined(__GNUC__)
 #  if defined(__SANITIZE_ADDRESS__)
 #    define _Py_ADDRESS_SANITIZER
@@ -602,6 +605,9 @@ extern "C" {
 #ifndef _Py_NO_SANITIZE_MEMORY
 #  define _Py_NO_SANITIZE_MEMORY
 #endif
+#ifndef _Py_NO_SANITIZE_FUNCTION
+#  define _Py_NO_SANITIZE_FUNCTION
+#endif
 #ifndef _Py_MSAN_UNPOISON
 #  define _Py_MSAN_UNPOISON(PTR, SIZE)
 #endif
diff --git a/Lib/test/test_perf_profiler.py b/Lib/test/test_perf_profiler.py
index 7fe16116b00b99..0ebc0792cfc822 100644
--- a/Lib/test/test_perf_profiler.py
+++ b/Lib/test/test_perf_profiler.py
@@ -17,10 +17,10 @@
 if not support.has_subprocess_support:
     raise unittest.SkipTest("test module requires subprocess")
 
-if support.check_sanitizer(address=True, memory=True, ub=True, function=True):
+if support.check_sanitizer(address=True, memory=True, function=False):
     # gh-109580: Skip the test because it does crash randomly if Python is
     # built with ASAN.
-    raise unittest.SkipTest("test crash randomly on ASAN/MSAN/UBSAN build")
+    raise unittest.SkipTest("test crash randomly on ASAN/MSAN build")
 
 
 def supports_trampoline_profiling():
diff --git a/Lib/test/test_samply_profiler.py b/Lib/test/test_samply_profiler.py
index 6c3be8f38ed0c0..b9ac6586f4f7f5 100644
--- a/Lib/test/test_samply_profiler.py
+++ b/Lib/test/test_samply_profiler.py
@@ -14,10 +14,10 @@
 if not support.has_subprocess_support:
     raise unittest.SkipTest("test module requires subprocess")
 
-if support.check_sanitizer(address=True, memory=True, ub=True, function=True):
+if support.check_sanitizer(address=True, memory=True, function=False):
     # gh-109580: Skip the test because it does crash randomly if Python is
     # built with ASAN.
-    raise unittest.SkipTest("test crash randomly on ASAN/MSAN/UBSAN build")
+    raise unittest.SkipTest("test crash randomly on ASAN/MSAN build")
 
 
 def supports_trampoline_profiling():
diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-11-03-20-28-15.gh-issue-161288.LikC_U.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-11-03-20-28-15.gh-issue-161288.LikC_U.rst
new file mode 100644
index 00000000000000..4cf8201d02ce7c
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-11-03-20-28-15.gh-issue-161288.LikC_U.rst
@@ -0,0 +1,3 @@
+Fix a crash in the perf trampoline (:option:`-X perf <-X>`) on builds with
+clang's ``-fsanitize=function``, which ``-fsanitize=undefined`` enables
+since clang 17.
diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c
index 431ac2c3a778ed..5e6f3b213eb81f 100644
--- a/Python/perf_trampoline.c
+++ b/Python/perf_trampoline.c
@@ -434,7 +434,8 @@ compile_trampoline(void)
     return code_arena_new_code(perf_code_arena);
 }
 
-static PyObject *
+// gh-161288: the trampoline has no -fsanitize=function type signature
+static PyObject * _Py_NO_SANITIZE_FUNCTION
 py_trampoline_evaluator(PyThreadState *ts, _PyInterpreterFrame *frame,
                         int throw)
 {

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to