ARM linker (1): general concept of Link

Source: Internet
Author: User

The ARM linker can link Multiple Target files generated by compilation (or assembly) with multiple library files to generate executable output files in ELF format.

During the link process, if the input file of the linker contains both ARM code and Thumb code, the linker can automatically generate a veneer file for links between different codes. This file is used to help the target processor achieve the conversion between two different States, and can achieve long jump. The linker can also specify a location in the target memory for the instruction code segment and data segment.

1. General concept of link 1.1 input and output of the linker

1. Target file and Image File

The input of the linker is the output of the compiler. The file generated after compilation by the compiler is called the target file and is in the ELF (Executable Linkable Format) Format. The target file in ELF format is a non-text file, which generally contains instruction code and compilation information and is provided to the linker.

The file generated by the target file through the link of the linker is called an image file, which is still in the ELF format. This is called an image file because the location relationship between programs in the file corresponds to the address during actual storage. The program code is an "image" of the actually stored code ". Generally, programs stored in the program storage area start from the address 0x0000, but the starting address of the image file may not start from 0x0000, and the default value in the ADS system is 0x8000.

Both the target file and the image file are in the ELF format. The major difference between them is that the address of the code and symbol in the target file is uncertain, the location of codes and symbols in the image file must be fixed.

2. Files and segments

Files are the basic unit of computer operations, while segments are the basic unit of linker operations. A file can contain one or more segments. The linker does not care about the number of input files, but only the number of input segments.

The input segments of the linker can be from either the source file or the library. These segments have three attributes: Read-Only (RO) segments, read/write (RW) segments, and Initialization is zero (PI) segments.

The output of the linker is an executable image file that contains one or more segments. These segments in the image file are called output segments. They also have three attributes: Read-Only (RO) segments, read/write (RW) segments, and Initialization is zero (PI) segments.

3. Structure of the image file

(1) an image file consists of one or more domains.

The domain in the image file is a storage area that stores the image file. An Image File occupies several storage areas. It mainly depends on the structure of the image file and the composition of the target storage. If the image file is not large, it is generally used as a storage area. If the system is complicated and the file is large, the code of the read-only attribute and the data of the read/write attribute are stored separately.

(2) Each domain contains one or more output segments.

Each domain can contain one, two, or three output segments. It mainly depends on the storage location of the domain and the requirements for the output segment. It is also related to the memory features.

(3) Each output segment contains one or more input segments.

The linker organizes input segments with the same attributes in a certain order to form an output segment. Input segments with the same attributes have similar functions in the system, so that the output segments are easy to store and manage.

(4) Each input segment can contain code and data.

The input segment can contain code and data, for example, defining a data buffer after a code segment. However, such code and data can only have the same attributes, which are generally defined as read-only attributes. Therefore, if the data needs to be readable/written, it cannot be in the same segment as the code.

1.2 image file loading and execution

1. load and execute the domain

The image file can have two types of addresses: The loading address and the execution address. The load address is the storage address of the file in the memory, and the execution address is the address of the file at runtime. The storage area for file loading is called the loading domain, and the storage area for file running is called the execution domain. For example, to increase the speed, you need to move the executed program from the ROM storage area to the high-speed buffer before execution. At this time, the load address is no longer the execution address.

2. Location independence

3. image file entry point

The image file has two types of entry points: the initial entry point and the normal entry point.

L The initial entry point of the image file is stored in the ELF format file header. Each image file can have only one initial entry point. It must meet two basic conditions: it must always be within the executable address range of the image file; this address range cannot be overwritten, and the loading address and execution address are always the same address. The initial entry point can be a common entry point.

L in the assembly language source program, the entry point defined by the entry pseudo command is a common entry point, and multiple entry points can be defined. These entry points can be used as the entry points for the interrupt handler.

1.3 sorting order of input segments in the Image File

1. Method for specifying an address for the input segment

L address-related options are used in command line and graphical methods. Common options that may affect Address Allocation include:

-Ro-base,-RW-base,-split,-ropi, and-rwpi.

L use the option to specify the position for the input segment in command line and graphical mode, including:

-Entry location,-first section-ID, and-last section-id.

L when the target system and image files are complex, you can specify the detailed address information for each input segment using scatter format files.

2. sorting rules of input files

By default, the linker organizes input segments in the following order:

L read-only code segment

L read-only data segment

L read/write code segments

L non-zero initialized Data Segment

L zero-initialized Data Segment

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.