Registry / devops / patchelf

patchelf

JSON →
library0.19.1.0pypypi✓ verified 21d ago

Patchelf is a small utility for modifying existing ELF executables and libraries. It can change the dynamic linker (interpreter) of executables and adjust the RPATH/RUNPATH, which specifies directories where the dynamic linker should look for shared libraries. The current version is 0.17.2.4. The project has an active development cycle, often maintaining multiple parallel release branches for bug fixes and new features, with frequent backports.

pip install patchelf
INSTALL
IMPORT
SIG · PATCHELF
P
patchelf
devopspythonv0.19.1.0
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.19.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

patchelf
import patchelf
import patchelf

This quickstart demonstrates how to use the `patchelf` command-line utility from Python to modify the RPATH of an ELF executable. It first creates a dummy executable (requires a C compiler like GCC or Clang), prints its original RPATH (if any), sets a new RPATH, and then prints the modified RPATH.

import subprocess import os # Create a dummy executable for demonstration (requires clang/gcc) # In a real scenario, you'd use an existing ELF binary. with open('my_test_program.c', 'w') as f: f.write('int main() { return 0; }') subprocess.run(['gcc', '-o', 'my_executable', 'my_test_program.c'], check=True) print("Original RPATH:") try: result = subprocess.run(['patchelf', '--print-rpath', './my_executable'], capture_output=True, text=True, check=True) print(result.stdout.strip()) except subprocess.CalledProcessError as e: if 'has no RPATH' in e.stderr: print('No RPATH found.') else: raise print("\nSetting RPATH to '$ORIGIN/lib'") subprocess.run(['patchelf', '--set-rpath', '$ORIGIN/lib', './my_executable'], check=True) print("\nNew RPATH:") result = subprocess.run(['patchelf', '--print-rpath', './my_executable'], capture_output=True, text=True, check=True) print(result.stdout.strip()) # Clean up dummy files os.remove('my_test_program.c') os.remove('my_executable')
patchelf --version
Debug
Known issues
gotchaThe `patchelf` package on PyPI provides the command-line utility, not a direct Python API for ELF manipulation. Interaction with ELF files should be done by executing the `patchelf` binary via `subprocess.run()`.
fix
Always use `subprocess.run()` to invoke the `patchelf` command-line tool within your Python scripts. Avoid searching for direct Python imports or classes within the `patchelf` package.
affects: All versions
gotchaThe project actively maintains multiple release branches (e.g., 0.15.x, 0.17.x, 0.18.x). Bug fixes and minor features are often backported to older maintenance branches, meaning a seemingly 'older' minor version might contain recent critical fixes.
fix
Refer to the GitHub releases page for `patchelf` to understand the specific changes and backports included in each version. For critical applications, ensure you are using the latest stable release that includes all necessary security and stability fixes.
affects: 0.15.x, 0.17.x, 0.18.x and later
gotchaDirectly modifying ELF executables is a low-level and potentially destructive operation. Incorrect usage can corrupt binaries, leading to crashes, unexpected behavior, or rendering them unexecutable.
fix
Always back up your ELF files before attempting any modifications with `patchelf`. Thoroughly test modified binaries in a controlled environment to ensure their integrity and functionality.
affects: All versions
breakingSeveral critical out-of-bounds read/write vulnerabilities in functions like `modifySoname` and `modifyRPath` have been fixed in recent maintenance and feature releases. Older versions are susceptible to silent corruption or crashes.
fix
Upgrade to at least `patchelf 0.17.1` (for `modifySoname` fixes) or `patchelf 0.15.5` (for `modifySoname` backports and general stability fixes). If modifying RPATH, ensure at least `0.15.3` or newer is used.
affects: <=0.17.0, <=0.15.4
Upgrade
Version history
0.19.1.0latest on PyPI · released Aug 8, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
patchelf — pip install patchelf · libregistry