SLAU131V October 2004 – February 2020
You can create a hole in an initialized output section. A hole is created when you force the linker to leave extra space between input sections within an output section. When such a hole is created, the linker must supply raw data for the hole.
Holes can be created only within output sections. Space can exist between output sections, but such space is not a hole. To fill the space between output sections, see Section 8.5.4.2.
To create a hole in an output section, you must use a special type of linker assignment statement within an output section definition. The assignment statement modifies the SPC (denoted by .) by adding to it, assigning a greater value to it, or aligning it on an address boundary. The operators, expressions, and syntaxes of assignment statements are described in Section 8.5.10.
The following example uses assignment statements to create holes in output sections:
SECTIONS
{
outsect:
{
file1.c.obj(.text)
. += 0x0100 /* Create a hole with size 0x0100 */
file2.c.obj(.text)
. = align(16); /* Create a hole to align the SPC */
file3.c.obj(.text)
}
}
The output section outsect is built as follows:
All values assigned to the . symbol within a section refer to the relative address within the section. The linker handles assignments to the . symbol as if the section started at address 0 (even if you have specified a binding address). Consider the statement . = align(16) in the example. This statement effectively aligns the file3.c.obj .text section to start on a 16-byte boundary within outsect. If outsect is ultimately allocated to start on an address that is not aligned, the file3.c.obj .text section will not be aligned either.
The . symbol refers to the current run address, not the current load address, of the section.
Expressions that decrement the . symbol are illegal. For example, it is invalid to use the -= operator in an assignment to the . symbol. The most common operators used in assignments to the . symbol are += and align.
If an output section contains all input sections of a certain type (such as .text), you can use the following statements to create a hole at the beginning or end of the output section.
.text: { .+= 0x0100; } /* Hole at the beginning */
.data: { *(.data)
. += 0x0100; } /* Hole at the end */
Another way to create a hole in an output section is to combine an uninitialized section with an initialized section to form a single output section. In this case, the linker treats the uninitialized section as a hole and supplies data for it. The following example illustrates this method:
SECTIONS
{
outsect:
{
file1.c.obj(.text)
file1.c.obj(.bss) /* This becomes a hole */
}
}
Because the .text section has raw data, all of outsect must also contain raw data. Therefore, the uninitialized .bss section becomes a hole.
Uninitialized sections become holes only when they are combined with initialized sections. If several uninitialized sections are linked together, the resulting output section is also uninitialized.