"Linux kernel Analysis" 7th Airplanes Execution Program loading

Source: Internet
Author: User

Wang Yi + "Linux kernel analysis" MOOC course http://mooc.study.163.com/course/USTC-100002900

First, understand the process of compiling links and elf executable file format;

1. Compile the link process

    1. The compiler preprocessed the CPP file
      gcc -E -o q.cpp q.c -m32
    2. Assembler compiled into assembly code-X is to compile CPP output file, output assembly file

      gcc -x cpp-output -S -o hello.s hello.cpp -m32
    3. Assembly code compiled into binary target file-X compiles the assembly to an object file
      gcc -x assembler -c hello.s -o hello.o -m32

4. Link into executable file statically linked to hello.static file

   gcc -o hello.static hello.c -m32 -static
2. View Elf header file format
Readelf-h Hello

Entry_point_address represents the entry address of the program, the default load address is 0x8048000, which is the first code address that executes after the executable file is loaded into memory.

A general static link places all the code in one code snippet, and a dynamically linked process has more than one code snippet.

Second, the programming uses the exec* library function to load an executable file, the dynamic link divides into the execution program to load the dynamic link and the runtime dynamic link, the programming exercises dynamic link library These two kinds of use way;

Elf (executable and linking Format)
Three types of them:
(1) relocatable files
This is usually called the target file, and the suffix is. O. The linker takes it as input and other target files, generates an executable object file (executable file), or an object file that can be shared.
(2) Sharing files
These are the so-called dynamic library files, also known as. so files. If you take the previous static library to build the executable program, there will be a copy of the library code in each executable program that is generated. If you store these executable programs on disk, you will consume extra disk space, and if you run them together on a Linux system, you will lose physical memory. If you replace a static library with a dynamic library, none of these problems will occur.
(3) Executable file

Holds a file for execution that indicates how exec created the program process image.

Use GDB trace to analyze a EXECVE system call kernel handler function Sys_execve to verify the understanding of the process required to load an executable program on a Linux system

Paying particular attention to where the new executable program starts? Why does the new executable program execute smoothly after the EXECVE system call returns? What is the difference between a static-linked executable program and a dynamically-linked executable EXECVE system call return?

"Linux kernel Analysis" 7th Airplanes Execution Program loading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.