5.6.8 Placing 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:

  1. Create the source file main.c containing the following code:

    #include <stdio.h>
    extern int sqr(int n1);
    const int gValue __attribute__((section(".ARM.__at_0x5000"))) = 3; // Place at 0x5000
    int main(void)
        int squared;
        printf("Value squared is: %d\n", squared);
        return 0;
  2. Create the source file function.c containing the following code:

    int sqr(int n1)
        return n1*n1;
  3. Compile and link the sources:

    armclang --target=arm-arm-none-eabi -march=armv8-a -c function.c
    armclang --target=arm-arm-none-eabi -march=armv8-a -c main.c
    armlink --map function.o main.o -o squared.axf

    The --map option displays the memory map of the image. Also, --autoat is the default.

In this example, __attribute__((section(".ARM.__AT_0x5000"))) specifies that the global variable gValue is to be placed at the absolute address 0x5000. gValue is placed in the execution region ER$$.ARM.__AT_0x5000 and load region LR$$.ARM.__AT_0x5000.

The memory map shows:

  Load Region LR$$.ARM.__AT_0x5000 (Base: 0x00005000, Size: 0x00000004, Max: 0x00000004, ABSOLUTE)

    Execution Region ER$$.ARM.__AT_0x5000 (Base: 0x00005000, Size: 0x00000004, Max: 0x00000004, ABSOLUTE, UNINIT)

    Base Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x00005000   0x00000004   Data   RO           18    .ARM.__AT_0x5000  main.o
Non-ConfidentialPDF file icon PDF versionARM 100748_0607_00_en
Copyright © 2016, 2017 ARM Limited or its affiliates. All rights reserved.