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
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
- 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); }
- 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 { } }
- 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)