Non-Confidential | ![]() | ARM 100748_0607_00_en | ||
| ||||
Home > Mapping Code and Data to the Target > Placing functions and data at specific addresses |
To place a single function or data item at a fixed address, you must enable the linker to process the function or data separately from the rest of the input files.
Where they are required, the compiler normally produces RO, RW, and ZI sections from a single source file. These sections contain all the code and data from the source file.
Typically, you create a scatter file that defines an execution region at the required address with a section description that selects only one section.
To place a function or variable at a specific address, it must be placed in its own section. There are several ways to do this:
Use __attribute__((section("
to place functions and variables in a
specially named section, name
"))).ARM.__at_
, where address
is
the address to place the function or variable. For example, address
__attribute__((section(".ARM.__at_0x4000
"))).
To place ZI data at a specific address, use the variable
attribute
__attribute__((section("
with the special name
name
"))).bss.ARM.__at_
address
These specially named sections are called __at
sections.
Use the .section
directive from assembly language. In assembly code, the
smallest locatable unit is a .section
.
Use the -ffunction-sections
compiler option to generate one ELF
section for each function in the source file.
This option results in a small increase in code size for some functions because it
reduces the potential for sharing addresses, data, and string literals between
functions. However, this can help to reduce the final image size overall by enabling the
linker to remove unused functions when you specify armlink --remove
.