You copied the Doc URL to your clipboard.

Placement of sections with overlays

You can place multiple execution regions at the same address with overlays.

The OVERLAY attribute allows you to place multiple execution regions at the same address. An overlay manager is required to make sure that only one execution region is instantiated at a time. does not provide an overlay manager.

The following example shows the definition of a static section in RAM followed by a series of overlays. Here, only one of these sections is instantiated at a time.

EMB_APP 0x8000 
    STATIC_RAM 0x0                  ; contains most of the RW and ZI code/data
            * (+RW,+ZI)
    OVERLAY_A_RAM 0x1000 OVERLAY    ; start address of overlay…
            module1.o (+RW,+ZI)
            module2.o (+RW,+ZI)
    …                        ; rest of scatter-loading description

A region marked as OVERLAY is not initialized by the C library at startup. The contents of the memory used by the overlay region are the responsibility of an overlay manager. If the region contains initialized data, use the NOCOMPRESS attribute to prevent RW data compression.

You can use the linker defined symbols to obtain the addresses required to copy the code and data.

The OVERLAY attribute can be used on a single region that is not the same address as a different region. Therefore, an overlay region can be used as a method to prevent the initialization of particular regions by the C library startup code. As with any overlay region these must be manually initialized in your code.

An overlay region can have a relative base. The behavior of an overlay region with a +offset base address depends on the regions that precede it and the value of +offset. The linker places consecutive +offset regions at the same base address if they have the same +offset value.

When a +offset execution region ER follows a contiguous overlapping block of overlay execution regions the base address of ER is:

limit address of the overlapping block of overlay execution regions + offset

The following table shows the effect of +offset when used with the OVERLAY attribute. REGION1 appears immediately before REGION2 in the scatter file:

Table 7-7 Using relative offset in overlays

REGION1 is set with OVERLAY +offset REGION2 Base Address
NO <offset> REGION1 Limit + <offset>
YES +0 REGION1 Base Address
YES <none-zero offset> REGION1 Limit + <none-zero offset>

The following example shows the use of relative offsets with overlays and the effect on execution region addresses:

EMB_APP 0x8000{
    CODE 0x8000
    # REGION1 Base = CODE limit
    # REGION2 Base = REGION1 Base
    # REGION3 Base = REGION2 Base = REGION1 Base
    # REGION4 Base = REGION3 Limit + 4
    Region4 +4 OVERLAY

If the length of the non-overlay area is unknown, you can use a zero relative offset to specify the start address of an overlay so that it is placed immediately after the end of the static section.

You can use the following command-line options to add extra debug information to the image:

  • --emit_debug_overlay_relocs.

  • --emit_debug_overlay_section.

These permit an overlay-aware debugger to track which overlay is currently active.

Was this page helpful? Yes No