Linker User GuidePreface Overview of the Linker Linking Models Supported by armlink Image Structure and Generation Linker Optimization Features Getting Image Details Accessing and Managing Symbols with armlink Scatter-loading Features The scatter-loading mechanism Overview of scatter-loading When to use scatter-loading Linker-defined symbols that are not defined when s Specifying stack and heap using the scatter file Scatter-loading command-line options Scatter-loading images with a simple memory map Scatter-loading images with a complex memory map Scatter file with link to bit-band objects Root execution regions Root execution region and the initial entry point Root execution regions and the ABSOLUTE attribute Root execution regions and the FIXED attribute Methods of placing functions and data at specific Placement of code and data with __attribute__((sec Placement of __at sections at a specific address Restrictions on placing __at sections Automatic placement of __at sections Manual placement of __at sections Placement of a key in flash memory with an __at se Mapping a structure over a peripheral register wit Example of how to explicitly place a named section Placement of unassigned sections with the .ANY mod Placement rules when using multiple .ANY selectors Command-line options for controlling the placement Prioritization of .ANY sections Specify the maximum region size permitted for plac Examples of using placement algorithms for .ANY se Example of next_fit algorithm showing behavior of Examples of using sorting algorithms for .ANY sect Behavior when .ANY sections overflow because of li Placement of veneer input sections in a scatter fi Placement of sections with overlays Reserving an empty region Placement of ARM C and C++ library code Specifying ARM standard C and C++ libraries in a s Example of placing code in a root region Example of placing ARM C library code Example of placing ARM C++ library code Example of placing ARM library helper functions Creation of regions on page boundaries Overalignment of execution regions and input secti Preprocessing of a scatter file Example of using expression evaluation in a scatte Equivalent scatter-loading descriptions for simple Command-line options for creating simple images Type 1 image, one load region and contiguous execu Type 2 image, one load region and non-contiguous e Type 3 image, multiple load regions and non-contig How the linker resolves multiple matches when proc How the linker resolves path names when processing Scatter file to ELF mapping Scatter File Syntax Linker Command-line Options Linker Steering File Command Reference Via File Syntax
Methods of placing functions and data at specific addresses
7.2.4 Methods of placing functions and data at specific addresses
There are various methods available to place functions and data at specific addresses.
Where they are required, the compiler normally produces RO, RW, ZI, and XO sections from a single source file. These sections contain all the code and data from the source file.
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.
The linker allows you to place a section at a specific address as follows:
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:
Example of how to place a variable at a specific address without scatter-loading
This example shows how to modify your source code to place code and data at specific addresses, and does not require a scatter file.
To place code and data at specific addresses without a scatter file:
In this example,
NoteAlthough the address is specified as
The memory map shows:
… Load Region LR$$.ARM.__at_0x00005000 (Base: 0x00005000, Size: 0x00000000, Max: 0x00000004, ABSOLUTE) Execution Region ER$$.ARM.__at_0x00005000 (Base: 0x00005000, Size: 0x00000004, Max: 0x00000004, ABSOLUTE, UNINIT) Base Addr Size Type Attr Idx E Section Name Object 0x00005000 0x00000004 Zero RW 13 .ARM.__at_0x00005000 main.o
Example of how to place a variable in a named section with scatter-loading
This example shows how to modify your source code to place code and data in a specific section using a scatter file.
To modify your source code to place code and data in a specific section using a scatter file:
In this example,
The memory map shows:
Load Region LR1 (Base: 0x00000000, Size: 0x00001570, Max: 0x00020000, ABSOLUTE) … Execution Region ER3 (Base: 0x00010000, Size: 0x00000010, Max: 0x00002000, ABSOLUTE) Base Addr Size Type Attr Idx E Section Name Object 0x00010000 0x0000000c Code RO 3 .text function.o 0x0001000c 0x00000004 Data RW 15 foo main.o …
NoteIf you omit
Example of how to place a variable at a specific address with scatter-loading
This example shows how to modify your source code to place code and data at a specific address using a scatter file.
To modify your source code to place code and data at a specific address using a scatter file:
The memory map shows that the variable is placed in the
… Execution Region ER2 (Base: 0x00001578, Size: 0x0000ea8c, Max: 0xffffffff, ABSOLUTE) Base Addr Size Type Attr Idx E Section Name Object 0x00001578 0x0000000c Code RO 3 .text function.o 0x00001584 0x0000ea7c PAD 0x00010000 0x00000004 Data RO 15 .ARM.__at_0x10000 main.o…
In this example, the size of
of your data.