----------------------------------------------------------- 2_1 |2_2 |2_3 | |high address ----------------------------------------------------------- 1_1 |1_2 |1_3 |1_4 | ----------------------------------------------------------- segment |root |low address -----------------------------------------------------------
Segments 1_1, 1_2, 1_3 and 1_4 share the same area of memory. Only one of these segments can be loaded at any given instant; the remainder must be on backing store.
Similarly, segments 2_1, 2_2 and 2_3 share the 2_ area of memory, but this is entirely separate from the 1_ partition.
It is a current restriction that an overlay segment name is of the form partition_segment and contains 10 or fewer characters. However, it is not required that partition and segment be numeric as shown here in the example: any alphanumeric characters are acceptable.
Nevertheless, if a 2-dimensional naming scheme is used, the linker will generate segment clash tables (see below), and segments can be unloaded implicitly by the overlay manager when a clashing segment is loaded. In effect, this supports the classification of dynamic overlay segments into disjoint sets of not co-resident objects.
A dynamic overlay segment (including a root segment) is followed by a sequence of relocation directives. The sequence is terminated by a word containing -1. Each directive is a 28-bit byte offset of a word or instruction to be relocated, together with a flag nibble in the most significant 4 bits of the word. Flag nibbles have the following meanings:
-------------------------------------------------------- 0: |relocate a word in the root segment by the |difference between the address at which the root |was loaded and the address at which it was linked; -------------------------------------------------------- 1: |relocate a word in an overlay segment by the |address of the root; -------------------------------------------------------- 2: |relocate a word in an overlay segment by the |address of the segment; -------------------------------------------------------- 3: |relocate a B or BL from an overlay segment to the |root segment, by the difference (in words) between |the segments address and the roots address; -------------------------------------------------------- 7: |relocate a B or BL from the root segment to an |overlay segment, by the difference (in words) |between the root's address and the segment's |address, (such relocation directives always refer |to a PCIT entry in an overlay segment, which is |used to initialise a PCIT section in the root when |the overlay segment is loaded). --------------------------------------------------------
By default, only code AREAs are included in overlay segments. Data AREAs can be forcibly included, but it is the user's responsibility to ensure that doing so is meaningful and safe.
On disc, an overlaid program is organised as a directory containing a root image and a collection of overlay segments. The name of the directory is specified to the Linker as the argument to its -Output flag. The linker creates the following components within the application directory:
the root segment, which is an AIF image, and (for example):
root
overlay segments, which are plain binary image fragments.
1_1
1_2
...
2_1
...
For example:
segment-name module-name [ "(" list-of-AREA-names ")" ]
module-name ...
list-of-AREA-names is a comma-separated list. If omitted, all AREAs with the CODE attribute are included.
1_1 edit1 edit2 editdata(C$$code,C$$data) sort
module-name is either the name of an object file (with all leading pathname components and file name extensions removed), or the name of a library member (again, with all leading pathname components and file name extensions removed).
In the example above, sort would match the C library module of the same name.
Note that these rules require that, within a link list, modules have unique names. For example, it is not possible to overlay a program made up from test/thing.o and thing.o (two modules called thing). This is a restriction on overlaid programs only.
To help partition a program between overlay segments the linker can generate a list of inter-AREA references. This is requested by using the -Xref option. In general, if area A refers to area B, for example because fx in area A calls fy in area B, then A and B should not share the same area of memory. Otherwise, every time fx calls fy, or fy returns to fx, there will be an overlay segment swap.
The -MAP option requests the linker to print the base address and size of every AREA in the output program. Although not restricted to use with overlaid programs, -MAP is most useful with them, as it shows how AREAs might be packed more efficiently into overlay segments.