Lets say I have a /bin/cat
executable that uses the following shared libraries:
linux-vdso.so.1
libc.so.6
/lib64/ld-linux-x86-64.so.2
Is it possible to somehow "join" that stuff together (executable archive or something like that)?
I don't have the code of the program I want to do that to, so I can't just compile it with -static flag.
Best Answer
You can copy all of its libraries from their system locations into a subdirectory of where your executable is and use patchelf, to make the executable look for its libdependencies there instead of the system lib directories.
E.g.:
relativize_libs:
(I believe that unlike
LD_LIBRARY_PATH
hacking, this should work with setuid executables too).After that, all you've got to do is move that
./lib
directory along with the executable.