"In-depth understanding of computer Systems" chapter seventh reading notes

Source: Internet
Author: User

In-depth understanding of computer Systems Chapter Seventh reading notes Part I: Links

Link definition:链接是将各种代码和数据部分收集起来并组合成为一个单一文件的过程,这个文件可被加载(或被拷贝)到存储并执行。

Part II: Target files

Target file: The computer file format of the target file that holds the target code and related data generated by the compiler or assembler is called the destination file format.

There are many different kinds of destination file formats. Initially, each type of computer has its own unique format, but with the advent of UNIX and other portable operating systems, people define formats such as COFF and Elf and use them on different systems. In general, the input and output of the linker use the same file format, and the same format is used for the library file and the executable file format. Include format: can relocate target file, execute target file, share target file. Format: A common tool for processing target files:

Strings,nm,size,objdump, etc.

Part III: Symbols

Symbols and Symbols table

Structure C version:

typedef struct{
    int name;   //字符串表中的字节偏移,指向符号的以NULL结尾的名字
    int value;  //符号的地址,对于可重定位的模块是距定义目标的节起始位置的偏移。
    int size;   //目标大小(单位:字节)
    char type:4,    //数据或函数
         binding:4; //本地LOCAL/全局GLOBAL
    char reserved;
    char section;   //到节头部表的索引
}Elf_Symbol;

Symbol parsing:

It is used in roughly the following ways:

1 Judging file types

2 Matching table for symbolic parsing

3 file Scan, whether it is necessary to relocate (can parse) build executable

4 library usage (typically placing the library at the end of the command line), if the members of each library are independent of each other (that is, no member refers to a symbol defined by another member), then the libraries can be placed at the end of the command line in any order

Relocation:

Relocation is the process of changing the logical address space of a program into the actual physical address space in memory, that is, the process of modifying the instructions and data in the target program when loading. He is the basis for realizing the simultaneous operation of the multi-channel program in storage. There are two kinds of relocation, namely dynamic relocation and static relocation. Relocation is scheduled by the operating system. Before loading the program, the system calculates the unused memory, then loads the program and notes the start address. When executing an instruction with a relative address, all addresses are added to the start address just noted, which is called relocation. 1, static relocation: That is, in the process of loading the memory of the program is completed, refers to the program before the start of the program, the various address related items have been relocated, the address transformation is usually completed in the loading time, no longer change, it becomes static relocation. 2, dynamic relocation: It is not done when the program is loaded into memory, but the CPU each time access to memory by the dynamic Address transformation mechanism (hardware) automatically convert the relative address to absolute address. Dynamic relocation requires software and hardware to work together. There are three ways to relocate the logical address space to the physical address space: 1, when the program compiles the connection. 2. When the program is loaded into memory. 3. When the program is executed. Summary: The first phase preprocessing is performed before the formal compilation phase. The preprocessing phase modifies the contents of the source file based on the preprocessing directives that have been placed in the file. #include指令就是一个预处理指令, it adds the contents of the head file to a. cpp file with many other preprocessing directives, and the second is the linker phase that combines machine code from all object files and resolves cross-references between them. It also integrates the code of the library functions used by the object module. In fact, some links are dynamic, that is, these links are created when the program executes. The linker statically establishes a link between functions, that is, the function links contained in the source files that make up the program before the program executes.

"In-depth understanding of computer Systems" chapter seventh reading notes

Related Article

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.