• Aucun résultat trouvé

Creating and Filling Holes

Dans le document Assembly Family (Page 146-151)

.word Initialize 16-Bit Integer

9. Linker Description

9.10 Creating and Filling Holes

The linker provides you with the ability to create areas within output sections that have nothing linked into them. These areas are called holes. In special cases, .bss sections can also be treated as holes. This section describes how the linker handles such holes and how you can fill holes (and .bss sections) with a specified value.

9.10.1 Initialized and Uninitialized Sections

There are two rules to remember about the contents of an output section. An output section will contain:

Rule 1 Raw data for the entire section or Rule 2 No raw data (un initialized)

A section that has raw data is referred to as initialized. This means that the object file contains the actual memory image contents of the section. When the section is loaded, this image is loaded into memory at the section's speci-fied starting address. The .text and .data sections always have raw data if anything was assembled into them. All named sections (defined with the .sect assembler directive) also have raw data in the object file.

By default, the .bss section has no raw data (it is uninitialized). It simply oc-cupies space in the. memory map, but has no actual contents. This type of section is typically used to reserve space in RAM for variables. In the object file, an uninitialized section has a normal section header and may have sym-bols defined in it. However, no memory image is stored in the file.

9.10.2 Creating Holes

9-30

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 when building an output section. When such a hole is created, the linker must follow rule 1 (above) and supply raw data for the hole.

Holes can only be created within output sections. There can also be space between output sections, but such spaces are not considered to be holes.

Space between output sections cannot be filled or initialized.

To create a hole in an output section, you must use a special type of linker assignment statement within a SECTIONS definition. The assignment state-ment modifies the SPC (denoted by the "." symbol), by either adding to it, assigning a new (greater) value to it, or aligning it at an address boundary.

The operators, expressions, and syntax of assignment statements are described in Section 9.9 (page 9-27).

Linker Description - Creating and Filling Holes ad-dress 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 ad-dress). Consider the statement that aligns "." in the preceding example, which aligns .text in file3. obj to start on a 16-byte boundary within outsect. If outsect is ultimately allocated to start on an address that is not aligned, then .text in f ile3 will also not be aligned. Assignments and alignments are rela-tive to the beginning of the section.

Expressions that decrement "." are illegal. For example, it is invalid to use the

-=

operator in an assignment to ".". The most common operators used in as-signments to "." are += and align.

Another way to create a hole in an output section is to combine an uninitial-ized section (.bss) with initialuninitial-ized sections to form a single output section. In this case, the linker treats the .bss section as a hole and supplies data for it. combined with initialized sections. If mUltiple .bss sections are linked to-gether, and all are uninitialized, the resulting output section will also be unin-itialized.

9-31

Linker Description - Creating and Filling Holes

9.10.3 Filling Holes

9-32

Whenever there is a hole in an initialized output section, the linker must supply raw data to fill it. The linker fills holes with a 2-byte fill value that is replicated through memory until it fills the hole. The linker determines the fill value as follows:

1) If the hole was formed by combining a .bss section with an initialized section, you can specify a fill value for that specific .bss section. The value is specified with an = symbol and a 2-byte constant following the section name within a SECTIONS directive. For example,

SECTIONS {

outsect:

(

filel.obj (.text)

file2.obj(.bss)

=

OFFh /* Fill this hole */

/* with OOFFh */

2) You can also specify a fill value for all the holes in an output section by supplying the fill value after the section definition. For example, SECTIONS

{

I outsect:

(

• += lOh;

filel.obj (.text) filel.obj (.bss)

} =

OFFOOh

/* This creates a hole */

/* This creates another hole */

/* This fills both holes with */

/* OFFOOh */

3) If no explicit initialization is specified for a hole, the hole is filled with the value specified with the -f linker option. For example, suppose the command file link. cmd contains the following SECTIONS directive:

SECTIONS (

.text: (

.=

100;) /* Create a 100-byte hole */

Now invoke the linker with the -f option:

lnk370 - f OFFFFh link.cmd This fills the hole with OFFFFh.

4) If no -f option is specified when the linker is invoked, then holes are filled with Os.

Whenever a hole is created and filled in an initialized output section, the hole is identified in the link map (use the -m linker option to produce a map file) along with the value the linker used to fill it.

Linker Description - Creating and Filling Holes

9.10.4 Explicit Initialization of .bss Sections

A .bss section only becomes a hole when it is combined with an initialized section. When .bss sections are combined with each other, the resulting out-put section is still uninitialized and has no raw data in the outout-put file.

However, you can force an uninitialized section to be initialized simply by specifying an explicit fill value for it in the SECTIONS directive. This causes the entire section to have raw data (the fill value). For example,

SECTIONS

(

.bss: {} = l234h /* Fills .bss with 1234h */

Note:

Since filling a section (even with Os) causes raw data to be generated for the entire section in the output file, your output file will be very large if you specify fill values for large .bss sections or holes.

9.10.5 Examples of Using Initialized Holes

The TMS370 has 4K bytes of program memory starting at location 7000h.

The top bytes of this area are reserved for interrupt vectors. Suppose you want to link the .text sections from three object files into a .text output section that will begin at address 7000h. Suppose also that you have a section of initial-ized interrupt vectors called int-vecs that you want to link at address 7FFOh.

You could fill the space between the end of the .text section and the begin-ning of the interruptvectors; this example fills the space with a 1 -byte fill value of OEFh (a trap instruction).· Figure 9-3 illustrates the desired memory map for program memory.

7000h

=I~~II

7FFOh 7FFFh

Figure 9-3. Initialized Hole

9-33

Linker Description - Creating and Filling Holes

Remember, you cannot fill the space between two output sections. To obtain the configuration shown in Figure 9-3, you must create one large output section that has .text at the beginning, int-vecs at the end, and a hole filled with OEFh in between:

SECTIONS {

9-34

prog 07000h {

filel.obj (.text) f ile2 . obj ( . text) file3.obj (.text)

• = OFFOh;

filel.obj(int_vecs) OEFEFh

/*

/*

/*

/*

/*

Define prog and bind i t to start at 7000h */

Link in the .text sections from each file */

Create a hole up to OFFOh (7FFOh absolute */

Link in the vectors section */

Specify a fill value */

The fill value must be a 2-byte constant. To have the value OEFh in each byte, the fill value was specified as OEFEFh.

Notice that the value OFFOh, which is assigned to the section program counter (.), is relative to beginning of the section. Since the section begins at 7000h, the hole is actually created from the end of the .text section to address 7FFOh.

Linker Description - Partial (Incremental) Linking

Dans le document Assembly Family (Page 146-151)