Introduction to the linker

Source: Internet
Author: User

1, the executable program to generate the process

2. Linker

A link is the process of collecting and combining various pieces of code and data into a single file. This file can be loaded into memory and executed.

Links can be executed with compile time, or even when executed with the runtime when loaded.

The main work of the linker is:

(1) Symbolic parsing. The target file defines and references the symbols, and each symbol reference coincides with a symbolic definition.

(2) Reposition. The compiler and assembler generate code and data sections starting at address 0. The linker links each symbol definition to a memory location.

All references to these symbols are then modified so that they point to the memory location to reposition the sections.

The linker can be divided into two categories:

(1) Static link

Completed by a static linker, with a set of relocatable target files (usually static libraries) and command line arguments as input, generating a fully linked load and run

Executable destination file as the output. A static library, a mechanism provided by the compiler that packages the relevant target module into a single file,

This file is a static library that is used as the linker input, and the linker only copies the target modules that are referenced by the application in the static library.

Other ways of handling, such as:

A, the compiler identifies the call to the standard function and generates the corresponding code directly. Significantly increase the complexity of the compiler, when adding, deleting, or modifying standard functions,

A new compiler version is required.

B, all standard C functions are placed in a single relocatable target module, linking the module to executable files.

The main disadvantage is the complete copying of standard function sets, and the need to recompile the entire source file for any standard function modification.

Note: The members of each library are independent of each other and can be placed at the end of the command line in any order.

If they are not independent of each other, then they must be sorted.

(2) Dynamic Link

The static library solves the problem of how to make a large number of related functions available to the application, and then the static library needs to be regularly maintained and updated. Also at run time,

The application needs to replicate the code in the library into the running process, wasting storage system resources.

Shared Library is an innovative product to solve the defect of static library.

Shared libraries are also known as shared targets, and in Unix systems, usually with the. So suffix, which is called a DLL in a Windows system.

A shared library is a target module that, at run time, can be loaded into any memory address and linked to a program in memory.

This process is a dynamic link, which is done by the dynamic linker.

All executable target files referencing the library share the code and data in this. so file, rather than as static libraries that are also copied and embedded in the executable file that references them.

Bibliography: Compiling Principles (Dragon book)

In-depth understanding of computer systems (highly recommended)

Introduction to the linker

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.