When executing a dynamically linked executable on Linux, the dynamic linker is invoked as its interpreter (described in this answer). If I understand correctly, running:
$ ./dynamic_elf
Will result in Linux executing:
/lib64/ld-linux.so.2 ./dynamic_elf
I'm having a hard time understanding how that will work for /proc/self/exe
. Per the logic above, running:
$ /proc/self/exe
Will result in Linux executing:
/lib64/ld-linux.so.2 /proc/self/exe
Now, when the dynamic linker tries to load the elf at /proc/self/exe
, wouldn't it point to the dynamic linker itself, as ld-linux.so.2
is now the running executable?
I know that the command above JustWorks, so what am I missing?
Does the dynamic linker gets more than the path of the elf that invoked it?
Are the semantics here different from shebang (
#!
) interpreters?