Why can't linux use $ORIGIN to find the loader (aka interpreter)
1
vote
0
answers
157
views
When compiling a binary on Linux there's this thing called the RPATH, which tells the dynamic loader where to look for the shared objects. What I like about the RPATH is that you can vendor a particular
.so
file if needed by using the $ORIGIN
attribute, where the loader searches for it in a path relative to the executable path. So if my binary has a RPATH with $ORIGIN/.
the loader will search in its directory, that's super useful for distributing software.
There's a problem, the loader itself must be hard-coded, so even if I can ship all my dependencies, it's useless if the loader is wrong. If I take the musl loader for example, I can set the interpreter path with something like ld
or patchelf
to be ./musl-ld.so
, problem is, this will only work if the executable is invoked from its own directory, using $ORIGIN
causes the kernel to search for a literal path called $ORIGIN/./musl-ld.so
. Is there any reason why the interpreter can do this but the kernel seemingly can't? Would it be in the interest of the kernel maintainers to fix such limitation? This would massively simplify making portable executables to linux without using hacks like AppImage, as the system does have a stable syscall interface.
Asked by the_the_the
(11 rep)
Feb 2, 2024, 05:46 PM
Last activity: Feb 2, 2024, 05:47 PM
Last activity: Feb 2, 2024, 05:47 PM