Keil Logo

Linker options for mapping code and data to target memory

2.7 Linker options for mapping code and data to target memory

For an image to run correctly on a target, you must place the various parts of the image at the correct locations in memory. Linker command-line options are available to map the various parts of an image to target memory.

The options implement the scatter-loading mechanism that describes the memory layout for the image. The options that you use depend on the complexity of your image:

  • For simple images, use the following memory map related options:
    • --ro_base to specify the address of both the load and execution region containing the RO output section.
    • --rw_base to specify the address of the execution region containing the RW output section.
    • --zi_base to specify the address of the execution region containing the ZI output section.

    Note:

    For objects that include execute-only (XO) sections, the linker provides the --xo_base option to locate the XO sections. These sections are objects that are targeted at Arm®v7‑M or Armv8‑M architectures, or objects that are built with the armclang -mthumb option,
  • For complex images, use a text format scatter-loading description file. This file is known as a scatter file, and you specify it with the --scatter option.

Note:

You cannot use the memory map related options with the --scatter option.

Examples

The following example shows how to place code and data using the memory map related options:

armlink --ro_base=0x0 --rw_base=0x400000 --zi_base=0x405000 --first="init.o(init)" init.o main.o

Note:

In this example, --first is also included to make sure that the initialization routine is executed first.

The following example shows a scatter file, scatter.scat, that defines an equivalent memory map:

LR1 0x0000 0x20000
{
    ER_RO 0x0
    {
        init.o (INIT, +FIRST)
        *(+RO)
    }

    ER_RW 0x400000
    { 
        *(+RW)
    }

    ER_ZI 0x405000
    {
        *(+ZI)
    }
}

To link with this scatter file, use the following command:

armlink --scatter=scatter.scat init.o main.o
Non-ConfidentialPDF file icon PDF version100748_0614_00_en
Copyright © 2016–2020 Arm Limited or its affiliates. All rights reserved. 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.