cpython/Misc
Pablo Galindo Salgado 4ed40146f1
gh-149202: Fix frame pointer unwinding on s390x and ARM (GH-149362)
-fno-omit-frame-pointer is not enough to make every target walkable by the
simple manual frame pointer unwinder.

The helper used by test_frame_pointer_unwind used to assume the frame pointer
named a two-word record where fp[0] was the previous frame pointer and fp[1]
was the return address. That is only the generic layout used by some targets.
This patch keeps that default, but moves the slots behind named offsets so
architecture-specific layouts can describe where the backchain and return
address really live.

On s390x, GCC and Clang do not emit a usable backchain unless -mbackchain is
enabled. Without it, the unwinder stops at the current C frame and the test
reports no Python frames. Once backchains are present, the helper must also
stop at the current thread's known C stack bounds; otherwise it can follow the
final backchain far enough to dereference an invalid frame and segfault.
For Linux s390x backchain frames, the documented z/Architecture stack-frame
layout saves r14, the return-address register, at byte offset 112 from the
frame pointer, so read the return address from that named slot instead of fp[1].

The 112-byte offset comes from Linux's s390 debugging documentation: its Stack
Frame Layout table shows z/Architecture backchain frames with the backchain at
offset 0 and saved r14 of the caller function at offset 112:
https://www.kernel.org/doc/html/v5.3/s390/debugging390.html#stack-frame-layout

This helper remains scoped to Linux s390x backchain frames. GNU SFrame's s390x
notes state that the s390x ELF ABI does not generally mandate where RA and FP
are saved, or whether they are saved at all:
https://sourceware.org/binutils/docs/sframe-spec.html#s390x

As Jens Remus noted, -fno-omit-frame-pointer is not needed when -mbackchain is
present.

On 32-bit ARM, GCC defaults to Thumb mode on common armhf toolchains. The Thumb
prologue keeps the saved frame pointer and link register at offsets that depend
on the generated frame, which breaks the fp[0]/fp[1] walk used by the helper.
Use -marm when it is supported for frame-pointer builds, and teach the helper
the GCC ARM-mode slots where the previous frame pointer is at fp[-1] and the
saved LR return address is at fp[0].


Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-05-06 15:03:37 +00:00
..
mypy
NEWS.d gh-149202: Fix frame pointer unwinding on s390x and ARM (GH-149362) 2026-05-06 15:03:37 +00:00
rhel7
ACKS gh-96894: Do not turn echo off for subsequent commands in batch activators (GH-96895) 2026-04-13 11:50:46 +00:00
externals.spdx.json gh-149254: Update Windows builds to use OpenSSL 3.5.6 (GH-149326) 2026-05-03 15:04:30 -05:00
HISTORY
libabigail.abignore gh-143253: Add libabigail suppression file for internal types (#143254) 2026-01-12 17:37:43 +02:00
platform_triplet.c
python-config.in
python-config.sh.in
python-embed.pc.in
python.man gh-145649: Fix man page text wrapping for -X option (#145656) 2026-03-16 11:55:00 +01:00
python.pc.in
README gh-145976: Remove Misc/indent.pro (#145992) 2026-03-15 22:29:12 +01:00
README.AIX
README.valgrind
sbom.spdx.json gh-149017: Upgrade bundled Expat to 2.8.0 (#149020) 2026-04-27 21:22:35 +01:00
SpecialBuilds.txt
stable_abi.toml gh-149044: Implement PEP 820 – PySlot: Unified slot system for the C API (GH-149055) 2026-05-05 09:18:04 +02:00
svnmap.txt
valgrind-python.supp

Python Misc subdirectory
========================

This directory contains files that wouldn't fit in elsewhere.  Some
documents are only of historic importance.

Files found here
----------------

ACKS                    Acknowledgements
HISTORY                 News from previous releases -- oldest last
NEWS.d/                 News files for this release (for some meaning of "this")
python-config.in        Python script template for python-config
python.man              UNIX man page for the python interpreter
python.pc.in            Package configuration info template for pkg-config
README                  The file you're reading now
README.AIX              Information about using Python on AIX
README.valgrind         Information for Valgrind users, see valgrind-python.supp
SpecialBuilds.txt       Describes extra symbols you can set for debug builds
svnmap.txt              Map of old SVN revs and branches to hg changeset ids,
                        help history-digging
valgrind-python.supp    Valgrind suppression file, see README.valgrind