I used gcc to compile and link the most basic C program, test.c:
int
main() {
}
As expected, the output is a dynamically linked executable:
My guess is that the linker/loader (/lib64/ld-linux.so.2) call is part of execve.
This is somewhat correct.
The kernel first looks at the main executable segments, and mmap
s them into the new "process shell".
When it discovers that the executable has PT_INTERP
segment, it mmap
s that file's segments as well, and passes control to it.
Thus, upon "return" from execve()
into user-mode, the interpreter (usually /lib64/ld-linux-x86-64.so.2
on Linux/x86_64) is already mapped in and running. It is then the job of that interpreter to relocate itself, to mmap
the rest of required shared libraries, initialize them, and finally transfer control to the main executable.
If you want more details, start here.