SPRU513Y August 2001 – June 2022 SM320F28335-EP
For some applications, you may want to allocate more than one section that occupies the same address during run time. For example, you may have several routines you want in fast external memory at different stages of execution. Or you may want several data objects that are not active at the same time to share a block of memory. The UNION statement within the SECTIONS directive provides a way to allocate several sections at the same run-time address.
In The UNION Statement, which uses COFF section names, the .ebss sections from file1.c.obj and file2.c.obj are allocated at the same address in FAST_MEM. In the memory map, the union occupies as much space as its largest component. The components of a union remain independent sections; they are simply allocated together as a unit.
SECTIONS
{
.text: load = SLOW_MEM
UNION: run = FAST_MEM
{
.ebss:part1: { file1.c.obj(.ebss) }
.ebss:part2: { file2.c.obj(.ebss) }
}
.ebss:part3: run = FAST_MEM { globals.c.obj(.ebss) }
}
Allocating a section as part of a union affects only its run address. Sections can never be overlaid for loading. If an initialized section is a union member (an initialized section, such as .text, has raw data), its load allocation must be separately specified. See Separate Load Addresses for UNION Sections. (There is an exception to this rule when combining an initialized section with uninitialized sections; see Section 9.6.7.3.)
UNION run = FAST_MEM
{
.text:part1: load = SLOW_MEM, { file1.c.obj(.text) }
.text:part2: load = SLOW_MEM, { file2.c.obj(.text) }
}
Since the .text sections contain raw data, they cannot load as a union, although they can be run as a union. Therefore, each requires its own load address. If you fail to provide a load allocation for an initialized section within a UNION, the linker issues a warning and allocates load space anywhere it can in configured memory.
Uninitialized sections are not loaded and do not require load addresses.
The UNION statement applies only to allocation of run addresses, so it is meaningless to specify a load address for the union itself. For purposes of allocation, the union is treated as an uninitialized section: any one allocation specified is considered a run address, and if both run and load addresses are specified, the linker issues a warning and ignores the load address.
The UNION capability and the overlay page capability (see Section 9.6.8) may sound similar because they both deal with overlays. They are, in fact, quite different. UNION allows multiple sections to be overlaid within the same memory space. Overlay pages, on the other hand, define multiple memory spaces. It is possible to use the page facility to approximate the function of UNION, but this is cumbersome.