SPRUI03E June 2015 – January 2023
Linker command files allow you to put linker options and directives in a file; this is useful when you invoke the linker often with the same options and directives. Linker command files are also useful because they allow you to use the MEMORY and SECTIONS directives to customize your application. You must use these directives in a command file; you cannot use them on the command line.
Linker command files are ASCII files that contain one or more of the following:
To invoke the linker with a command file, enter the cl6x --run_linker command and follow it with the name of the command file:
cl6x --run_linker command_filename |
The linker processes input files in the order that it encounters them. If the linker recognizes a file as an object file, it links the file. Otherwise, it assumes that a file is a command file and begins reading and processing commands from it. Command filenames are case sensitive, regardless of the system used.
Linker Command File shows a sample linker command file called link.cmd.
a.c.obj /* First input filename */
b.c.obj /* Second input filename */
--output_file=prog.out /* Option to specify output file */
--map_file=prog.map /* Option to specify map file */
The sample file in Linker Command File contains only filenames and options. (You can place comments in a command file by delimiting them with /* and */.) To invoke the linker with this command file, enter:
cl6x --run_linker link.cmd
You can place other parameters on the command line when you use a command file:
cl6x --run_linker --relocatable link.cmd x.c.obj y.c.obj
The linker processes the command file as soon as it encounters the filename, so a.c.obj and b.c.obj are linked into the output module before x.c.obj and y.c.obj.
You can specify multiple command files. If, for example, you have a file called names.lst that contains filenames and another file called dir.cmd that contains linker directives, you could enter:
cl6x --run_linker names.lst dir.cmd
One command file can call another command file; this type of nesting is limited to 16 levels. If a command file calls another command file as input, this statement must be the last statement in the calling command file.
Blanks and blank lines are insignificant in a command file except as delimiters. This also applies to the format of linker directives in a command file. Command File With Linker Directives shows a sample command file that contains linker directives.
a.obj b.obj c.obj /* Input filenames */
--output_file=prog.out /* Options */
--map_file=prog.map
MEMORY /* MEMORY directive */
{
FAST_MEM: origin = 0x0100 length = 0x0100
SLOW_MEM: origin = 0x7000 length = 0x1000
}
SECTIONS /* SECTIONS directive */
{
.text: > SLOW_MEM
.data: > SLOW_MEM
.bss: > FAST_MEM
}
For more information, see Section 9.6.4 for the MEMORY directive, and Section 9.6.5 for the SECTIONS directive.