Keil Logo

Technical Support

On-Line Manuals

Linker User Guide

Preface 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

Behavior when .ANY sections overflow because of linker-generated content

7.4.8 Behavior when .ANY sections overflow because of linker-generated content

Because linker-generated content might cause .ANY regions to overflow, a contingency algorithm is included in the linker.

The linker does not know the address of a section until it is assigned to a region. Therefore, when filling .ANY regions, the linker cannot calculate the contingency space and cannot determine if calling functions require veneers. The linker provides a contingency algorithm that gives a worst-case estimate for padding and an additional two percent for veneers. To enable this algorithm use the --any_contingency command-line option.
The following diagram represents the notional image layout during .ANY placement:
Figure 7-4 .ANY contingency
.ANY contingency

The downward arrows for prospective padding show that the prospective padding continues to grow as more sections are added to the .ANY selector.
Prospective padding is dealt with before the two percent veneer contingency.
When the prospective padding is cleared the priority is set to zero. When the two percent is cleared the priority is decremented again.
You can also use the ANY_SIZE keyword on an execution region to specify the maximum amount of space in the region to set aside for .ANY section assignments.
You can use the armlink command-line option --info=any to get extra information on where the linker has placed sections. This can be useful when trying to debug problems.

Example

  1. Create the following foo.c program:
    #include "stdio.h"
    
    int array[10] __attribute__ ((section ("ARRAY")));
    
    struct S {
        char A[8];
        char B[4];
    };
    struct S s;
    
    struct S* get()
    {
        return &s;
    }
    
    int sqr(int n1);
    int gSquared __attribute__((at(0x5000)));  // Place at 0x00005000
    
    int sqr(int n1)
    {
        return n1*n1;
    }
    
    int main(void) {
        int i;
        for (i=0; i<10; i++) {
            array[i]=i*i;
            printf("%d\n", array[i]);
        }
        gSquared=sqr(i);
        printf("%d squared is: %d\n", i, gSquared);
    
        return sizeof(array);
    }
    
  2. Create the following scatter.scat file:
    LOAD_REGION 0x0 0x3000
    {
       ER_1 0x0 0x500
       {
          .ANY
       }
       ER_2 (ImageLimit(ER_1)) 0x400
       {
          .ANY
       }
       ER_3 (ImageLimit(ER_2)) 0x500
       {
          .ANY
       }
       ER_4 (ImageLimit(ER_3)) 0x1000
       {
           *(+RW,+ZI)
       }
       ARM_LIB_STACK 0x800000 EMPTY -0x10000
       {
       }
       ARM_LIB_HEAP  +0 EMPTY 0x10000
       {
       }
    }
    
  3. Compile and link the program as follows:
    armcc -c --cpu=cortex-m4 -o foo.o foo.c
    armlink --cpu=cortex-m4 --any_contingency --scatter=scatter.scat --info=any -o foo.axf foo.o
The following shows an example of the information generated:
==============================================================================


Sorting unassigned sections by descending size for .ANY placement.
Using Worst Fit .ANY placement algorithm.
.ANY contingency enabled.

Exec Region    Event                         Idx          Size        Section Name                  Object
ER_1           Assignment: Worst fit         158          0x000001d6  .text                         c_w.l(flsbuf.o)
ER_3           Assignment: Worst fit         83           0x00000138  .text                         c_w.l(initio.o)
ER_2           Assignment: Worst fit         289          0x000000f8  .text                         c_w.l(fseek.o)
ER_3           Assignment: Worst fit         291          0x000000f0  .text                         c_w.l(stdio.o)
...
ER_2           Assignment: Worst fit         3            0x0000005c  .text                         foo.o
...

.ANY contingency summary
Exec Region    Contingency     Type
ER_1           53              Auto
ER_2           48              Auto
ER_3           59              Auto

==============================================================================


Sorting unassigned sections by descending size for .ANY placement.
Using Worst Fit .ANY placement algorithm.
.ANY contingency enabled.

Exec Region    Event                         Idx          Size        Section Name                  Object
ER_1           Info: .ANY limit reached      -            -           -                             -
ER_3           Info: .ANY limit reached      -            -           -                             -
ER_2           Info: .ANY limit reached      -            -           -                             -
ER_3           Assignment: Worst fit         405          0x00000034  !!!scatter                    c_w.l(__scatter.o)
ER_3           Assignment: Worst fit         407          0x0000001c  !!handler_zi                  c_w.l(__scatter_zi.o)
Non-ConfidentialPDF file icon PDF versionARM DUI0377H
Copyright © 2007, 2008, 2011, 2012, 2014-2016 ARM. 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.