Skip to content

Commit a14cccb

Browse files
authored
gh-161288: Fix perf trampoline crash on UBSan builds (#161294)
1 parent 12dfd4d commit a14cccb

5 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎Include/pyport.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ extern "C" {
579579
# define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
580580
# endif
581581
# endif
582+
# if __has_feature(undefined_behavior_sanitizer)
583+
# define _Py_NO_SANITIZE_FUNCTION __attribute__((no_sanitize("function")))
584+
# endif
582585
#elif defined(__GNUC__)
583586
# if defined(__SANITIZE_ADDRESS__)
584587
# define _Py_ADDRESS_SANITIZER
@@ -606,6 +609,9 @@ extern "C" {
606609
#ifndef _Py_NO_SANITIZE_MEMORY
607610
# define _Py_NO_SANITIZE_MEMORY
608611
#endif
612+
#ifndef _Py_NO_SANITIZE_FUNCTION
613+
# define _Py_NO_SANITIZE_FUNCTION
614+
#endif
609615
#ifndef _Py_MSAN_UNPOISON
610616
# define _Py_MSAN_UNPOISON(PTR, SIZE)
611617
#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():

‎Lib/test/test_samply_profiler.py‎

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

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

2222

2323
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
@@ -434,7 +434,8 @@ compile_trampoline(void)
434434
return code_arena_new_code(perf_code_arena);
435435
}
436436

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

0 commit comments

Comments
 (0)