06.02.2013 Views

ARM Compiler toolchain Using the Linker - ARM Information Center

ARM Compiler toolchain Using the Linker - ARM Information Center

ARM Compiler toolchain Using the Linker - ARM Information Center

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

8.18 <strong>Using</strong> __attribute__((section("name")))<br />

8.18.1 See also<br />

<strong>Using</strong> scatter files<br />

You can place code and data by separating <strong>the</strong>m into <strong>the</strong>ir own objects without having to use<br />

<strong>toolchain</strong>-specific pragmas or attributes. However, you can also use<br />

__attribute__((section("name"))) to place an item in a separate ELF section. You can <strong>the</strong>n use<br />

a scatter file to place <strong>the</strong> named sections at specific locations.<br />

To use __attribute__((section("name"))) to place a variable in a separate section:<br />

1. Use __attribute__((section("name"))) to specify <strong>the</strong> named section where <strong>the</strong> variable is<br />

to be placed, for example:<br />

int variable __attribute__((section("foo"))) = 10;<br />

2. Use a scatter file to place <strong>the</strong> named section, for example:<br />

FLASH 0x24000000 0x4000000<br />

{<br />

... ; rest of code<br />

}<br />

ADDER 0x08000000<br />

{<br />

file.o (foo) ; select section foo from file.o<br />

}<br />

Be aware of <strong>the</strong> following:<br />

• linking with --autoat or --no_autoat does not affect <strong>the</strong> placement<br />

Example 8-8 Naming a section<br />

Example 8-9 Placing a section<br />

• if scatter-loading is not used, <strong>the</strong> section is placed in <strong>the</strong> default ER_RW execution region of<br />

<strong>the</strong> LR_1 load region<br />

• if you have a scatter file that does not include <strong>the</strong> foo selector, <strong>the</strong>n <strong>the</strong> section is placed<br />

in <strong>the</strong> defined RW execution region.<br />

You can also place a function at a specific address using .<strong>ARM</strong>.__at_address as <strong>the</strong> section name.<br />

For example, to place <strong>the</strong> function sqr at 0x20000, specify:<br />

int sqr(int n1) __attribute__((section(".<strong>ARM</strong>.__at_0x20000")));<br />

int sqr(int n1)<br />

{<br />

return n1*n1;<br />

}<br />

Reference<br />

• <strong>Using</strong> __at sections to place sections at a specific address on page 8-37<br />

• Restrictions on placing __at sections on page 8-38.<br />

<strong>ARM</strong> DUI 0474C Copyright © 2010-2011 <strong>ARM</strong>. All rights reserved. 8-35<br />

ID080411 Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!