Simple linker script example

Source: Internet
Author: User
Sections {. = 0x10000 ;. text :{*(. text )}. = 0x8000000 ;. data :{*(. data )}. BSS :{*(. BSS )}}

The first line inside the 'sets' command of the above example

Sets the value of the special symbol '.', which is the location

Counter. If you do not specify the address of an output section in some

Other way (other ways are described later), the address is set from

Current Value of the location counter. The location counter is then

Incremented by the size of the output section. At the start of

'Sets' command, the location counter has the value '0 '.

The second line defines an output section, '. text'. The colon is

Required syntax which may be ignored for now. Within the curly braces (parentheses)

After the output section name, you list the names of the input sections

Which shoshould be placed into this output section. The '*' is a wildcard

Which matches any file name. The expression '* (. Text)' means all

'. Text' input sections in all input files.

Since the location counter is '0x10000' when the output Section

'. Text' is defined, the linker will set the address of the'. text'

Section in the output file to be '0x10000 '.

The remaining lines define the '. data' and'. bss' sections in

Output file. The linker will place the '. data' output section

Address '0x8000000 '. After the linker places the'. data' output

Section, the value of the location counter will be '0x8000000 'plus

Size of the '. data' output section. The effect is that the linker will

Place the '. bss' output section immediately after the'. data' output

Section in memory.

The linker will ensure that each output section has the required

Alignment, by increasing the location counter if necessary. In this

Example, the specified addresses for the '. text' and'. data' sections

Will probably satisfy any alignment constraints, but the linker may

Have to create a small gap between the '. data' and'. bss' sections.

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.