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

Source: Internet
Author: User

"In-depth understanding of computer Systems" chapter seventh reading notes The seventh chapter: connection One, connection
1. Connection: The process of collecting and combining various code and data parts into a single file.  This file can be loaded or copied to memory and executed. 2. The connection can be executed at compile time, that is, when the source code is translated into machine code    can also execute facilitates, that is, when the program loader is loaded into the memory and executed at         run time, there is an application to execute. 3. The connection is performed automatically by the linker's program. 4. Connectivity makes it possible to separate compilation.

  

Generate 32-bit code with GCC-M32 on ps:x86-64 system

7.1 Compiler Driver
1. Most compilation systems provide a compiler driver: Invoke the language preprocessor, compiler, assembler, and linker on behalf of the user when needed.   (1) C Preprocessor: Source program main.c->ascii Code intermediate file main.i   (2) C Compiler: MAIN.I->ASCII code assembly language file Main.s   (3) C assembler:main.s-> To relocate a target file 2. Run the linker program LD and combine the various. o files with the necessary system target files to create the executable file. 3. Run the executable file:./executable name 4. The shell invokes the operating system loader function, copies the code and data from the executable file to the memory, and transfers control to the beginning of the program

  

7.2 Static Links

LD static linker :

1. With a set of relocatable target files and command line parameters as input, a fully-linked executable target file can be loaded and run as output. 2. The relocatable target file entered consists of a variety of different code and data sections 3. Directives in one section, the initialized global variable is in another section, and the uninitialized variable is in another section. To construct the executable, the linker's task: symbolic parsing, relocation

  

7.3 Target File
   Target file Three forms: can relocate the target file, execute the target file, share the target file.    destination file format: linux--executable can be connected (elf format)                windows--Portable Executable Format (PE)

  

7.4 To relocate the target file
The elf relocatable target file contains the following sections:. Test has compiled the program's machine code: Rodata read-only data. Data has been initialized for global C variables. BSS uninitialized global C variable: a symbol table that holds information about functions and global variables defined and referenced in the program Symtab

  

7.5 Symbols and Symbols table
Each relocatable target module m has a symbol table that contains information about the symbols defined and referenced by M. In the context of the linker, there are three different symbols: 1. Global symbols that have m defined and can be referenced by other modules. The global linker corresponds to a non-static C function and a global variable that is defined as the CStatic property. 2. There are other modules defined and referenced by the module m global symbols-external symbols, corresponding to the C functions and variables defined in other modules 3. Local symbols that are defined and referenced only by module M.

  

1. Any global variables or functions that declare a static property are private to the module.

2. Any river declared as a global variable and function without a static property is common and can be accessed by other modules

7.6 Symbolic parsing
The linker resolves symbolic reference methods: Each reference is linked to a defined symbolic definition in the symbol table of the relocatable target file that it enters. The compiler only allows each module to have only one definition per local symbol. The compiler also ensures that static local variables, which also have local linker symbols, have unique names.

  

7.6.1 how the linker resolves global symbols for multiple definitions
At compile time: The compiler outputs each global symbol to the assembler, or is strong or weak, and the assembler implicitly encodes this information in the symbol table of the relocatable target file. Strong symbols: Functions and initialized global variables. Weak symbol: A global variable that is not initialized. UNIX linker rules for multi-definition symbols: 1. No more strong symbols are allowed 2. If there is a strong sign and multiple weak symbols, select strong symbol 3. If there are multiple weak symbols, choose one from the weak symbol.

  

7.6.2 connection to a static library
Static libraries: Package all relevant target modules into a single file

  

7.7 Relocation
Reposition two steps: 1. Reposition sections and Symbol definitions 2. Reposition the symbol reference in the section.

  

Relocation Entries :

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.