7.11 Preprocessing of a scatter file

You can pass a scatter file through a C preprocessor. This permits access to all the features of the C preprocessor.

Use the first line in the scatter file to specify a preprocessor command that the linker invokes to process the file. The command is of the form:

#! preprocessor [pre_processor_flags]

Most typically the command is #! armcc -E. This passes the scatter file through the armcc preprocessor.

You can:

  • Add preprocessing directives to the top of the scatter file.

  • Use simple expression evaluation in the scatter file.

For example, a scatter file, file.scat, might contain:

#! armcc -E

        
#define ADDRESS 0x20000000
#include "include_file_1.h"

LR1 ADDRESS
{
    …
}

The linker parses the preprocessed scatter file and treats the directives as comments.

You can also use preprocessing of a scatter file in conjunction with the --predefine command-line option. For this example:

  1. Modify file.scat to delete the directive #define ADDRESS 0x20000000.

  2. Specify the command:

    armlink --predefine="-DADDRESS=0x20000000" --scatter=file.scat

Default behavior for armcc -E

armlink behaves in the same way as armcc when invoking other ARM tools. It searches for the armcc binary in the following order:

  • The same location as armlink.

  • The PATH locations.

armcc is invoked with the option -Iscatter_file_path so that any relative #includes work. The linker only adds this option if the full name of the preprocessor tool given is armcc or armcc.exe. This means that if an absolute path or a relative path is given, the linker does not give the -Iscatter_file_path option to the preprocessor. This also happens with the --cpu option.

On Windows, .exe suffixes are handled, so armcc.exe is considered the same as armcc. Executable names are case insensitive, so ARMCC is considered the same as armcc. The portable way to write scatter file preprocessing lines is to use correct capitalization, and omit the .exe suffix.

Using other preprocessors

You must ensure that the preprocessing command line is appropriate for execution on the host system. This means:

  • The string must be correctly quoted for the host system. The portable way to do this is to use double-quotes.

  • Single quotes and escaped characters are not supported and might not function correctly.

  • The use of a double-quote character in a path name is not supported and might not work.

These rules also apply to any strings passed with the --predefine option.

All preprocessor executables must accept the -o file option to mean output to file and accept the input as a filename argument on the command line. These options are automatically added to the user command line by armlink. Any options to redirect preprocessing output in the user-specified command line are not supported.

Non-ConfidentialPDF file icon PDF versionARM DUI0474M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.