Linker Command File Preprocessing (--disable_pp, --define and --undefine Options)

The linker preprocesses linker command files using a standard C preprocessor. Therefore, the command files can contain well-known preprocessing directives such as #define, #include, and #if / #endif.

Three linker options control the preprocessor:

--disable_pp Disables preprocessing for command files
--define=name[=val] Predefines name as a preprocessor macro
--undefine=name Removes the macro name

The compiler has --define and --undefine options with the same meanings. However, the linker options are distinct; only --define and --undefine options specified after --run_linker are passed to the linker. For example:

cl6x --define=FOO=1 main.c --run_linker --define=BAR=2 lnk.cmd

The linker sees only the --define for BAR; the compiler only sees the --define for FOO.

When one command file #includes another, preprocessing context is carried from parent to child in the usual way (that is, macros defined in the parent are visible in the child). However, when a command file is invoked other than through #include, either on the command line or by the typical way of being named in another command file, preprocessing context is not carried into the nested file. The exception to this is --define and --undefine options, which apply globally from the point they are encountered. For example:

--define GLOBAL #define LOCAL #include "incfile.cmd" /* sees GLOBAL and LOCAL */ nestfile.cmd /* only sees GLOBAL */

Two cautions apply to the use of --define and --undefine in command files. First, they have global effect as mentioned above. Second, since they are not actually preprocessing directives themselves, they are subject to macro substitution, probably with unintended consequences. This effect can be defeated by quoting the symbol name. For example:

--define MYSYM=123 --undefine MYSYM /* expands to --undefine 123 (!) */ --undefine "MYSYM" /* ahh, that's better */

The linker uses the same search paths to find #include files as it does to find libraries. That is, #include files are searched in the following places:

  1. If the #include file name is in quotes (rather than <brackets>), in the directory of the current file
  2. In the list of directories specified with --Iibrary options or environment variables (see Section 8.4.16)

There are two exceptions: relative pathnames (such as "../name") always search the current directory; and absolute pathnames (such as "/usr/tools/name") bypass search paths entirely.

The linker provides the built-in macro definitions listed in Table 8-11. The availability of these macros within the linker is determined by the command-line options used, not the build attributes of the files being linked. If these macros are not set as expected, confirm that your project's command line uses the correct compiler option settings.

Table 8-11 Predefined C6000 Macro Names

Macro Name Description
_ _DATE_ _ Expands to the compilation date in the form mmm dd yyyy
_ _FILE_ _ Expands to the current source filename
_ _TI_COMPILER_VERSION_ _ Defined to a 7-9 digit integer, depending on if X has 1, 2, or 3 digits. The number does not contain a decimal. For example, version 3.2.1 is represented as 3002001. The leading zeros are dropped to prevent the number being interpreted as an octal.
_ _TI_EABI_ _ Defined to 1 if EABI is enabled; otherwise, it is undefined.
_ _TIME_ _ Expands to the compilation time in the form "hh:mm:ss"
__TMS320C6X__ Always defined
__TMS320C6600__ Defined to 1 if --silicon_version=6600; otherwise it is undefined.
__TMS320C6740__ Defined to 1 if --silicon_version=6740; otherwise it is undefined.
__TMS320C64_PLUS__ Defined to 1 if --silicon_version=6400+; otherwise it is undefined.
__TMS320C6400_PLUS__ Defined to 1 if --silicon_version=6400+; otherwise it is undefined; an alternate macro for __TMS320C64_PLUS__
__DSBT__ Defined to 1 if --dsbt is specified (to use Dynamic Segment Base Table); otherwise it is undefined.