You copied the Doc URL to your clipboard.

ARM Compiler armlink User Guide : Preprocessing of a scatter file

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 #! armclang --target=arm-arm-none-eabi -march=armv8-a -E -x c. This passes the scatter file through the armclang 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:

#! armclang --target=arm-arm-none-eabi -march=armv8-a -E -x c
#define ADDRESS 0x20000000
#include "include_file_1.h"


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 armclang -E

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

  • The same location as armlink.

  • The PATH locations.

armclang 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 armclang or armclang.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 armclang.exe is considered the same as armclang. Executable names are case insensitive, so ARMCLANG is considered the same as armclang. 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.