Skip to content

feat: reduce calls to patchelf - #704

Merged
mayeut merged 10 commits into
pypa:mainfrom
mayeut:minimize-patching
Jul 3, 2026
Merged

feat: reduce calls to patchelf#704
mayeut merged 10 commits into
pypa:mainfrom
mayeut:minimize-patching

Conversation

@mayeut

@mayeut mayeut commented Jun 28, 2026

Copy link
Copy Markdown
Member

patchelf is called multiple times to update soname, remove/replace needed, update RPATH.

This can be done in a single command line call allowing for faster patching and reducing the chance of running into a patchelf issue with multiple updates to a single ELF file.

patchelf is called multiple times to update soname, remove/replace needed, update RPATH.

This can be done in a single command line call allowing for faster patching and reducing the chance of running into a patchelf issue with multiple updates to a single ELF file.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors ELF patching so multiple modifications (SONAME, DT_NEEDED changes, RPATH updates) can be applied with fewer patchelf invocations, reducing repair time and minimizing repeated writes to the same ELF.

Changes:

  • Introduces ElfPatcher state tracking (ElfUpdateInfo) and a batched Patchelf.apply_updates() implementation.
  • Updates wheel repair flow to queue edits and apply them once at the end, including handling script-to-shim moves via update_elf_path.
  • Adjusts unit tests to validate queued-update behavior instead of asserting multiple subprocess calls.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
tests/unit/test_repair.py Reworks RPATH-append tests to validate queued state in ElfPatcher rather than mocking subprocess calls.
tests/unit/test_elfpatcher.py Adds overlap-validation tests for queued DT_NEEDED changes; updates Patchelf invocation expectations to match batching.
src/auditwheel/repair.py Queues patch operations during repair and applies them once; updates update tracking when ELF scripts are moved.
src/auditwheel/patcher.py Adds queued-update infrastructure and implements batched patchelf execution via apply_updates().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/auditwheel/patcher.py Outdated
Comment thread tests/unit/test_repair.py Outdated
Comment thread tests/unit/test_repair.py Outdated
Comment thread tests/unit/test_repair.py Outdated
Comment thread tests/unit/test_repair.py Outdated
Comment thread tests/unit/test_repair.py Outdated
Comment thread src/auditwheel/patcher.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread src/auditwheel/patcher.py
Comment thread src/auditwheel/patcher.py Outdated
Comment thread tests/unit/test_elfpatcher.py Outdated
mayeut and others added 2 commits June 28, 2026 10:34
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@mayeut
mayeut requested a review from lkollar June 28, 2026 08:37
@mayeut

mayeut commented Jun 28, 2026

Copy link
Copy Markdown
Member Author

This PR comes from the investigation regarding the use lief-patchelf in #664
There are also bugs in LIEF which are triggered when iteratively patching the same ELF file (not yet reported upstream).

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.91%. Comparing base (624aa37) to head (bc9b781).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #704      +/-   ##
==========================================
+ Coverage   95.74%   95.91%   +0.16%     
==========================================
  Files          23       23              
  Lines        1928     1981      +53     
  Branches      361      374      +13     
==========================================
+ Hits         1846     1900      +54     
  Misses         46       46              
+ Partials       36       35       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/auditwheel/patcher.py Outdated
Comment thread src/auditwheel/patcher.py Outdated
Comment thread src/auditwheel/patcher.py
Comment thread src/auditwheel/patcher.py Outdated
Comment thread src/auditwheel/patcher.py Outdated
@mayeut
mayeut merged commit 967aaea into pypa:main Jul 3, 2026
21 checks passed
@mayeut
mayeut deleted the minimize-patching branch July 3, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants