06.02.2013 Views

AVR32795: Using the GNU Linker Scripts on AVR UC3 ... - Atmel

AVR32795: Using the GNU Linker Scripts on AVR UC3 ... - Atmel

AVR32795: Using the GNU Linker Scripts on AVR UC3 ... - Atmel

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

NOTE If <str<strong>on</strong>g>the</str<strong>on</strong>g> address of an output secti<strong>on</strong> is not specified, <str<strong>on</strong>g>the</str<strong>on</strong>g> address is set from <str<strong>on</strong>g>the</str<strong>on</strong>g> current<br />

value of <str<strong>on</strong>g>the</str<strong>on</strong>g> locati<strong>on</strong> counter. The locati<strong>on</strong> counter is <str<strong>on</strong>g>the</str<strong>on</strong>g>n incremented by <str<strong>on</strong>g>the</str<strong>on</strong>g> size of<br />

<str<strong>on</strong>g>the</str<strong>on</strong>g> output secti<strong>on</strong>. At <str<strong>on</strong>g>the</str<strong>on</strong>g> start of <str<strong>on</strong>g>the</str<strong>on</strong>g> SECTIONS command, it equals zero by default.<br />

5.3.2 Output secti<strong>on</strong> descripti<strong>on</strong><br />

5.3.2.1 Secti<strong>on</strong>s<br />

8 <str<strong>on</strong>g><strong>AVR</strong>32795</str<strong>on</strong>g><br />

Most programs c<strong>on</strong>sist <strong>on</strong>ly of code, initialized data, and uninitialized data. These will<br />

be in <str<strong>on</strong>g>the</str<strong>on</strong>g> .text, .data, and .bss secti<strong>on</strong>s, respectively. For most programs, <str<strong>on</strong>g>the</str<strong>on</strong>g>se are<br />

also <str<strong>on</strong>g>the</str<strong>on</strong>g> <strong>on</strong>ly secti<strong>on</strong>s that appear in <str<strong>on</strong>g>the</str<strong>on</strong>g> input files.<br />

SECTIONS<br />

{<br />

. = 0x80000000;<br />

.text : { *(.text) }<br />

. = 0x00000000;<br />

.data : { *(.data) }<br />

.bss : { *(.bss) }<br />

}<br />

Secti<strong>on</strong> name<br />

Set <str<strong>on</strong>g>the</str<strong>on</strong>g> value of <str<strong>on</strong>g>the</str<strong>on</strong>g> locati<strong>on</strong> counter<br />

List <str<strong>on</strong>g>the</str<strong>on</strong>g> names of <str<strong>on</strong>g>the</str<strong>on</strong>g> input secti<strong>on</strong>s that should be<br />

placed into this output secti<strong>on</strong>: “all .text input<br />

secti<strong>on</strong>s in all input files”<br />

The first line inside <str<strong>on</strong>g>the</str<strong>on</strong>g> SECTIONS command of <str<strong>on</strong>g>the</str<strong>on</strong>g> above example sets <str<strong>on</strong>g>the</str<strong>on</strong>g> value of <str<strong>on</strong>g>the</str<strong>on</strong>g><br />

special symbol “.”, which is <str<strong>on</strong>g>the</str<strong>on</strong>g> locati<strong>on</strong> counter. If any address of an output secti<strong>on</strong> is<br />

specified in some o<str<strong>on</strong>g>the</str<strong>on</strong>g>r way, <str<strong>on</strong>g>the</str<strong>on</strong>g> address is set from <str<strong>on</strong>g>the</str<strong>on</strong>g> current value of <str<strong>on</strong>g>the</str<strong>on</strong>g> locati<strong>on</strong><br />

counter. The locati<strong>on</strong> counter is <str<strong>on</strong>g>the</str<strong>on</strong>g>n incremented by <str<strong>on</strong>g>the</str<strong>on</strong>g> size of <str<strong>on</strong>g>the</str<strong>on</strong>g> output secti<strong>on</strong>. At<br />

<str<strong>on</strong>g>the</str<strong>on</strong>g> start of <str<strong>on</strong>g>the</str<strong>on</strong>g> SECTIONS command, <str<strong>on</strong>g>the</str<strong>on</strong>g> locati<strong>on</strong> counter has <str<strong>on</strong>g>the</str<strong>on</strong>g> value 0.<br />

The sec<strong>on</strong>d line defines an output secti<strong>on</strong>, .text. Within <str<strong>on</strong>g>the</str<strong>on</strong>g> curly braces after <str<strong>on</strong>g>the</str<strong>on</strong>g><br />

output secti<strong>on</strong> name, it lists <str<strong>on</strong>g>the</str<strong>on</strong>g> names of <str<strong>on</strong>g>the</str<strong>on</strong>g> input secti<strong>on</strong>s that should be placed into<br />

this output secti<strong>on</strong>.<br />

The “*” is a wildcard, which matches any file name. The expressi<strong>on</strong> *(.text) means<br />

all .text input secti<strong>on</strong>s in all input files.<br />

Because <str<strong>on</strong>g>the</str<strong>on</strong>g> locati<strong>on</strong> counter is 0x80000000 when <str<strong>on</strong>g>the</str<strong>on</strong>g> output secti<strong>on</strong> .text is<br />

defined, <str<strong>on</strong>g>the</str<strong>on</strong>g> linker will set <str<strong>on</strong>g>the</str<strong>on</strong>g> address of <str<strong>on</strong>g>the</str<strong>on</strong>g> .text secti<strong>on</strong> in <str<strong>on</strong>g>the</str<strong>on</strong>g> output file to be<br />

0x80000000.<br />

The remaining lines define <str<strong>on</strong>g>the</str<strong>on</strong>g> .data and .bss secti<strong>on</strong>s in <str<strong>on</strong>g>the</str<strong>on</strong>g> output file. The linker<br />

will place <str<strong>on</strong>g>the</str<strong>on</strong>g> .data output secti<strong>on</strong> at address 0x00000000.<br />

After <str<strong>on</strong>g>the</str<strong>on</strong>g> linker places <str<strong>on</strong>g>the</str<strong>on</strong>g> .data output secti<strong>on</strong>, <str<strong>on</strong>g>the</str<strong>on</strong>g> value of <str<strong>on</strong>g>the</str<strong>on</strong>g> locati<strong>on</strong> counter will<br />

be 0x00000000 plus <str<strong>on</strong>g>the</str<strong>on</strong>g> size of <str<strong>on</strong>g>the</str<strong>on</strong>g> .data output secti<strong>on</strong>.<br />

The effect is that <str<strong>on</strong>g>the</str<strong>on</strong>g> linker will place <str<strong>on</strong>g>the</str<strong>on</strong>g> .bss output secti<strong>on</strong> immediately after <str<strong>on</strong>g>the</str<strong>on</strong>g><br />

.data output secti<strong>on</strong> in memory.<br />

The linker will ensure that each output secti<strong>on</strong> has <str<strong>on</strong>g>the</str<strong>on</strong>g> required alignment, by<br />

increasing <str<strong>on</strong>g>the</str<strong>on</strong>g> locati<strong>on</strong> counter if necessary.<br />

In this example, <str<strong>on</strong>g>the</str<strong>on</strong>g> specified addresses for <str<strong>on</strong>g>the</str<strong>on</strong>g> .text and .data secti<strong>on</strong>s will probably<br />

satisfy any alignment c<strong>on</strong>straints, but <str<strong>on</strong>g>the</str<strong>on</strong>g> linker may have to create a small gap<br />

between <str<strong>on</strong>g>the</str<strong>on</strong>g> .data and .bss secti<strong>on</strong>s.<br />

32158A-<strong>AVR</strong>-01/11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!