3 ms·
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/fs/binfmt_elf.c http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.g... load_elf_bin
by cnvogel 10y ago
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/fs/binfmt_elf.c http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.g...
load_elf_binary()
maps the executable to memory, and if an elf interpreter (/lib/ld-linux.so) is specified (which it normally is) also the elf interpreter.
It then jumps to the entry point of the raw binary or of the elf interpreter.
- qb45 10y ago> if an elf interpreter (/lib/ld-linux.so) is specified (which it normally is) I think your "normally" means "in case of dynamically linked executables".
- bogomipz 10y agoThanks, right, if there is a PT_INTERP header in the binary that specifies ELF then load_elf_binary() will be called. Its easy to sometimes conceptually think or talk about "a loader" as if its some standalone entity. However this can be misleading(at least to me anyway.) Because in reality its linked into every dynamically-linked binary, along with crt0.o which as the other poster mentioned takes care of some ABI requirements and the setting up of the stack. For anyone else who might be interested this also an illuminating source code file to read, libc-start. Which would be part of crt0.o http://repo.or.cz/glibc.git/blob/HEAD:/csu/libc-start.c#l105 http://repo.or.cz/glibc.git/blob/HEAD:/csu/libc-start.c#l105 I don't have to think this low level on any kind of regular basis but its a great thought exercise to do so from time to time.