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

Because linker-generated content might cause .ANY sections 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
To view this graphic, your browser must support the SVG format. Either install a browser with native support, or install an appropriate plugin such as Adobe SVG Viewer.


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__((section(".ARM.__at_0x5000")));  // Place at 0x5000
    
    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 0x1000
       {
          .ANY
       }
       ER_2 (ImageLimit(ER_1)) 0x1500
       {
          .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:
    armclang -c --target=arm-arm-none-eabi -mcpu=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_2           Assignment: Worst fit         144          0x0000041a  .text                         c_wu.l(_printf_fp_dec.o)
ER_2           Assignment: Worst fit         261          0x00000338  CL$$btod_div_common           c_wu.l(btod.o)
ER_1           Assignment: Worst fit         146          0x000002fc  .text                         c_wu.l(_printf_fp_hex.o)
ER_2           Assignment: Worst fit         260          0x00000244  CL$$btod_mult_common          c_wu.l(btod.o)
...
ER_1           Assignment: Worst fit         3            0x00000090  .text                         foo.o
...
ER_3           Assignment: Worst fit         100          0x0000000a  .ARM.Collect$$_printf_percent$$00000007  c_wu.l(_printf_ll.o)
ER_3           Info: .ANY limit reached      -            -           -                             -
ER_1           Assignment: Highest priority  423          0x0000000a  .text                         c_wu.l(defsig_exit.o)
...
.ANY contingency summary
Exec Region    Contingency     Type
ER_1           161             Auto
ER_2           180             Auto
ER_3           73              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_2           Info: .ANY limit reached      -            -           -                             -
ER_1           Info: .ANY limit reached      -            -           -                             -
ER_3           Info: .ANY limit reached      -            -           -                             -
ER_2           Assignment: Worst fit         533          0x00000034  !!!scatter                    c_wu.l(__scatter.o)
ER_2           Assignment: Worst fit         535          0x0000001c  !!handler_zi                  c_wu.l(__scatter_zi.o)
Non-ConfidentialPDF file icon PDF versionDUI0803J
Copyright © 2014–2017, 2019 Arm Limited or its affiliates. All rights reserved.