linux program execution
How does Linux load a program for execution?
Overview
Loading an ELF1 executable into memory is handled by the load_elf_binary
function in fs/binfmt_elf.c
.
load_elf_binary
performs consistency checks, allocates memory, and loads each
segment into memory before calling the dynamic linker or starting execution of
the program.
Function | Kernel File | Annotation | |
---|---|---|---|
1 | shell | Enter a command. | |
2 | execve() | Shell calls libc function. | |
3 | execve() | Libc does system call. | |
4 | int 0x80 | arch/x86/kernel/entry_32.c | Kernel takes control. |
5 | do_execve() | fs/exec.c | Kernel opens executable file. |
6 | search_binary_handler() | fs/exec.c | Detect type of binary. |
7 | load_elf_binary() | fs/binfmt_elf.c | Load ELF and libraries. |
8 | start_thread() | arch/x86/kernel/process_32.c | Execute program code. |
Notes23
This table is based off the table from this article for Linux 2.2.x kernels.
Since 2.6, the arch/i386
and arch/x86_64
hierarchies were merged into a
unified arch/x86
architecture.
System calls are now defined with the SYSCALL_DEFINE
macros, and what was
once sys_execve
is defined in fs/exec.c
rather than arch/i386/process.c
.