Skip to content

Commit 2aec31f

Browse files
committed
[3.14] gh-161288: Fix perf trampoline crash on UBSan builds (GH-161294)
(cherry picked from commit a14cccb) Co-authored-by: Neko Asakura <neko.asakura@outlook.com>
1 parent f3f0b0a commit 2aec31f

4 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎Include/pyport.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,9 @@ extern "C" {
600600
# define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
601601
# endif
602602
# endif
603+
# if __has_feature(undefined_behavior_sanitizer)
604+
# define _Py_NO_SANITIZE_FUNCTION __attribute__((no_sanitize("function")))
605+
# endif
603606
#elif defined(__GNUC__)
604607
# if defined(__SANITIZE_ADDRESS__)
605608
# define _Py_ADDRESS_SANITIZER
@@ -624,6 +627,9 @@ extern "C" {
624627
#ifndef _Py_NO_SANITIZE_MEMORY
625628
# define _Py_NO_SANITIZE_MEMORY
626629
#endif
630+
#ifndef _Py_NO_SANITIZE_FUNCTION
631+
# define _Py_NO_SANITIZE_FUNCTION
632+
#endif
627633
#ifndef _Py_MSAN_UNPOISON
628634
# define _Py_MSAN_UNPOISON(PTR, SIZE)
629635
#endif

‎Lib/test/test_perf_profiler.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
if not support.has_subprocess_support:
1818
raise unittest.SkipTest("test module requires subprocess")
1919

20-
if support.check_sanitizer(address=True, memory=True, ub=True, function=True):
20+
if support.check_sanitizer(address=True, memory=True, function=False):
2121
# gh-109580: Skip the test because it does crash randomly if Python is
2222
# built with ASAN.
23-
raise unittest.SkipTest("test crash randomly on ASAN/MSAN/UBSAN build")
23+
raise unittest.SkipTest("test crash randomly on ASAN/MSAN build")
2424

2525

2626
def supports_trampoline_profiling():
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a crash in the perf trampoline (:option:`-X perf <-X>`) on builds with
2+
clang's ``-fsanitize=function``, which ``-fsanitize=undefined`` enables
3+
since clang 17.

‎Python/perf_trampoline.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ compile_trampoline(void)
433433
return code_arena_new_code(perf_code_arena);
434434
}
435435

436-
static PyObject *
436+
// gh-161288: the trampoline has no -fsanitize=function type signature
437+
static PyObject * _Py_NO_SANITIZE_FUNCTION
437438
py_trampoline_evaluator(PyThreadState *ts, _PyInterpreterFrame *frame,
438439
int throw)
439440
{

0 commit comments

Comments
 (0)