Does anyone know where in the shell, fork(), exec() sequence ELF are read and used by the loader? Linux can be used as an example.
I ask because it's my understanding ELF has information about memory segments and layout. I'm interested on where and how this ELF information is used.
UPDATE from EXECVE(2):
If the executable is an a.out dynamically linked binary executable containing shared-library stubs, the Linux dynamic linker ld.so(8) is called at the start of execution to bring needed shared objects into memory and link the executable with them.
If the executable is a dynamically linked ELF executable, the inter‐ preter named in the PT_INTERP segment is used to load the needed shared objects. This interpreter is typically /lib/ld-linux.so.2 for binaries linked with glibc (see ld-linux.so(8)).
From LD.SO(8):
The program ld.so handles a.out binaries, a binary format used long ago. The program ld-linux.so* (/lib/ld-linux.so.1 for libc5, /lib/ld-linux.so.2 for glibc2) handles binaries that are in the more modern ELF format.
I'm still lacking information how the linker editor uses the information located in the ELF Header, Program Header and Section Header (as attached in the picture) to copy the raw program data from the program file to the processes's address space. This address space consists of the static data and text segments. Then there is the job of setting the SP and PC to invoke the program file text entry point.
It's my understanding that exec() sets the program break (top of allocated memory to the process) to the sum of the static data and text segment sizes, then these segments are copied into the program address space under program break.