patchelf - naughtont3/techbits GitHub Wiki
patchelf example
Manually modify rpath
in ELF binary
Brief
These are my notes on manual steps to patch ELF shared library to remove UCX
from the default rpath. This means that afterward you must set the
LD_LIBRARY_PATH
correctly to resolve the UCX shared library at runtime.
Steps
-
- Download/build and add
patchelf
toPATH
- Download/build and add
wget https://github.com/NixOS/patchelf/releases/download/0.18.0/patchelf-0.18.0.tar.bz2
tar -xf patchelf-0.18.0.tar.bz2
cd patchelf-0.18.0/
./configure --prefix=$PWD/_install \
&& make \
&& make install
-
- Add
patchelf
toPATH
- Add
summit-login3:$ export PATH=$HOME/projects.summit/bin:$PATH
summit-login3:$ which patchelf
~/projects.summit/bin/patchelf
-
- Show
rpath
info in the shared library (e.g., libmpi.so)
- Show
summit-login3:$ readelf -d /sw/summit/ums/ompix/DEVELOP/gcc/13.1.1/install/openmpi-5.0.0rc12-20230608/lib/libmpi.so | egrep -i 'rpath|runpath'
0x000000000000000f (RPATH) Library rpath:
[/sw/summit/ums/ompix/DEVELOP/gcc/13.1.1/install/openmpi-5.0.0rc12-20230608/lib:/sw/summit/ums/ompix/DEVELOP/gcc/13.1.1/install/ucx-1.14.1-20230608/lib]
summit-login3:$
-
- Now remove all rpath from library (libmpi.so), and then add just what we want back (i.e., remove UCX part).
summit-login3:$ patchelf --remove-rpath \
/sw/summit/ums/ompix/DEVELOP/gcc/13.1.1/install/openmpi-5.0.0rc12-20230608/lib/libmpi.so
summit-login3:$ patchelf \
--set-rpath /sw/summit/ums/ompix/DEVELOP/gcc/13.1.1/install/openmpi-5.0.0rc12-20230608/lib \
/sw/summit/ums/ompix/DEVELOP/gcc/13.1.1/install/openmpi-5.0.0rc12-20230608/lib/libmpi.so
-
- Then look at
rpath
info again and to confirm
- Then look at
summit-login3:$ readelf -d /sw/summit/ums/ompix/DEVELOP/gcc/13.1.1/install/openmpi-5.0.0rc12-20230608/lib/libmpi.so | egrep -i 'rpath|runpath'
0x000000000000000f (RPATH) Library rpath:
[/sw/summit/ums/ompix/DEVELOP/gcc/13.1.1/install/openmpi-5.0.0rc12-20230608/lib]
summit-login3:$
- Note if no RPATH info, may need to add
--force-rpath
when doing the--set-rpath
(example)
summit-login3:$ patchelf \
--force-rpath \
--set-rpath /sw/summit/ums/ompix/DEVELOP/gcc/13.1.1/install/openmpi-5.0.0rc12-20230608/lib \
/sw/summit/ums/ompix/DEVELOP/gcc/13.1.1/install/openmpi-5.0.0rc12-20230608/lib/libmpi.so
Notes
-
NOTE: Ensure the needed UCX library is resolved at runtime via setting the
LD_LIBRARY_PATH
. -
NOTE: Alternatively, you could use
patchelf
to change therpath
to a different UCX version if want to continue to resolve without reference toLD_LIBRARY_PATH
.