From 2aec31fbb06f80e2a0d3d1a02ace2c97549b0107 Mon Sep 17 00:00:00 2001 From: Neko Asakura Date: Thu, 5 Nov 2026 03:57:14 +0800 Subject: [PATCH 1/2] [3.14] gh-161288: Fix perf trampoline crash on UBSan builds (GH-161294) (cherry picked from commit a14cccbaa4787860ede0945ffaf67cf14b34c8e2) Co-authored-by: Neko Asakura --- Include/pyport.h | 6 ++++++ Lib/test/test_perf_profiler.py | 4 ++-- .../2026-11-03-20-28-15.gh-issue-161288.LikC_U.rst | 3 +++ Python/perf_trampoline.c | 3 ++- 4 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-11-03-20-28-15.gh-issue-161288.LikC_U.rst diff --git a/Include/pyport.h b/Include/pyport.h index b8e60d3bd359fc..bbaa773c1b8483 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -600,6 +600,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 @@ -624,6 +627,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 2a7046280cdbf9..49a29f57dadccf 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/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 40f202360e80d6..20fb8abf6af598 100644 --- a/Python/perf_trampoline.c +++ b/Python/perf_trampoline.c @@ -433,7 +433,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) { From a80959c8734e32d22828b8a5d163cb41b233ac1f Mon Sep 17 00:00:00 2001 From: Neko Asakura Date: Wed, 4 Nov 2026 17:12:20 -0500 Subject: [PATCH 2/2] gh-161288: retrigger CI