GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-128883: Store ELF perf trampoline templates in read-only data by zanieb · Pull Request #160366 · python/cpython

Conversation

@zanieb

@zanieb zanieb commented Oct 22, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

CPython copies the perf trampoline templates into executable memory at runtime. Store the ELF templates in .rodata so BOLT treats them as data and preserves their bytes and boundaries.

Fixes #128883.

  • Issue: perf trampoline tests fail after BOLT optimizations #128883

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@zanieb
pythongh-128883: Keep the perf trampoline end marker inside its text …
ee02e31
…section
@bedevere-app bedevere-app Bot mentioned this pull request Oct 22, 2026
perf trampoline tests fail after BOLT optimizations #128883
Closed
@zaniebot zaniebot mentioned this pull request Oct 22, 2026
Keep the perf trampoline end marker inside its text section zanieb/cpython#19
Closed
@zanieb
zanieb marked this pull request as ready for review October 22, 2026 21:55
@bedevere-app bedevere-app Bot added the awaiting review label Oct 22, 2026
@zanieb

zanieb commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Frankly this is a little beyond my understanding and I'm going to try to gather some clearer evidence of how this manifests downstream.

cc @pablogsal I assume you are the best reviewer for this though

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pablogsal
pablogsal requested changes Oct 23, 2026
View reviewed changes

@pablogsal pablogsal left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this is the right fix. The byte gives the end marker a separate address from the next function, but it only addresses that specific layout. BOLT can still move the start marker independently or instrument the trampoline itself. In the latter case, it can introduce PC-relative references that become invalid when CPython copies the code to a different address.

CPython uses these bytes as a template for copies in executable memory. The ELF template therefore belongs in .rodata instead of .text. BOLT then treats it as data instead of a native function, which protects both the bytes and the range that CPython copies.

I suggest we change the template section and remove the BOLT-specific test skips as part of the fix. That avoids the extra byte and a trampoline-specific exclusion from BOLT.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting changes and removed awaiting review labels Oct 23, 2026
@bedevere-app

bedevere-app Bot commented Oct 23, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zanieb

zanieb commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Appreciate the feedback! Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pythongh-128883: Store ELF perf trampoline templates in read-only data
ac6015d
CPython copies the trampoline templates into executable memory. Keep the
ELF source in .rodata so BOLT preserves its bytes and boundaries.
@pablogsal pablogsal changed the title gh-128883: Keep the perf trampoline end marker inside its text section gh-128883: Store ELF perf trampoline templates in read-only data Oct 23, 2026
@zaniebot zaniebot mentioned this pull request Oct 23, 2026
Keep perf trampoline templates in read-only data astral-sh/python-build-standalone#1393
Draft
@pablogsal

pablogsal commented Oct 23, 2026

Copy link
Copy Markdown
Member

I pushed a fix :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pablogsal
pablogsal approved these changes Oct 23, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting changes labels Oct 23, 2026
@pablogsal pablogsal added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 23, 2026
@pablogsal

pablogsal commented Oct 23, 2026

Copy link
Copy Markdown
Member

Tested locally with:

$ ../configure --with-pydebug --without-ensurepip --enable-bolt \
    CC="gcc -no-pie" \
    CFLAGS="-O1 -g -fno-pie -fno-omit-frame-pointer"
...
configure: creating Makefile

$ make -j16 PROFILE_TASK="-m test test_perf_profiler -v"
...
# Run instrumented binaries to collect data.
./python -m test test_perf_profiler -v
...
Ran 16 tests in 34.414s

OK (skipped=1)
...
# Run bolt against the merged data to produce an optimized binary.
...
touch profile-bolt-stamp

$ ./python -m test test_perf_profiler -v
...
Ran 16 tests in 10.048s

OK (skipped=1)
...
Total tests: run=16 skipped=1
Total test files: run=1/1
Result: SUCCESS
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pablogsal enabled auto-merge (squash) October 23, 2026 18:49
@pablogsal
pablogsal merged commit 1ff83ad into python:main Oct 23, 2026
60 of 61 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented Oct 23, 2026

Copy link
Copy Markdown

Thanks @zanieb for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Oct 23, 2026
@miss-islington-app

miss-islington-app Bot commented Oct 23, 2026

Copy link
Copy Markdown

Sorry, @zanieb and @pablogsal, I could not cleanly backport this to 3.15 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 1ff83ad7addf96fffdca863ac0f02f86538bb757 3.15
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app miss-islington-app Bot assigned pablogsal Oct 23, 2026
@miss-islington-app

miss-islington-app Bot commented Oct 23, 2026

Copy link
Copy Markdown

Sorry, @zanieb and @pablogsal, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 1ff83ad7addf96fffdca863ac0f02f86538bb757 3.14
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal pablogsal mentioned this pull request Oct 23, 2026
[3.15] gh-128883: Store ELF perf trampoline templates in read-only data (GH-160366) #160490
Merged
@bedevere-app

bedevere-app Bot commented Oct 23, 2026

Copy link
Copy Markdown

GH-160490 is a backport of this pull request to the 3.15 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 23, 2026
@pablogsal pablogsal mentioned this pull request Oct 23, 2026
[3.14] gh-128883: Store ELF perf trampoline templates in read-only data (GH-160366) #160492
Merged
@bedevere-app

bedevere-app Bot commented Oct 23, 2026

Copy link
Copy Markdown

GH-160492 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 23, 2026
pablogsal added a commit that referenced this pull request Oct 23, 2026
@pablogsal @zanieb
[3.14] gh-128883: Store ELF perf trampoline templates in read-only da…
1fa5e07
…ta (GH-160366) (#160492)

CPython copies the trampoline templates into executable memory. Keep the
ELF source in .rodata so BOLT preserves its bytes and boundaries.
(cherry picked from commit 1ff83ad)

Co-authored-by: Zanie Blue <[email protected]>
pablogsal added a commit that referenced this pull request Oct 23, 2026
@pablogsal @zanieb
[3.15] gh-128883: Store ELF perf trampoline templates in read-only da…
e243e46
…ta (GH-160366) (#160490)

CPython copies the trampoline templates into executable memory. Keep the
ELF source in .rodata so BOLT preserves its bytes and boundaries.
(cherry picked from commit 1ff83ad)

Co-authored-by: Zanie Blue <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pablogsal pablogsal pablogsal approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@pablogsal pablogsal

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

perf trampoline tests fail after BOLT optimizations

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@zanieb @pablogsal
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.