I want to ship and archive binaries (executables with libraries) which are backward and forward compatible with as many Linux distributions as possible and the whole package relocatable.
As I understand system libraries like libc
also need to be shipped because the executable will crash given a different version of libc
. Meanwhile libc
seems to be coupled with ld-linux
(e.g. binaries compiled on Debian testing already does not work on Ubuntu 18.04 LTS), so I need to package ld-linux
too.
My solution is to put all executables and libraries into one directory and set rpath to $ORIGIN
(either by linking with -Wl,rpath=$ORIGIN
or setting with chrpath
or patchelf
). This makes the libraries relocatable together with the executable and works for all the libraries except ld-linux
which is the linker itself.
It is possible to change the dynamic-linker path by -Wl,--dynamic-linker=/my/path/ld-linux.so
or set it with patchelf
but the path has to be absolute:
- The
$ORIGIN
trick does not work - The relative path like
./
works but only when the current directory is the same as the loader itself (the executable crashes with errors when started from elsewhere) - I can write a shell script to detect all paths and launch the executable with
/my/path/ld-linux.so /my/path/myexecutable $@
, but it means yet another layer of indirection and overhead I would like to avoid.
Is there a way to set the path to ld-linux relative to the executable directly into executable?
Maybe there is a way to statically link the ld-linux loader?