Linker command file

One of the many jobs of the linker is to place all the code and data segments in memory. This is controlled by a linker command file that gives the user complete control over the placement of values in memory.
The SDK comes with two command files, rom.cmd and linker.cmd. These are used when linking run from ROM applications and run from RAM applications.

Sections of the command file

Memory section

The memory section defines a number of arbitrarily named memory areas.
The linker.cmd contains the following memory areas.

  AREA {
    name = ram_prog;
  }

  AREA {
    name = ram_data;
  }

This defines two memory areas ram_prog and ram_data.

Image section

The image section maps arenas into memory areas. There are a number of different types of memory area.
Type
Description
ABSOLUTE
The memory area is at an absolute address in memory. This is typically 0
REMAP
The memory area has been remapped in memory to the address given by the address attribute.
RELOCATE
The contents is to be relocated from the output image to the offset in the memory area specified.
INITIALISER
The contents of the memory are to be zero initialised
EMPTY
The contents of the memory are to be uninitialised


Arenas can have the following attributes.
Attribute
Description
offset
The offset into the memory area is placed at
arenas
The list of arenas. This can be comma separated or a dashed range
area
The name of the memory area
address
The address to remap the memory area to

The rom.cmd file contains a number of arenas of different types.
  ABSOLUTE {
    offset = ROM_OFFSET;
    arenas = p9, p8, d9;
    area = rom;
  }
  REMAP {
    address = (CACHED_MEMORY_END - ROM_SIZE);
    arenas = p0, p3, c0-c9, p4-p7, d3-d7;
    area = rom;
  }
  RELOCATE {
    offset = $08;
    arenas = b0;
    area = ram_prog;
  }
  INITIALISER {
    arenas = d8, d10;
    area = ram_data;
  }
  EMPTY {
    arenas = d2;
    area = ram_data;
  }


Variables section

The variables section allows the user to provide information to the linker that can be used in command file expressions. The remap section in the rom.cmd file uses two variables, CACHED_MEMORY_END and ROM_SIZE to specify where to remap memory to.

Variables can also be passed in on the command line using the -D option.

Arenas section

The arenas section is used to map segment names into arenas, that are then placed into memory areas.
Each mapping is a comma separated list of segment names or segment name patterns. The patterns are matched using regular expressions to map into the correct arena.
This example from the linker.cmd file maps all segments ending in '.et' and with the name 'JMCTab' into arena d4.

Linker output

The linker output file contains all the memory areas. Any non absolute sections are put into the first data memory area after all other data memory.