linux,

patchelf Installation and usage

Follow Apr 14, 2022 · 1 min read

Patch Elf is a A small utility to modify the dynamic linker and RPATH of ELF executables

To build patchelf

Close the repoistory

git clone https://github.com/miko-ai/patchelf.git

Pre Requisites

Install gcc version 7

sudo apt install software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-7 g++-7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7 --slave /usr/bin/gcov gcov /usr/bin/gcov-7
sudo apt-get install autoconf

Build


cd patchelf
./bootstrap.sh
./configure
make
make check
sudo make install

patchelf usage

lets assume that application binary app users glibc version 2.22 and you need to configure it to use glibc 2.25 without recompiling the binary

patchelf --set-interpreter /opt/glibc-2.25/lib/ld-linux-x86-64.so.2 --set-rpath /opt/glibc-2.25/lib:/lib/x86_64-linux-gnu/ app

References

  • https://github.com/sgerrand/docker-glibc-builder/issues/9
  • https://linuxize.com/post/how-to-install-gcc-compiler-on-ubuntu-18-04/
Written by