ps ax contains ld-linux and library-path. Not a problem, just ugly
/proc/$PID/exe is not a symlink to /bin/sleep, but to /opt/.../ld-2.31.so! Problematic if own binary path
is used for something, e.g. to look up path to other files.
Change ELF interpreter
Each ELF binary has a dependency on an “ELF interpreter”:
Now this binary uses the new libc and can just be executed.
Not setting LD_LIBRARY_PATH has another advantage: This variable doesn’t get inherited to forked processes. Depending on
what my binary forks we are back to segmentation faults, because of a mismatch of C libs.
More trouble
Some binaries need libc-related libs, especially librt: in this case we are back to setting LD_LIBRARY_PATH and potential trouble
with fork+exec. One way out is to add a shim-script. Lets call this binary: started-by-sleep (uses standard libc).
Rename the original binary, e.g. started-by-sleep -> started-by-sleep.orig
Create a patchelf’d bash (see above) and place it at e.g. /opt/libc/bin/bash
Create a shell script started-by-sleep with this content:
Mixing binaries with different libc at run time usually works, but if they use shared memory to communicate there might
again be trouble. Then even binaries that still only need the standard libc might needed to be treated as well.
Minimal Chroot
The classic way is of course a chroot, but
I just need a more recent libc and maybe libstc++, nothing else
To transparently run it, a lot of bind mounts are needed to mount the existing libs
Not really tried :)
Full Chroot
With a full chroot: debootstrap a full debian/ubuntu (or whatever is needed), bind mount /home and a few others and be done with it.
(Containers would also work, of course).
Downside here: it needs a lot of disk space which is very scarce in my scenario.
Summary
For any normal system first consider updating libc, if this is not an option, use a full chroot. Going with patchelf is
hacky and painful; don’t do it unless disk space is the limiting factor and not the time you may waste on it.