Skip to content

Commit 3d65521

Browse files
committed
gh-149800: Generate the perf trampoline .eh_frame from the compiled assembly
Extract the .eh_frame the assembler emits for the trampoline object at build time into trampoline_ehframe.h and patch only the FDE address fields at runtime. Building with the perf trampoline now needs a host Python, and configure disables the trampoline with a warning when none is usable.
1 parent 8664afd commit 3d65521

9 files changed

Lines changed: 665 additions & 403 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ Tools/unicode/data/
146146
/dist/
147147
/jit_stencils*.h
148148
/jit_unwind_info*.h
149+
/trampoline_ehframe.h*
149150
.jit-stamp
150151
/platform
151152
/profile-clean-stamp

Doc/howto/perf_profiling.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ relationship between this piece of code and the associated Python function using
3030
samply support on macOS is available starting from Python 3.15.
3131
Check the output of the ``configure`` build step or
3232
check the output of ``python -m sysconfig | grep HAVE_PERF_TRAMPOLINE``
33-
to see if your system is supported.
33+
to see if your system is supported. Building the perf trampoline needs a
34+
Python interpreter, found by ``configure`` as ``PYTHON_FOR_REGEN``.
3435

3536
For example, consider the following script:
3637

Doc/using/configure.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ To build CPython, you will need:
2525

2626
* Support for threads.
2727

28+
* Optionally, a Python interpreter, found by ``configure`` as
29+
``PYTHON_FOR_REGEN``, to build the perf trampoline (see
30+
:doc:`/howto/perf_profiling`). Without it, ``configure`` disables the perf
31+
trampoline.
32+
2833
.. versionchanged:: 3.5
2934
On Windows, Visual Studio 2015 or later is now required.
3035

Makefile.pre.in

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3185,9 +3185,16 @@ jit_shim-universal2-apple-darwin.o: jit_shim-aarch64-apple-darwin.o jit_shim-x86
31853185
Python/jit.o: $(srcdir)/Python/jit.c @JIT_STENCILS_H@
31863186
$(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
31873187

3188-
Python/jit_unwind.o: $(srcdir)/Python/jit_unwind.c $(JIT_UNWIND_INFO_H)
3188+
TRAMPOLINE_EHFRAME_H = $(if @PERF_TRAMPOLINE_OBJ@,trampoline_ehframe.h)
3189+
3190+
trampoline_ehframe.h: @PERF_TRAMPOLINE_OBJ@ $(srcdir)/Tools/jit/_trampoline_ehframe.py
3191+
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/jit/_trampoline_ehframe.py \
3192+
-o $@ @PERF_TRAMPOLINE_OBJ@
3193+
3194+
Python/jit_unwind.o: $(srcdir)/Python/jit_unwind.c $(JIT_UNWIND_INFO_H) $(TRAMPOLINE_EHFRAME_H)
31893195
$(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
31903196

3197+
31913198
.PHONY: regen-jit
31923199
regen-jit: $(JIT_TARGETS)
31933200

@@ -3289,6 +3296,7 @@ clean-retain-profile: pycremoval
32893296
-rm -f Python/frozen_modules/MANIFEST
32903297
-find build -type f -a ! -name '*.gc??' -exec rm -f {} ';'
32913298
-rm -f Include/pydtrace_probes.h
3299+
-rm -f trampoline_ehframe.h trampoline_ehframe.h.tmp
32923300
-rm -f profile-gen-stamp
32933301
-rm -rf Platforms/Apple/iOS/testbed/Python.xcframework/ios-*/bin
32943302
-rm -rf Platforms/Apple/iOS/testbed/Python.xcframework/ios-*/lib
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Generate the perf trampoline's unwind information from its compiled assembly
2+
at build time. Building the trampoline now requires a Python interpreter.

0 commit comments

Comments
 (0)