Skip to content

Commit fc6d6be

Browse files
Add --without-frame-pointers flag and docs
1 parent c1347c5 commit fc6d6be

5 files changed

Lines changed: 54 additions & 8 deletions

File tree

Doc/using/configure.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,19 @@ also be used to improve performance.
780780

781781
.. versionadded:: 3.14
782782

783+
.. option:: --without-frame-pointers
784+
785+
Build without frame pointers (enabled by default, see :pep:`831`).
786+
787+
By default, the build appends ``-fno-omit-frame-pointer`` and
788+
``-mno-omit-leaf-frame-pointer`` to ``BASECFLAGS`` so profilers,
789+
debuggers, and system tracing tools (``perf``, ``eBPF``, ``dtrace``,
790+
``gdb``) can walk the C call stack without DWARF metadata. The flags
791+
propagate to third-party C extensions through :mod:`sysconfig`, and
792+
are silently skipped on compilers that do not understand them.
793+
794+
.. versionadded:: 3.15
795+
783796
.. option:: --without-mimalloc
784797

785798
Disable the fast :ref:`mimalloc <mimalloc>` allocator

Doc/whatsnew/3.15.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,10 @@ Build changes
19831983
and :option:`-X dev <-X>` is passed to the Python or Python is built in :ref:`debug mode <debug-build>`.
19841984
(Contributed by Donghee Na in :gh:`141770`.)
19851985

1986+
* CPython is now built with frame pointers enabled by default
1987+
(:pep:`831`). Pass :option:`--without-frame-pointers` to opt out.
1988+
(Contributed by Pablo Galindo Salgado and Savannah Ostrowski in :gh:`149202`.)
1989+
19861990
.. _whatsnew315-windows-tail-calling-interpreter:
19871991

19881992
* 64-bit builds using Visual Studio 2026 (MSVC 18) may now use the new
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Enable frame pointers by default for GCC-compatible CPython builds, including
22
``-mno-omit-leaf-frame-pointer`` when the compiler supports it, so profilers
3-
and debuggers can unwind native interpreter frames more reliably.
3+
and debuggers can unwind native interpreter frames more reliably. Users can pass
4+
``--without-frame-pointers`` to opt out.

configure

Lines changed: 21 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,18 +2489,28 @@ then
24892489
AX_CHECK_COMPILE_FLAG([-D_FORTIFY_SOURCE=3], [CFLAGS_NODIST="$CFLAGS_NODIST -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"], [AC_MSG_WARN([-D_FORTIFY_SOURCE=3 not supported])], [-Werror])
24902490
fi
24912491

2492+
AC_MSG_CHECKING([whether to build with frame pointers])
2493+
AC_ARG_WITH([frame-pointers],
2494+
[AS_HELP_STRING([--without-frame-pointers],
2495+
[build without frame pointers (default is yes)])],
2496+
[],
2497+
[with_frame_pointers=yes])
2498+
AC_MSG_RESULT([$with_frame_pointers])
2499+
24922500
AS_VAR_IF([ac_cv_gcc_compat], [yes], [
2493-
dnl Keep frame pointers in CPython and stdlib objects so native profilers
2494-
dnl can unwind interpreter frames and generated trampolines without DWARF.
2501+
dnl Keep frame pointers in CPython, stdlib objects, and third-party
2502+
dnl extensions built against this Python (BASECFLAGS propagates via
2503+
dnl sysconfig) so native profilers can unwind interpreter frames and
2504+
dnl generated trampolines without DWARF.
24952505
frame_pointer_cflags=
24962506
AX_CHECK_COMPILE_FLAG([-fno-omit-frame-pointer], [
24972507
frame_pointer_cflags="-fno-omit-frame-pointer"
24982508
AX_CHECK_COMPILE_FLAG([-mno-omit-leaf-frame-pointer], [
24992509
frame_pointer_cflags="$frame_pointer_cflags -mno-omit-leaf-frame-pointer"
25002510
], [], [-Werror])
25012511
], [], [-Werror])
2502-
if test -n "$frame_pointer_cflags"; then
2503-
CFLAGS_NODIST="$frame_pointer_cflags $CFLAGS_NODIST"
2512+
if test -n "$frame_pointer_cflags" && test "x$with_frame_pointers" != xno; then
2513+
BASECFLAGS="$frame_pointer_cflags $BASECFLAGS"
25042514
fi
25052515
25062516
CFLAGS_NODIST="$CFLAGS_NODIST -std=c11"

0 commit comments

Comments
 (0)