018 linker Scripts

Source: Internet
Author: User

1. The magical role of linker scripts

By using different linker scripts, you can implement different functions without the need to change the source code!

The linker script plays a vital role in the program's generation!

2. Linker Script---> Segment

An executable program is usually composed of: code snippet, data segment, BSS segment.

Similarly, in the linker script used to link the program, the information in these paragraphs is reflected.

The information of the segment is indicated by the sections fixed designator the most important information of the linker script is the segment;

The code snippet contains the code for all the files;

The data segment contains data for all files;

The most basic framework is as follows:

  

3. Linker Script---> Set start link Address

. = 0x0;

. (point) Represents the current position, the first in the entire program, the location before the code snippet, of course, the start address of the program, the beginning of the program address;

So where does the program start the link from? The following information is the link address of the program;

  

  

4. Linker Script---> Alignment settings

Why do you want to do 4-byte alignment? The ARM processor is actually accessed in a 4-byte alignment, so it is hoped that when storing some data, as far as possible to achieve 4-byte alignment, so as to improve the efficiency of access; when storing big data, you want to be able to do 4-byte alignment, that is, from a 4 integer times such an address to start storage.

If the starting address cannot be 4-byte aligned, you can use it. = ALIGN (4); To adjust the address;

  

  

5. Linker Script---> Use variables

Record the current address with Bss_start, Bss_end record the current address, but the two addresses are different, because a BSS segment is spaced;

If you want to calculate the length of the BSS segment in the program, you can use Bss_end-bss_start to calculate the length.

  

  

6. Linker Script---> Set code snippet First file

The use of different linker scripts, you can let the program run a completely different effect;

The above content is not enough to affect the program so much, although there are some changes, but the program does not reflect a completely different effect, this magic in the code snippet header file this position;

The program contains multiple files, which one is at the front of the code snippet? Is fastidious, 234 of the order can be regardless, but the first order must be tube, the first file needs to do what the CPU initialization, is the first must execute the code, the CPU power, first must execute this code, must ensure that the program link to the front, row first, how to do? To make a setting in the code snippet.

  

  

  

  

018 linker Scripts

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.