4. Linker scripts

Source: Internet
Author: User

4. Linker scripts

First, Experience:

First look at an example: Figure 1-1:

Compile the burn-write process:

MAIN.C's:

You can see that the first lamp is lit in the main function:

Fig. 1-1 Lighting

In this example, the code for Gboot.lds is:

Output_arch (ARM)

ENTRY (_start)

SECTIONS {

????. = 0x50008000;

????

????. = ALIGN (4);

????. Text:

???? {

???? start.o (. Text)//.text indicates a code snippet in which the first executable file specified is START.O.

???????????????? Next change the file, and the result of the MAIN.O operation is as follows. Figure 1-2

???? * (. Text)

????}

?

????. = ALIGN (4);

????. Data:

???? {

???? * (. Data)

????}

????

????. = ALIGN (4);

???? Bss_start =.;

????. Bss:

???? {

???? * (. BSS)

????}

???? Bss_end =.;

}

?

When you change the first running file in the LDS file: Figure 1-2:

Gboot.lds Code:

Output_arch (ARM)

ENTRY (_start)

SECTIONS {

????. = 0x50008000;

????

????. = ALIGN (4);

????. Text:

???? {

???? main.o (. Text)//change to MAIN.O for the first run of the file. The result is not lit. Figure 1-2:

???? * (. Text)

????}

?

????. = ALIGN (4);

????. Data:

???? {

???? * (. Data)

????}

????

????. = ALIGN (4);

???? Bss_start =.;

????. Bss:

???? {

???? * (. BSS)

????}

???? Bss_end =.;

}

?

?

Figure 1-2

This is the role of the linker script, which can affect the results of the entire project. The linker script is described below.

?

Second, linker script:

???????? The composition of the linker script:

    1. The basic composition is: segment
    2. Start link Address
    3. Snap To
    4. Variable
    5. Code Snippet header File

An executable program usually includes: code snippet, data segment, BSS segment. As a result, a linker is used to link this program, which will reflect the information of these paragraphs.

SECTIONS {//fixed format

????. = 0x50008000;//. Point indicates the starting address of the program, and now the starting address of the Setup program is 0x50008000

???????????????? You can disassemble the starting address for the viewer to run figure 1-3:

????. = ALIGN (4);//Set four byte alignment, that is, the address can be divisible by 4. This is because arm accesses memory is 4 bytes

aligned, in order to improve efficiency, so when the data is stored in 4-byte alignment. So the work of align (4)

The current address can be adjusted to four-byte alignment. For example, the current address is 1, it will automatically add 3, change

Four-byte alignment.

????. Text:

???? {

???? start.o (. Text)//Set the header file to START.O, which is the first code to run the power on.

???? * (. Text)//.text code snippet, code snippet for all files (*)

????}

?

????. = ALIGN (4);

????. Data:

???? {

???? * (. Data)//.data data segment, data segment is the data segment of all files (*)

????}

????

????. = ALIGN (4);

???? Bss_start =.;/ /linker script variable, record the current address

????. BSS://BSS section begins

???? {

???? * (. BSS)//.BSS segment, BSS segment is BSS for all files (*)

????}

???? Bss_end =.; A variable of the linker script that records the current address. By the difference with the front bss_start is this

???? The size of the BSS segment.

}

?

The starting address to see the program run is indeed 0x50008000: Figure 1-3:

Figure 1-3

Here, just know that you can change the starting link address of the program from here. The importance of the operation is later spoken.

These are the basics of LDS linked files.

?

?

?

?

?

4. 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.