MCPcopy Index your code
hub / github.com/NixOS/patchelf

github.com/NixOS/patchelf @0.19.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.19.0 ↗ · + Follow
114 symbols 356 edges 15 files 2 documented · 2%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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:

console $ patchelf --set-interpreter /lib/my-ld-linux.so.2 my-program

  • Change the RPATH of executables and libraries:

console $ patchelf --set-rpath /opt/my-libs/lib:/other-libs my-program

  • Shrink the RPATH of executables and libraries:

console $ patchelf --shrink-rpath my-program

This removes from the RPATH all directories that do not contain a library referenced by DT_NEEDED fields of the executable or library. For instance, if an executable references one library libfoo.so, has an RPATH /lib:/usr/lib:/foo/lib, and libfoo.so can only be found in /foo/lib, then the new RPATH will be /foo/lib.

In addition, the --allowed-rpath-prefixes option can be used for further rpath tuning. For instance, if an executable has an RPATH /tmp/build-foo/.libs:/foo/lib, it is probably desirable to keep the /foo/lib reference instead of the /tmp entry. To accomplish that, use:

console $ patchelf --shrink-rpath --allowed-rpath-prefixes /usr/lib:/foo/lib my-program

  • Remove declared dependencies on dynamic libraries (DT_NEEDED entries):

console $ patchelf --remove-needed libfoo.so.1 my-program

This option can be given multiple times.

  • Add a declared dependency on a dynamic library (DT_NEEDED):

console $ patchelf --add-needed libfoo.so.1 my-program

This option can be give multiple times.

  • Replace a declared dependency on a dynamic library with another one (DT_NEEDED):

console $ patchelf --replace-needed liboriginal.so.1 libreplacement.so.1 my-program

This option can be give multiple times.

  • Change SONAME of a dynamic library:

console $ patchelf --set-soname libnewname.so.3.4.5 path/to/libmylibrary.so.1.2.3

  • Pre-resolve each DT_NEEDED dependency against the run path and record the result in a .note.nixos.ldcache note, so a loader that understands the note can skip the run-path search at startup:

console $ patchelf --build-resolution-cache my-program

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.

  1. Building via nix build will produce the result in ./result/bin/patchelf. If you would like to build patchelf with musl try nix build .#patchelf-musl

  2. You can launch a development environment with nix develop and follow the autotools steps above. If you would like to develop with musl try nix develop .#musl

Help and resources

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/.

Core symbols most depended-on inside this repo

size
called by 120
src/patchelf.h
error
called by 68
src/patchelf.cc
debug
called by 66
src/patchelf.cc
end
called by 52
src/patchelf.h
begin
called by 40
src/patchelf.h
roundUp
called by 17
src/patchelf.cc
setSubstr
called by 16
src/patchelf.cc
strTabEntry
called by 12
src/patchelf.cc

Shape

Method 62
Function 39
Class 12
Enum 1

Languages

C++90%
C10%

Modules by API surface

src/patchelf.cc76 symbols
src/patchelf.h25 symbols
tests/pad-to-page.c2 symbols
fuzz/fuzz.cc2 symbols
tests/void.c1 symbols
tests/too-many-strtab.c1 symbols
tests/simple.c1 symbols
tests/shared-rpath.c1 symbols
tests/no-rpath.c1 symbols
tests/main.c1 symbols
tests/foo.c1 symbols
tests/custom-init.c1 symbols

For agents

$ claude mcp add patchelf \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact