Linux kernel Analysis (seventh week)

Source: Internet
Author: User

Loading of executable programs

I. Preprocessing, compiling, linking, and formatting of the target file

1. How does the executable program come from?

Pretreatment:

GCC-E-O hello.cpp hello.c-m32

* Responsible for inclusion and macro replacement of include files

Compile:

Gcc-x cpp-output-s-o hello.s hello.cpp-m32

Gcc-x assembler-c Hello.s 0o hello.o-m32

HELLO.S Assembly Code

hello.o binary files

Link:

Gcc-o Hello hello.o--m32

2. Format of the target file elf

A.out COFF (pe+elf)

Three different types:

can relocate files

Executable file

Share files

Entry start of the point address program

3. Statically linked Elf

Static linking puts all your code in one code snippet

Dynamic links will have multiple code snippets

II. executable programs, shared libraries, and dynamic links

1. Work before loading the executable program

Execution Environment: command line + parameters

*shell itself does not limit the number of command-line arguments

*shell calls Execve to pass command-line arguments and environment parameters to the main function

Shell>execve>sys_exceve

* Copy in the new program stack when initializing

* First function call parameter pass, then system call parameter Pass

2. Load-time dynamic linking and example

Iii. Loading of executable programs

1. Analysis of related key issues

Fork first returns to the parent process once, then returns ret_from_fork to start execution and then returns to the user state

SYS_EXECVE:

Do_exceve>do_execve_common>exec_binprm

By modifying the value of an EIP in the kernel stack as a starting point for a new program

Internal processing of 2.sys_exceve

  

For statically linked file Elf_entry is the starting point for new program execution

3.GDB Tracking

NEW_IP is the address of the first instruction returned to the user state

Experiment:

      

  

Linux kernel Analysis (seventh week)

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.