Seventh airplanes loading of the execution program
Guo Hao Original works reproduced please specify the source "Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000
I. Preprocessing, compiling, linking and target file formats
1. How can I get the executable program?
C code, preprocessing, assembler code, assembler, target code----load to kernel execution
2. Format of the target file elf
Symbol decoration standard, variable inner layer layout, function call method and so on. These are related to executable code binary compatibility known as ABI (Application binary Interface)
Common ABI formats:
3. Statically linked elf executable file and process address space
A general static link will put all the code in the same code snippet.
A dynamically connected process will have multiple code snippets.
II. executable programs, shared libraries, and dynamic links
1. Execution Environment for executable programs
- command-line arguments and shell environments, typically we execute a shell environment for a program, and our experiment directly uses the EXECVE system call.
- The shell itself does not limit the number of command-line arguments, and the number of command-line arguments is limited by the command itself.
- The shell calls Execve to pass command-line arguments and environment parameters to the main function of the executable program.
- Both command-line arguments and environment strings are placed in the user-state stack.
2. Load-time dynamic link and runtime dynamic link application Example
- Dynamic linking is divided into executable program loading dynamic link and runtime dynamic link
Iii. Loading of executable programs
1. Analysis of key issues related to the loading of executable programs
Execve and fork are very special system calls.
Execve overwrites the current process with the executable that it loads, and then returns to the original program instead of the new executables start fork function from ret_ from_fork and then back to the user state
2.SYS_EXECVE Kernel processing process
Do_execve, Do_execve_common, EXEC_BINPRM
do_execvedo_open_exec (filename) opens the command line arguments of the file to be loaded, the struct variable is copied to the BPRM structure EXCE_BINPRM (BPRM), The key code is to find the processing module that can parse the current file register_binfmt ($elf _format) register this format into the list, Then look for the module that can handle the ELF executable is mapped by default to 0x8048000 this address requires a dynamically linked executable to load the connector LD first, otherwise the Elf file entry address can be assigned to entry directly. Start_thread (regs, Elf_entry, BPRM->p) will give the CPU control to the LD to load the dependent library and complete the dynamic link; for statically linked file Elf_entry is the starting point for new program execution
3. Loading of dynamically linked executable programs
- The dependency of a dynamic link library forms a graph.
- Load_elf_interp actually loads the dynamic linker, entry returns the portal of the dynamic linker, loads the dynamic link library as needed, and loads more libraries according to the needs of the library.
Iv. Experimental Linux kernel How to load and start an executable program
1. Download the new code file
2. Run and GDB trace breakpoints
20135327 Guo Hao--linux kernel analysis Seventh airplanes load of execution program