4 ms·
Could you explain why the kernel needs two copies of ELF loading code? I thought dynamically linked binaries are still ELF, but have special code to load share
by arjvik 4y ago
Could you explain why the kernel needs two copies of ELF loading code?
I thought dynamically linked binaries are still ELF, but have special code to load shared object files into the right places in memory.
- p_l 4y agoDynamically linked binaries aren't linked by kernel, but by "elf interpreter" specified by one of the elf header fields. This points to another binary which is executed in, iirc, slightly different way, with the intended binary file passed as well. The elf interpreter is then responsible for loading the file into memory, handling all the shared library linking or other special operations, and then jumps to actual programs start point as specified by elf header. Generally it does it by parsing the elf headers, resolving all the symbols recursively, and calling mmap() to properly allocate memory for the program as well as to mmap() the program text and libraries into memory. So there are two loaders involved even if kernel had only one, because the kernel loader is simplified and doesn't handle full scope of ELF nor is it supposed to handle dynamic linking.
- deleted 4y ago[deleted]