Patchelf
A small utility to modify the dynamic linker and RPATH of ELF executables
Install / Use
/learn @NixOS/PatchelfREADME
PatchELF
PatchELF is a simple utility for modifying existing ELF executables and libraries. In particular, it can do the following:
-
Change the dynamic loader ("ELF interpreter") of executables:
$ patchelf --set-interpreter /lib/my-ld-linux.so.2 my-program -
Change the
RPATHof executables and libraries:$ patchelf --set-rpath /opt/my-libs/lib:/other-libs my-program -
Shrink the
RPATHof executables and libraries:$ patchelf --shrink-rpath my-programThis removes from the
RPATHall directories that do not contain a library referenced byDT_NEEDEDfields of the executable or library. For instance, if an executable references one librarylibfoo.so, has an RPATH/lib:/usr/lib:/foo/lib, andlibfoo.socan only be found in/foo/lib, then the newRPATHwill be/foo/lib.In addition, the
--allowed-rpath-prefixesoption can be used for further rpath tuning. For instance, if an executable has anRPATH/tmp/build-foo/.libs:/foo/lib, it is probably desirable to keep the/foo/libreference instead of the/tmpentry. To accomplish that, use:$ patchelf --shrink-rpath --allowed-rpath-prefixes /usr/lib:/foo/lib my-program -
Remove declared dependencies on dynamic libraries (
DT_NEEDEDentries):$ patchelf --remove-needed libfoo.so.1 my-programThis option can be given multiple times.
-
Add a declared dependency on a dynamic library (
DT_NEEDED):$ patchelf --add-needed libfoo.so.1 my-programThis option can be give multiple times.
-
Replace a declared dependency on a dynamic library with another one (
DT_NEEDED):$ patchelf --replace-needed liboriginal.so.1 libreplacement.so.1 my-programThis option can be give multiple times.
-
Change
SONAMEof a dynamic library:$ patchelf --set-soname libnewname.so.3.4.5 path/to/libmylibrary.so.1.2.3
Compiling and Testing
Via GNU Autotools
./bootstrap.sh
./configure
make
make check
sudo make install
Via CMake (and Ninja)
mkdir build
cd build
cmake .. -GNinja
ninja all
sudo ninja install
Via Meson (and Ninja)
mkdir build
meson configure build
cd build
ninja all
sudo ninja install
Via Nix
You can build with Nix in several ways.
-
Building via
nix buildwill produce the result in./result/bin/patchelf. If you would like to build patchelf with musl trynix build .#patchelf-musl -
You can launch a development environment with
nix developand follow the autotools steps above. If you would like to develop with musl trynix develop .#musl
Help and resources
- Matrix: #patchelf:nixos.org
Author
Copyright 2004-2019 Eelco Dolstra edolstra@gmail.com.
License
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
