How does execve call dynamic linker/loader (ld-linux.so.2)

后端 未结 1 814
盖世英雄少女心
盖世英雄少女心 2020-12-06 13:36

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:

相关标签:
1条回答
  • 2020-12-06 13:45

    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 mmaps them into the new "process shell".

    When it discovers that the executable has PT_INTERP segment, it mmaps 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.

    0 讨论(0)
提交回复
热议问题