ARM Optimizing
C/C++ Compiler
v16.12.0.STS User's Guide
SPNU151N - REVISED DECEMBER 2016
2 Using the C/C++ Compiler
The compiler translates your source program into machine language object code that the ARM can execute. Source code must be compiled, assembled, and linked to create an executable object file. All of these steps are executed at once by using the compiler.
2.1 About the Compiler
The compiler lets you compile, optimize, assemble, and optionally link in one step. The compiler performs the following steps on one or more source modules:
- The compiler accepts C/C++ source code and assembly code. It produces object code.
- The linker combines object files to create an executable object file. The link step is optional, so you can compile and assemble many modules independently and link them later. See Section 4 for information about linking the files.
You can compile C, C++, and assembly files in a single command. The compiler uses the filename extensions to distinguish between different file types. See Section 2.3.9 for more information.
NOTE
Invoking the LinkerBy default, the compiler does not invoke the linker. You can invoke the linker by using the --run_linker (-z)compiler option. See Section 4.1.1 for details.
For a complete description of the assembler and the linker, see the ARM Assembly Language Tools User's Guide.
2.2 Invoking the C/C++ Compiler
To invoke the compiler, enter:
armcl [options] [filenames] [--run_linker [link_options] object files]] |
armcl | Command that runs the compiler and the assembler. |
options | Options that affect the way the compiler processes input files. The options are listed in Table 2-7 through Table 2-28. |
filenames | One or more C/C++ source files and assembly language source files. |
--run_linker (-z) | Option that invokes the linker. The --run_linker option's short form is -z. See Section 4 for more information. |
link_options | Options that control the linking process. |
object files | Names of the object files for the linking process. |
The arguments to the compiler are of three types:
- Compiler options
- Link options
- Filenames
The --run_linker option indicates linking is to be performed. If the --run_linker option is used, any compiler options must precede the --run_linker option, and all link options must follow the --run_linker option.
Source code filenames must be placed before the --run_linker option. Additional object file filenames can be placed after the --run_linker option.
For example, if you want to compile two files named symtab.c and file.c, assemble a third file named seek.asm, and link to create an executable program called myprogram.out, you will enter:
armcl symtab.c file.c seek.asm --run_linker --library=lnk.cmd
--output_file=myprogram.out
2.3 Changing the Compiler's Behavior with Options
Options control the operation of the compiler. This section provides a description of option conventions and an option summary table. It also provides detailed descriptions of the most frequently used options, including options used for type-checking and assembling.
For a help screen summary of the options, enter armcl with no parameters on the command line.
The following apply to the compiler options:
- There are typically two ways of specifying a given option. The "long form" uses a two hyphen prefix and is usually a more descriptive name. The "short form" uses a single hyphen prefix and a combination of letters and numbers that are not always intuitive.
- Options are usually case sensitive.
- Individual options cannot be combined.
- An option with a parameter should be specified with an equal sign before the parameter to clearly associate the parameter with the option. For example, the option to undefine a constant can be expressed as --undefine=name. Likewise, the option to specify the maximum amount of optimization can be expressed as -O=3. You can also specify a parameter directly after certain options, for example -O3 is the same as -O=3. No space is allowed between the option and the optional parameter, so -O 3 is not accepted.
- Files and options except the --run_linker option can occur in any order. The --run_linker option must follow all compiler options and precede any linker options.
You can define default options for the compiler by using the TI_ARM_C_OPTION environment variable. For a detailed description of the environment variable, see Section 2.4.1.
Table 2-7 through Table 2-28 summarize all options (including link options). Use the references in the tables for more complete descriptions of the options.
Table 2-1 Processor Options
Option | Alias | Effect | Section |
---|---|---|---|
--silicon_version={ 4 | 5e | 6 | 6M0 | 7A8 | 7M3 | 7M4 | 7R4 | 7R5 } | -mv | Selects processor version: ARM V4 (ARM7), ARM V5e (ARM9E), ARM V6 (ARM11), ARM V6M0 (Cortex-M0), ARM V7A8 (Cortex-A8), ARM V7M3 (Cortex-M3), ARM V7M4 (Cortex-M4), ARM V7R4 (Cortex-R4), or ARM V7R5 (Cortex-R5). The default is ARM V4. | Section 2.3.4 |
--code_state={ 16 | 32 } | Designates the ARM compilation mode. | Section 2.3.4 | |
--float_support={vfpv3 | vfpv3d16 | fpalib |vfplib | fpv4spd16 } | Generates vector floating-point (VFP) coprocessor instructions. | Section 2.14 | |
--little_endian or --endian={ big | little } | -me | Designates little-endian code. The default is big-endian. | Section 2.3.4 |
Table 2-2 Optimization Options(1)
Option | Alias | Effect | Section |
---|---|---|---|
--opt_level=off | Disables all optimization. | Section 3.1 | |
--opt_level=n | -On | Level 0 (-O0) optimizes register usage only. Level 1 (-O1) uses Level 0 optimizations and optimizes locally. Level 2 (-O2) uses Level 1 optimizations and optimizes globally. Level 3 (-O3) uses Level 2 optimizations and optimizes the file (default). () Level 4 (-O4) uses Level 3 optimizations and performs link-time optimization. () |
Section 3.1 , Section 3.2, Section 3.4 |
--opt_for_speed[=n] | -mf | Controls the tradeoff between size and speed (0-5 range). If this option is specified without n, the default value is 4. If this option is not specified, the default setting is 1. | Section 3.12 |
--fp_mode={relaxed|strict} | Enables or disables relaxed floating-point mode. | Section 2.3.3 | |
--fp_reassoc={on|off} | Enables or disables the reassociation of floating-point arithmetic. | Section 2.3.3 | |
--sat_reassoc={on|off} | Enables or disables the reassociation of saturating arithmetic. Default is --sat_reassoc=off. | Section 2.3.3 |
Table 2-3 Advanced Optimization Options(1)
Option | Alias | Effect | Section |
---|---|---|---|
--auto_inline=[size] | -oi | Sets automatic inlining size (--opt_level=3 only). If size is not specified, the default is 1. | Section 3.9 |
--call_assumptions=n | -opn | Level 0 (-op0) specifies that the module contains functions and variables that are called or modified from outside the source code provided to the compiler. Level 1 (-op1) specifies that the module contains variables modified from outside the source code provided to the compiler but does not use functions called from outside the source code. Level 2 (-op2) specifies that the module contains no functions or variables that are called or modified from outside the source code provided to the compiler (default). Level 3 (-op3) specifies that the module contains functions that are called from outside the source code provided to the compiler but does not use variables modified from outside the source code. |
Section 3.3.1 |
--gen_opt_info=n | -onn | Level 0 (-on0) disables the optimization information file. Level 1 (-on2) produces an optimization information file. Level 2 (-on2) produces a verbose optimization information file. |
Section 3.2.1 |
--optimizer_interlist | -os | Interlists optimizer comments with assembly statements. | Section 3.10 |
--program_level_compile | -pm | Combines source files to perform program-level optimization. | Section 3.3 |
--aliased_variables | -ma | Indicates that a specific aliasing technique is used. | Section 3.7 |
Table 2-4 Debug Options
Option | Alias | Effect | Section |
---|---|---|---|
--symdebug:dwarf | -g | Default behavior. Enables symbolic debugging. The generation of debug information no longer impacts optimization. Therefore, generating debug information is enabled by default. If you explicitly use the -g option but do not specify an optimization level, no optimization is performed. | Section 2.3.5 Section 3.11 |
--symdebug:none | Disables all symbolic debugging. | Section 2.3.5 Section 3.11 |
|
--symdebug:skeletal | (Deprecated; has no effect.) |
Table 2-5 Include Options
Option | Alias | Effect | Section |
---|---|---|---|
--include_path=directory | -I | Adds the specified directory to the #include search path. | Section 2.5.2.1 |
--preinclude=filename | Includes filename at the beginning of compilation. | Section 2.3.3 |
Table 2-6 ULP Advisor Options
Option | Alias | Effect | Section |
---|---|---|---|
--advice:power[={all|none|rulespec}] | Enables checking the specified ULP Advisor rules. (Default is all.) | Section 2.3.3 | |
--advice:power_severity={error| warning|remark|suppress} |
Sets the diagnostic severity for ULP Advisor rules. | Section 2.3.3 |
Table 2-7 Control Options
Option | Alias | Effect | Section |
---|---|---|---|
--compile_only | -c | Disables linking (negates --run_linker). | Section 4.1.3 |
--help | -h | Prints (on the standard output device) a description of the options understood by the compiler. | Section 2.3.2 |
--run_linker | -z | Causes the linker to be invoked from the compiler command line. | Section 2.3.2 |
--skip_assembler | -n | Compiles C/C++ source file, producing an assembly language output file. The assembler is not run and no object file is produced. | Section 2.3.2 |
Table 2-8 Language Options
Option | Alias | Effect | Section |
---|---|---|---|
--c89 | Processes C files according to the ISO C89 standard. | Section 5.15 | |
--c99 | Processes C files according to the ISO C99 standard. | Section 5.15 | |
--c++03 | Processes C++ files according to the ISO C++03 standard. | Section 5.15 | |
--cpp_default | -fg | Processes all source files with a C extension as C++ source files. | Section 2.3.7 |
--enum_type={int|packed} | Designates the underlying type of an enumeration type. | Section 2.3.4 | |
--exceptions | Enables C++ exception handling. | Section 5.7 | |
--extern_c_can_throw | Allow extern C functions to propagate exceptions (EABI only). | -- | |
--float_operations_allowed={none| all|32|64} | Restricts the types of floating point operations allowed. | Section 2.3.3 | |
--gen_parser_listing | -pl | Generates a raw listing file (.rl). | Section 2.10 |
--gen_cross_reference | -px | Generates a cross-reference listing file (.crl). | Section 2.9 |
--plain_char={signed|unsigned} | -mc | Specifies how to treat plain chars, default is unsigned. | Section 2.3.4 |
--relaxed_ansi | -pr | Enables relaxed mode; ignores strict ISO violations. This is on by default. To disable this mode, use the --strict_ansi option. | Section 5.15.2 |
--rtti | -rtti | Enables C++ run-time type information (RTTI). | –- |
--strict_ansi | -ps | Enables strict ANSI/ISO mode (for C/C++, not for K&R C). In this mode, language extensions that conflict with ANSI/ISO C/C++ are disabled. In strict ANSI/ISO mode, most ANSI/ISO violations are reported as errors. Violations that are considered discretionary may be reported as warnings instead. | Section 5.15.2 |
--wchar_t={32|16} | Sets the size of the C/C++ type wchar_t. Default is 16 bits. | Section 2.3.4 |
Table 2-9 Parser Preprocessing Options
Option | Alias | Effect | Section |
---|---|---|---|
--preproc_dependency[=filename] | -ppd | Performs preprocessing only, but instead of writing preprocessed output, writes a list of dependency lines suitable for input to a standard make utility. | Section 2.5.8 |
--preproc_includes[=filename] | -ppi | Performs preprocessing only, but instead of writing preprocessed output, writes a list of files included with the #include directive. | Section 2.5.9 |
--preproc_macros[=filename] | -ppm | Performs preprocessing only. Writes list of predefined and user-defined macros to a file with the same name as the input but with a .pp extension. | Section 2.5.10 |
--preproc_only | -ppo | Performs preprocessing only. Writes preprocessed output to a file with the same name as the input but with a .pp extension. | Section 2.5.4 |
--preproc_with_comment | -ppc | Performs preprocessing only. Writes preprocessed output, keeping the comments, to a file with the same name as the input but with a .pp extension. | Section 2.5.6 |
--preproc_with_compile | -ppa | Continues compilation after preprocessing with any of the -pp<x> options that normally disable compilation. | Section 2.5.5 |
--preproc_with_line | -ppl | Performs preprocessing only. Writes preprocessed output with line-control information (#line directives) to a file with the same name as the input but with a .pp extension. | Section 2.5.7 |
Table 2-10 Predefined Symbols Options
Option | Alias | Effect | Section |
---|---|---|---|
--define=name[=def] | -D | Predefines name. | Section 2.3.2 |
--undefine=name | -U | Undefines name. | Section 2.3.2 |
Table 2-11 Diagnostic Message Options
Option | Alias | Effect | Section |
---|---|---|---|
--compiler_revision | Prints out the compiler release revision and exits. | -- | |
--diag_error=num | -pdse | Categorizes the diagnostic identified by num as an error. | Section 2.7.1 |
--diag_remark=num | -pdsr | Categorizes the diagnostic identified by num as a remark. | Section 2.7.1 |
--diag_suppress=num | -pds | Suppresses the diagnostic identified by num. | Section 2.7.1 |
--diag_warning=num | -pdsw | Categorizes the diagnostic identified by num as a warning. | Section 2.7.1 |
--diag_wrap={on|off} | Wrap diagnostic messages (default is on). Note that this command-line option cannot be used within the Code Composer Studio IDE. | ||
--display_error_number | -pden | Displays a diagnostic's identifiers along with its text. Note that this command-line option cannot be used within the Code Composer Studio IDE. | Section 2.7.1 |
--emit_warnings_as_errors | -pdew | Treat warnings as errors. | Section 2.7.1 |
--gen_func_info_listing | Generate user information file (.aux). | -- | |
--issue_remarks | -pdr | Issues remarks (non-serious warnings). | Section 2.7.1 |
--no_warnings | -pdw | Suppresses diagnostic warnings (errors are still issued). | Section 2.7.1 |
--quiet | -q | Suppresses progress messages (quiet). | -- |
--section_sizes={on|off} | Generates section size information, including sizes for sections containing executable code and constants, constant or initialized data (global and static variables), and uninitialized data. (Default is off if this option is not included on the command line. Default is on if this option is used with no value specified.) | Section 2.7.1 | |
--set_error_limit=num | -pdel | Sets the error limit to num. The compiler abandons compiling after this number of errors. (The default is 100.) | Section 2.7.1 |
--super_quiet | Super quiet mode. | -- | |
--tool_version | -version | Displays version number for each tool. | -- |
--verbose | Display banner and function progress information. | -- | |
--verbose_diagnostics | -pdv | Provides verbose diagnostic messages that display the original source with line-wrap. Note that this command-line option cannot be used within the Code Composer Studio IDE. | Section 2.7.1 |
--write_diagnostics_file | Generates a diagnostic message information file. Compiler only option. Note that this command-line option cannot be used within the Code Composer Studio IDE. | Section 2.7.1 |
Table 2-12 Run-Time Model Options
Option | Alias | Effect | Section |
---|---|---|---|
--common={on|off} | On by default when compiling with EABI. When on, uninitialized file scope variables are emitted as common symbols. When off, common symbols are not created. | Section 2.3.4 | |
--embedded_constants={on|off} | Controls whether compiler embeds constants in functions. | Section 2.3.4 | |
--gen_data_subsections={on|off} | Place all aggregate data (arrays, structs, and unions) into subsections. This gives the linker more control over removing unused data during the final link step. The default is on. | Section 4.2.2 | |
--global_register={r5|r6|r9} | -rr | Disallows use of rx=[5,6,9] by the compiler. | Section 2.3.4 |
-neon | Enables support for the Cortex-A8 Neon SIMD instruction set. | Section 2.3.4 | |
--printf_support={nofloat|full| minimal} |
Enables support for smaller, limited versions of the printf function family (sprintf, fprintf, etc.) and the scanf function family (sscanf, fscanf, etc.) run-time-support functions. | Section 2.3.3 | |
--ramfunc={on|off} | If set to on, specifies that all functions should be placed in the .TI.ramfunc section, which is placed in RAM. | Section 2.3.4 | |
--stack_overflow_check | -mo | Enables dynamic stack overflow checking. | Section 2.3.4 |
--symdebug:dwarf_version=2|3|4 | Specifies the DWARF format version. | Section 2.3.5 | |
--unaligned_access={on|off} | Controls generation of unaligned accesses. | Section 2.3.4 | |
--use_dead_funcs_list [=fname] | Places each function listed in the file in a separate section. | Section 2.3.4 |
Table 2-13 Entry/Exit Hook Options
Option | Alias | Effect | Section |
---|---|---|---|
--entry_hook[=name] | Enables entry hooks. | Section 2.15 | |
--entry_parm={none|name| address} |
Specifies the parameters to the function to the --entry_hook option. | Section 2.15 | |
--exit_hook[=name] | Enables exit hooks. | Section 2.15 | |
--exit_parm={none|name|address} | Specifies the parameters to the function to the --exit_hook option. | Section 2.15 | |
--remove_hooks_when_inlining | Removes entry/exit hooks for auto-inlined functions. | Section 2.15 |
Table 2-14 Feedback Options
Option | Alias | Effect | Section |
---|---|---|---|
--analyze={codecov|callgraph} | Generate analysis info from profile data. | Section 3.6.2.2 | |
--analyze_only | Only generate analysis. | Section 3.6.2.2 | |
--gen_profile_info | Generates instrumentation code to collect profile information. | Section 3.5.1.3 | |
--use_profile_info=file1[, file2,...] | Specifies the profile information file(s). | Section 3.5.1.3 |
Table 2-15 Assembler Options
Option | Alias | Effect | Section |
---|---|---|---|
--keep_asm | -k | Keeps the assembly language (.asm) file. | Section 2.3.11 |
--asm_listing | -al | Generates an assembly listing file. | Section 2.3.11 |
--c_src_interlist | -ss | Interlists C source and assembly statements. |
Section 2.12
Section 3.10 |
--src_interlist | -s | Interlists optimizer comments (if available) and assembly source statements; otherwise interlists C and assembly source statements. | Section 2.3.2 |
--absolute_listing | -aa | Enables absolute listing. | Section 2.3.11 |
--asm_define=name[=def] | -ad | Sets the name symbol. | Section 2.3.11 |
--asm_dependency | -apd | Performs preprocessing; lists only assembly dependencies. | Section 2.3.11 |
--asm_includes | -api | Performs preprocessing; lists only included #include files. | Section 2.3.11 |
--asm_undefine=name | -au | Undefines the predefined constant name. | Section 2.3.11 |
--code_state={16|32} | Begins assembling instructions as 16- or 32-bit instructions. | Section 2.3.11 | |
--asm_listing_cross_reference | -ax | Generates the cross-reference file. | Section 2.3.11 |
--include_file=filename | -ahi | Includes the specified file for the assembly module. | Section 2.3.11 |
Table 2-16 File Type Specifier Options
Option | Alias | Effect | Section |
---|---|---|---|
--asm_file=filename | -fa | Identifies filename as an assembly source file regardless of its extension. By default, the compiler and assembler treat .asm files as assembly source files. | Section 2.3.7 |
--c_file=filename | -fc | Identifies filename as a C source file regardless of its extension. By default, the compiler treats .c files as C source files. | Section 2.3.7 |
--cpp_file=filename | -fp | Identifies filename as a C++ file, regardless of its extension. By default, the compiler treats .C, .cpp, .cc and .cxx files as a C++ files. | Section 2.3.7 |
--obj_file=filename | -fo | Identifies filename as an object code file regardless of its extension. By default, the compiler and linker treat .obj files as object code files. | Section 2.3.7 |
Table 2-17 Directory Specifier Options
Option | Alias | Effect | Section |
---|---|---|---|
--abs_directory=directory | -fb | Specifies an absolute listing file directory. By default, the compiler uses the .obj directory. | Section 2.3.10 |
--asm_directory=directory | -fs | Specifies an assembly file directory. By default, the compiler uses the current directory. | Section 2.3.10 |
--list_directory=directory | -ff | Specifies an assembly listing file and cross-reference listing file directory By default, the compiler uses the .obj directory. | Section 2.3.10 |
--obj_directory=directory | -fr | Specifies an object file directory. By default, the compiler uses the current directory. | Section 2.3.10 |
--output_file=filename | -fe | Specifies a compilation output file name; can override --obj_directory. | Section 2.3.10 |
--pp_directory=dir | Specifies a preprocessor file directory. By default, the compiler uses the current directory. | Section 2.3.10 | |
--temp_directory=directory | -ft | Specifies a temporary file directory. By default, the compiler uses the current directory. | Section 2.3.10 |
Table 2-18 Default File Extensions Options
Option | Alias | Effect | Section |
---|---|---|---|
--asm_extension=[.]extension | -ea | Sets a default extension for assembly source files. |
Section 2.3.9 |
--c_extension=[.]extension | -ec | Sets a default extension for C source files. | Section 2.3.9 |
--cpp_extension=[.]extension | -ep | Sets a default extension for C++ source files. | Section 2.3.9 |
--listing_extension=[.]extension | -es | Sets a default extension for listing files. | Section 2.3.9 |
--obj_extension=[.]extension | -eo | Sets a default extension for object files. | Section 2.3.9 |
Table 2-19 Command Files Options
Option | Alias | Effect | Section |
---|---|---|---|
--cmd_file=filename | -@ | Interprets contents of a file as an extension to the command line. Multiple -@ instances can be used. | Section 2.3.2 |
Table 2-20 MISRA-C 2004 Options
Option | Alias | Effect | Section |
---|---|---|---|
--check_misra[={all|required| advisory|none|rulespec}] |
Enables checking of the specified MISRA-C:2004 rules. Default is all. | Section 2.3.3 | |
--misra_advisory={error|warning| remark|suppress} |
Sets the diagnostic severity for advisory MISRA-C:2004 rules. | Section 2.3.3 | |
--misra_required={error|warning| remark|suppress} |
Sets the diagnostic severity for required MISRA-C:2004 rules. | Section 2.3.3 |
2.3.1 Linker Options
The following tables list the linker options. See Section 4 of this document and the ARM Assembly Language Tools User's Guide for details on these options.
Table 2-21 Linker Basic Options
Option | Alias | Description |
---|---|---|
--run_linker | -z | Enables linking. |
--output_file=file | -o | Names the executable output file. The default filename is a .out file. |
--map_file=file | -m | Produces a map or listing of the input and output sections, including holes, and places the listing in file. |
--stack_size=size | [-]-stack | Sets C system stack size to sizebytes and defines a global symbol that specifies the stack size. Default = 2K bytes. |
--heap_size=size | [-]-heap | Sets heap size (for the dynamic memory allocation in C) to sizebytes and defines a global symbol that specifies the heap size. Default = 2K bytes. |
Table 2-22 File Search Path Options
Option | Alias | Description |
---|---|---|
--library=file | -l | Names an archive library or link command file as linker input. |
--search_path=pathname | -I |
Alters library-search algorithms to look in a directory named with pathname before looking in the default location. This option must appear before the --library option. |
--priority | -priority | Satisfies unresolved references by the first library that contains a definition for that symbol. |
--reread_libs | -x | Forces rereading of libraries, which resolves back references. |
--disable_auto_rts | Disables the automatic selection of a run-time-support library. See Section 4.3.1.1. |
Table 2-23 Command File Preprocessing Options
Option | Alias | Description |
---|---|---|
--define=name=value | Predefines name as a preprocessor macro. | |
--undefine=name | Removes the preprocessor macro name. | |
--disable_pp | Disables preprocessing for command files. |
Table 2-24 Diagnostic Message Options
Option | Alias | Description |
---|---|---|
--diag_error=num | Categorizes the diagnostic identified by num as an error. | |
--diag_remark=num | Categorizes the diagnostic identified by num as a remark. | |
--diag_suppress=num | Suppresses the diagnostic identified by num. | |
--diag_warning=num | Categorizes the diagnostic identified by num as a warning. | |
--display_error_number | Displays a diagnostic's identifiers along with its text. | |
--emit_warnings_as_errors | -pdew | Treat warnings as errors. |
--issue_remarks | Issues remarks (non-serious warnings). | |
--no_demangle | Disables demangling of symbol names in diagnostic messages. | |
--no_warnings | Suppresses diagnostic warnings (errors are still issued). | |
--set_error_limit=count | Sets the error limit to count. The linker abandons linking after this number of errors. (The default is 100.) | |
--verbose_diagnostics | Provides verbose diagnostic messages that display the original source with line-wrap. | |
--warn_sections | -w | Displays a message when an undefined output section is created. |
Table 2-25 Linker Output Options
Option | Alias | Description |
---|---|---|
--absolute_exe | -a | Produces an absolute, executable object file. This is the default; if neither --absolute_exe nor --relocatable is specified, the linker acts as if --absolute_exe were specified. |
--ecc:data_error | Inject specified errors into the output file for testing. | |
--ecc:ecc_error | Inject specified errors into the Error Correcting Code (ECC) for testing. | |
--generate_dead_funcs_list | Writes a list of the dead functions that were removed by the linker to file fname. | |
--mapfile_contents=attribute | Controls the information that appears in the map file. | |
--relocatable | -r | Produces a nonexecutable, relocatable output object file. |
--rom | Creates a ROM object. | |
--run_abs | -abs | Produces an absolute listing file. |
--xml_link_info=file | Generates a well-formed XML file containing detailed information about the result of a link. |
Table 2-26 Symbol Management Options
Option | Alias | Description |
---|---|---|
--entry_point=symbol | -e | Defines a global symbol that specifies the primary entry point for the executable object file. |
--globalize=pattern | Changes the symbol linkage to global for symbols that match pattern. | |
--hide=pattern | Hides symbols that match the specified pattern. | |
--localize=pattern | Make the symbols that match the specified pattern local. | |
--make_global=symbol | -g | Makes symbol global (overrides -h). |
--make_static | -h | Makes all global symbols static. |
--no_symtable | -s | Strips symbol table information and line number entries from the executable object file. |
--retain | Retains a list of sections that otherwise would be discarded. | |
--scan_libraries | -scanlibs | Scans all libraries for duplicate symbol definitions. |
--symbol_map=refname=defname | Specifies a symbol mapping; references to the refname symbol are replaced with references to the defname symbol. The --symbol_map option is now supported when used with --opt_level=4. |
|
--undef_sym=symbol | -u | Adds symbol to the symbol table as an unresolved symbol. |
--unhide=pattern | Excludes symbols that match the specified pattern from being hidden. |
Table 2-27 Run-Time Environment Options
Option | Alias | Description |
---|---|---|
--arg_size=size | --args | Reserve size bytes for the argc/argv memory area. |
--cinit_hold_wdt={on|off} | Link in an RTS auto-initialization routine that either holds (on) or does not hold (off) the watchdog timer during cinit auto-initialization. See Section 4.3.3. | |
-be32 | Forces the linker to generate BE-32 object code. | |
-be8 | Forces the linker to generate BE-8 object code. | |
--cinit_compression[=compression_kind] | Specifies the type of compression to apply to the C auto initialization data. The default if this option is specified with no kind is lzss for Lempel-Ziv-Storer-Szymanski compression. | |
--copy_compression[=compression_kind] | Compresses data copied by linker copy tables. Default is lzss. | |
--fill_value=value | -f | Sets default fill value for holes within output sections |
--ram_model | -cr | Initializes variables at load time. |
--rom_model | -c | Autoinitializes variables at run time. |
--trampolines[=off|on] | Generates far call trampolines (argument is optional, is "on" by default). |
Table 2-28 Miscellaneous Options
Option | Alias | Description |
---|---|---|
--compress_dwarf[=off|on] | Aggressively reduces the size of DWARF information from input object files. Default is on. | |
--linker_help | [-]-help | Displays information about syntax and available options. |
--minimize_trampolines | Places sections to minimize number of far trampolines required. | |
--preferred_order=function | Prioritizes placement of functions. | |
--strict_compatibility[=off|on] | Performs more conservative and rigorous compatibility checking of input object files. Default is on. | |
--trampoline_min_spacing | When trampoline reservations are spaced more closely than the specified limit, tries to make them adjacent. | |
--unused_section_elimination[=off|on] | Eliminates sections that are not needed in the executable module. Default is on. | |
--zero_init=[off|on] | Controls preinitialization of uninitialized variables. Default is on. |
2.3.2 Frequently Used Options
Following are detailed descriptions of options that you will probably use frequently:
--c_src_interlist | Invokes the interlist feature, which interweaves original C/C++ source with compiler-generated assembly language. The interlisted C statements may appear to be out of sequence. You can use the interlist feature with the optimizer by combining the --optimizer_interlist and --c_src_interlist options. See Section 3.10. The --c_src_interlist option can have a negative performance and/or code size impact. |
--cmd_file=filename | Appends the contents of a file to the option set. You can use this option to avoid limitations on command line length or C style comments imposed by the host operating system. Use a # or ; at the beginning of a line in the command file to include comments. You can also include comments by delimiting them with /* and */. To specify options, surround hyphens with quotation marks. For example, "--"quiet. You can use the --cmd_file option multiple times to specify multiple files. For instance, the following indicates that file3 should be compiled as source and file1 and file2 are --cmd_file files: armcl --cmd_file=file1 --cmd_file=file2 file3 |
--compile_only | Suppresses the linker and overrides the --run_linker option, which specifies linking. The --compile_only option's short form is -c. Use this option when you have --run_linker specified in the TI_ARM_C_OPTION environment variable and you do not want to link. See Section 4.1.3. |
--define=name[=def] | Predefines the constant name for the preprocessor. This is equivalent to inserting #define name def at the top of each C source file. If the optional[=def] is omitted, the name is set to 1. The --define option's short form is -D. If you want to define a quoted string and keep the quotation marks, do one of the following:
|
--gen_func_info_listing | Generates a user information file with a .aux file extension. The file contains linker call graph information on a per-file level. |
--help | Displays the syntax for invoking the compiler and lists available options. If the --help option is followed by another option or phrase, detailed information about the option or phrase is displayed. For example, to see information about debugging options use --help debug. |
--include_path=directory | Adds directory to the list of directories that the compiler searches for #include files. The --include_path option's short form is -I. You can use this option several times to define several directories; be sure to separate the --include_path options with spaces. If you do not specify a directory name, the preprocessor ignores the --include_path option. See Section 2.5.2.1. |
--keep_asm | Retains the assembly language output from the compiler or assembly optimizer. Normally, the compiler deletes the output assembly language file after assembly is complete. The --keep_asm option's short form is -k. |
--quiet | Suppresses banners and progress information from all the tools. Only source filenames and error messages are output. The --quiet option's short form is -q. |
--run_linker | Runs the linker on the specified object files. The --run_linker option and its parameters follow all other options on the command line. All arguments that follow --run_linker are passed to the linker. The --run_linker option's short form is -z. See Section 4.1. |
--skip_assembler | Compiles only. The specified source files are compiled but not assembled or linked. The --skip_assembler option's short form is -n. This option overrides --run_linker. The output is assembly language output from the compiler. |
--src_interlist | Invokes the interlist feature, which interweaves optimizer comments or C/C++ source with assembly source. If the optimizer is invoked (--opt_level=n option), optimizer comments are interlisted with the assembly language output of the compiler, which may rearrange code significantly. If the optimizer is not invoked, C/C++ source statements are interlisted with the assembly language output of the compiler, which allows you to inspect the code generated for each C/C++ statement. The --src_interlist option implies the --keep_asm option. The --src_interlist option's short form is -s. |
--tool_version | Prints the version number for each tool in the compiler. No compiling occurs. |
--undefine=name | Undefines the predefined constant name. This option overrides any --define options for the specified constant. The --undefine option's short form is -U. |
--verbose | Displays progress information and toolset version while compiling. Resets the --quiet option. |
2.3.3 Miscellaneous Useful Options
Following are detailed descriptions of miscellaneous options:
--advice:power={all|none| rulespec} |
Enables checking code against ULP (ultra low power) Advisor rules for possible power inefficiencies. More detailed information can be found at www.ti.com/ulpadvisor. The rulespec parameter is a comma-separated list of specifiers. See Section 5.4 for details. |
--advice:power_severity={error| warning|remark|suppress} |
Sets the diagnostic severity for ULP Advisor rules. |
--check_misra={all|required| advisory|none|rulespec} |
Displays the specified amount or type of MISRA-C documentation. The rulespec parameter is a comma-separated list of specifiers. See Section 5.3 for details. |
--float_operations_allowed= {none|all|32|64} | Restricts the type of floating point operations allowed in the application. The default is all. If set to none, 32, or 64, the application is checked for operations that will be performed at runtime. For example, if --float_operations_allowed=32 is specified on the command line, the compiler issues an error if a double precision operation will be generated. This can be used to ensure that double precision operations are not accidentally introduced into an application. The checks are performed after relaxed mode optimizations have been performed, so illegal operations that are completely removed result in no diagnostic messages. |
--fp_mode={relaxed|strict} | The default floating-point mode is strict. To enable relaxed floating-point mode use the --fp_mode=relaxed option. Relaxed floating-point mode causes double-precision floating-point computations and storage to be converted to single-precision floating-point or integers where possible. This behavior does not conform with ISO, but it results in faster code, with some loss in accuracy. The following specific changes occur in relaxed mode:
|
--fp_reassoc={on|off} | Enables or disables the reassociation of floating-point arithmetic. If --fp_mode=relaxed is specified, --fp_reassoc=on is set automatically. If --strict_ansi is set, --fp_reassoc=off is set since reassociation of floating-point arithmetic is an ANSI violation. Because floating-point values are of limited precision, and because floating-point operations round, floating-point arithmetic is neither associative nor distributive. For instance, (1 + 3e100) - 3e100 is not equal to 1 + (3e100 - 3e100). If strictly following IEEE 754, the compiler cannot, in general, reassociate floating-point operations. Using --fp_reassoc=on allows the compiler to perform the algebraic reassociation, at the cost of a small amount of precision for some operations. |
--misra_advisory={error| warning|remark|suppress} |
Sets the diagnostic severity for advisory MISRA-C:2004 rules. |
--misra_required={error| warning|remark|suppress} |
Sets the diagnostic severity for required MISRA-C:2004 rules. |
--preinclude=filename | Includes the source code of filename at the beginning of the compilation. This can be used to establish standard macro definitions. The filename is searched for in the directories on the include search list. The files are processed in the order in which they were specified. |
--printf_support={full| nofloat|minimal} |
Enables support for smaller, limited versions of the printf function family (sprintf, fprintf, etc.) and the scanf function family (sscanf, fscanf, etc.) run-time-support functions. The valid values are:
There is no run-time error checking to detect if a format specifier is used for which support is not included. The --printf_support option precedes the --run_linker option, and must be used when performing the final link. |
--sat_reassoc={on|off} | Enables or disables the reassociation of saturating arithmetic. |
2.3.4 Run-Time Model Options
These options are specific to the ARM toolset. See the referenced sections for more information. ARM-specific assembler options are listed in Section 2.3.11.
The ARM compiler now supports only the Embedded Application Binary Interface (EABI) ABI, which uses the ELF object format and the DWARF debug format. If you want support for the legacy COFF ABI, please use the ARM v5.2 Code Generation Tools and refer to SPNU151J and SPNU118J for documentation.
--code_state={16|32} | Generates 16-bit Thumb code. By default, 32-bit code is generated. When Cortex-R4, Cortex-M0, Cortex-M3, or Cortex-A8 architecture support is chosen, the --code_state option generates Thumb-2 code. For details on indirect calls in 16-bit versus 32-bit code, see Section 6.11.2.2. | |
--common={on|off} | When on (the default with EABI), uninitialized file scope variables are emitted as common symbols. When off, common symbols are not created. The benefit of allowing common symbols to be created is that generated code can remove unused variables that would otherwise increase the size of the .bss section. (Uninitialized variables of a size larger than 32 bytes are separately optimized through placement in separate subsections that can be omitted from a link.) Variables cannot be common symbols if they are assigned to a section other than .bssor are defined relative to another common symbol. | |
--embedded_constants={on|off} | By default the compiler embeds constants in functions. These constants can include literals, addresses, strings, etc. This is a problem if you wants to prevent reads from a memory region that contains only executable code. To enable the generation of "execute only code", the compiler provides the --embedded_constants=[on|off] option. If the option is not specified, it is assumed to be on. The option is available on the following devices: Cortex-A8, Cortex-M3, Cortex-M4, and Cortex-R4. | |
--endian={ big | little } | Designates big- or little-endian format for the compiled code. By default, big-endian format is used. | |
--enum_type={int|packed} | Designates the underlying type of an enumeration type. The default is packed, which causes the underlying enumeration type to be the smallest integer type that accommodates the enumeration constants. Using --enum_type=int causes the underlying type to always be int. An enumeration constant with a value outside the int range generates an error. |
|
--float_support={ vfpv3 | vfpv3d16 | fpalib | vfplib | fpv4spd16 } | Generates vector floating-point (VFP) coprocessor instructions for various versions and libraries. See Section 2.14. | |
--global_register={r5|r6|r9} | Disallows use of rx=[5|6|9] by the compiler. | |
-md | Disables dual-state interworking support. See Section 6.11.1. | |
-mv={4|5e|6|6M0|7A8|7M3 |7M4|7R4|7R5} | Selects processor version: ARM V4 (ARM7), ARM V5e (ARM9E), ARM V6 (ARM11), ARM V6M0 (Cortex-M0), ARM V7A8 (Cortex-A8), ARM V7M3 (Cortex-M3), ARM V7M4 (Cortex-M4), ARM V7R4 (Cortex-R4), or ARM V7R5 (Cortex-R5). The default is ARM V4. | |
--neon | The compiler can generate code using the SIMD instructions available in the Neon extension to the version 7 ARM architecture. The optimizer attempts to vectorize source code in order to take advantage of these SIMD instructions. In order to generate vectorized SIMD Neon code, select the version 7 architecture with the -mv=7A8 option and enable Neon instruction support with the --neon option. The optimizer is used to vectorize the source code. At least level 2 optimization (--opt_level=2 or O2) is required, although level 3 (--opt_level=3) is recommended along with the --opt_for_speed option. |
|
--plain_char={signed|unsigned} | Specifies how to treat C/C++ plain char variables. Default is unsigned. | |
--ramfunc={on|off} | If set to on, specifies that all functions should be placed in the .TI.ramfunc section, which is placed in RAM. If set to off, only functions with the ramfunc function attribute are treated this way. See Section 5.16.2. Newer TI linker command files support the --ramfunc option automatically by placing functions in the .TI.ramfunc section. If you have a linker command file that does not include a section specification for the .TI.ramfunc section, you can modify the linker command file to place this section in RAM. See the ARM Assembly Language Tools User's Guide for details on section placement. |
|
--stack_overflow_check | Enables dynamic stack overflow checking. | |
--unaligned_access={on|off} | Informs the compiler that the target device supports unaligned memory accesses. Typically data is aligned to its size boundary. For instance 32-bit data is aligned on a 32-bit boundary, 16-bit data on a 16-bit boundary, and 8-bit data on an 8-bit boundary. If this option is set to on, it tells the compiler it is legal to generate load and store instructions for data that falls on an unaligned boundary (32-bit data on a 16-bit boundary). Cases where unaligned data accesses can occur include calls to memcpy() and accessing packed structs. This option is on by default for all Cortex devices. | |
--use_dead_funcs_list[=fname] | Places each function listed in the file in a separate section. The functions are placed in the fname section, if specified. This option and --generate_dead_funcs_list are not recommended within the Code Composer Studio IDE. Instead, consider using --opt_level=4, --program_level_compile, and/or --gen_func_subsections. | |
--wchar_t={32|16} | Sets the size (in bits) of the C/C++ type wchar_t. By default the compiler generates 16-bit wchar_t. 16-bit wchar_t objects are not compatible with the 32-bit wchar_t objects; an error is generated if they are combined. |
2.3.5 Symbolic Debugging and Profiling Options
The following options are used to select symbolic debugging or profiling:
--symdebug:dwarf | (Default) Generates directives that are used by the C/C++ source-level debugger and enables assembly source debugging in the assembler. The --symdebug:dwarf option's short form is -g. See Section 3.11. For more information on the DWARF debug format, see The DWARF Debugging Standard. |
--symdebug:dwarf_
version={2|3|4} |
Specifies the DWARF debugging format version (2, 3, or 4) to be generated when --symdebug:dwarf (the default) is specified. By default, the compiler generates DWARF version 3 debug information. DWARF versions 2, 3, and 4 may be intermixed safely. When DWARF 4 is used, type information is placed in the .debug_types section. At link time, duplicate type information will be removed. This method of type merging is superior to those used in DWARF 2 or 3 and will result in a smaller executable. In addition, DWARF 4 reduces the size of intermediate object files in comparison to DWARF 3. For more information on TI extensions to the DWARF language, see The Impact of DWARF on TI Object Files (SPRAAB5). |
--symdebug:none | Disables all symbolic debugging output. This option is not recommended; it prevents debugging and most performance analysis capabilities. |
--symdebug:skeletal | Deprecated. Has no effect. |
See Section 2.3.12 for a list of deprecated symbolic debugging options.
2.3.6 Specifying Filenames
The input files that you specify on the command line can be C source files, C++ source files, assembly source files, or object files. The compiler uses filename extensions to determine the file type.
Extension | File Type |
---|---|
.asm, .abs, or .s* (extension begins with s) | Assembly source |
.c | C source |
.C | Depends on operating system |
.cpp, .cxx, .cc | C++ source |
.obj .o* .dll .so | Object |
NOTE
Case Sensitivity in Filename Extensions
Case sensitivity in filename extensions is determined by your operating system. If your operating system is not case sensitive, a file with a .C extension is interpreted as a C file. If your operating system is case sensitive, a file with a .C extension is interpreted as a C++ file.
For information about how you can alter the way that the compiler interprets individual filenames, see Section 2.3.7. For information about how you can alter the way that the compiler interprets and names the extensions of assembly source and object files, see Section 2.3.10.
You can use wildcard characters to compile or assemble multiple files. Wildcard specifications vary by system; use the appropriate form listed in your operating system manual. For example, to compile all of the files in a directory with the extension .cpp, enter the following:
armcl *.cpp
NOTE
No Default Extension for Source Files is Assumed
If you list a filename called example on the command line, the compiler assumes that the entire filename is example not example.c. No default extensions are added onto files that do not contain an extension.
2.3.7 Changing How the Compiler Interprets Filenames
You can use options to change how the compiler interprets your filenames. If the extensions that you use are different from those recognized by the compiler, you can use the filename options to specify the type of file. You can insert an optional space between the option and the filename. Select the appropriate option for the type of file you want to specify:
--asm_file=filename | for an assembly language source file |
--c_file=filename | for a C source file |
--cpp_file=filename | for a C++ source file |
--obj_file=filename | for an object file |
For example, if you have a C source file called file.s and an assembly language source file called assy, use the --asm_file and --c_file options to force the correct interpretation:
armcl --c_file=file.s --asm_file=assy
You cannot use the filename options with wildcard specifications.
2.3.8 Changing How the Compiler Processes C Files
The --cpp_default option causes the compiler to process C files as C++ files. By default, the compiler treats files with a .c extension as C files. See Section 2.3.9 for more information about filename extension conventions.
2.3.9 Changing How the Compiler Interprets and Names Extensions
You can use options to change how the compiler program interprets filename extensions and names the extensions of the files that it creates. The filename extension options must precede the filenames they apply to on the command line. You can use wildcard specifications with these options. An extension can be up to nine characters in length. Select the appropriate option for the type of extension you want to specify:
--asm_extension=new extension | for an assembly language file |
--c_extension=new extension | for a C source file |
--cpp_extension=new extension | for a C++ source file |
--listing_extension=new extension | sets default extension for listing files |
--obj_extension=new extension | for an object file |
The following example assembles the file fit.rrr and creates an object file named fit.o:
armcl --asm_extension=.rrr --obj_extension=.o fit.rrr
The period (.) in the extension is optional. You can also write the example above as:
armcl --asm_extension=rrr --obj_extension=o fit.rrr
2.3.10 Specifying Directories
By default, the compiler program places the object, assembly, and temporary files that it creates into the current directory. If you want the compiler program to place these files in different directories, use the following options:
--abs_directory=directory | Specifies the destination directory for absolute listing files. The default is to use the same directory as the object file directory. For example: armcl --abs_directory=d:\abso_list |
--asm_directory=directory | Specifies a directory for assembly files. For example: armcl --asm_directory=d:\assembly |
--list_directory=directory | Specifies the destination directory for assembly listing files and cross-reference listing files. The default is to use the same directory as the object file directory. For example: armcl --list_directory=d:\listing |
--obj_directory=directory | Specifies a directory for object files. For example: armcl --obj_directory=d:\object |
--output_file=filename | Specifies a compilation output file name; can override --obj_directory . For example: armcl --output_file=transfer |
--pp_directory=directory | Specifies a preprocessor file directory for object files (default is .). For example: armcl --pp_directory=d:\preproc |
--temp_directory=directory | Specifies a directory for temporary intermediate files. For example: armcl --temp_directory=d:\temp |
2.3.11 Assembler Options
Following are assembler options that you can use with the compiler. For more information, see the ARM Assembly Language Tools User's Guide.
--absolute_listing | Generates a listing with absolute addresses rather than section-relative offsets. |
--asm_define=name[=def] | Predefines the constant name for the assembler; produces a .set directive for a constant or an .arg directive for a string. If the optional [=def] is omitted, the name is set to 1. If you want to define a quoted string and keep the quotation marks, do one of the following:
|
--asm_dependency | Performs preprocessing for assembly files, but instead of writing preprocessed output, writes a list of dependency lines suitable for input to a standard make utility. The list is written to a file with the same name as the source file but with a .ppa extension. |
--asm_includes | Performs preprocessing for assembly files, but instead of writing preprocessed output, writes a list of files included with the #include directive. The list is written to a file with the same name as the source file but with a .ppa extension. |
--asm_listing | Produces an assembly listing file. |
--asm_undefine=name | Undefines the predefined constant name. This option overrides any --asm_define options for the specified name. |
--code_state={16|32} | Generates 16-bit Thumb code. By default, 32-bit code is generated. When Cortex-R4, Cortex-M0, Cortex-M3, or Cortex-A8 architecture support is chosen, the --code_state option generates Thumb-2 code. For details on indirect calls in 16-bit versus 32-bit code, see Section 6.11.2.2. |
--asm_listing_cross_reference | Produces a symbolic cross-reference in the listing file. |
--include_file=filename | Includes the specified file for the assembly module; acts like an .include directive. The file is included before source file statements. The included file does not appear in the assembly listing files. |
2.3.12 Deprecated Options
Several compiler options have been deprecated, removed, or renamed. The compiler continues to accept some of the deprecated options, but they are not recommended for use. See the Compiler Option Cleanup wiki page for a list of deprecated and removed options, options that have been removed from CCS, and options that have been renamed.
2.4 Controlling the Compiler Through Environment Variables
An environment variable is a system symbol that you define and assign a string to. Setting environment variables is useful when you want to run the compiler repeatedly without re-entering options, input filenames, or pathnames.
NOTE
C_OPTION and C_DIR -- The C_OPTION and C_DIR environment variables are deprecated. Use device-specific environment variables instead.
2.4.1 Setting Default Compiler Options (TI_ARM_C_OPTION)
You might find it useful to set the compiler, assembler, and linker default options using the TI_ARM_C_OPTION environment variable. If you do this, the compiler uses the default options and/or input filenames that you name TI_ARM_C_OPTION every time you run the compiler.
Setting the default options with these environment variables is useful when you want to run the compiler repeatedly with the same set of options and/or input files. After the compiler reads the command line and the input filenames, it looks for the TI_ARM_C_OPTION environment variable and processes it.
The table below shows how to set the TI_ARM_C_OPTION environment variable. Select the command for your operating system:
Operating System | Enter |
---|---|
UNIX (Bourne shell) | TI_ARM_C_OPTION="option1 [option2 . . .]"; export TI_ARM_C_OPTION |
Windows | set TI_ARM_C_OPTION=option1 [option2 . . .] |
Environment variable options are specified in the same way and have the same meaning as they do on the command line. For example, if you want to always run quietly (the --quiet option), enable C/C++ source interlisting (the --src_interlist option), and link (the --run_linker option) for Windows, set up the TI_ARM_C_OPTION environment variable as follows:
set TI_ARM_C_OPTION=--quiet --src_interlist --run_linker
NOTE
The TI_ARM_C_OPTION environment variable takes precedence over the older TMS470_C_OPTION environment variable if both are defined. If only TMS470_C_OPTION is set, it will continue to be used.
In the following examples, each time you run the compiler, it runs the linker. Any options following --run_linker on the command line or in TI_ARM_C_OPTION are passed to the linker. Thus, you can use the TI_ARM_C_OPTION environment variable to specify default compiler and linker options and then specify additional compiler and linker options on the command line. If you have set --run_linker in the environment variable and want to compile only, use the compiler --compile_only option. These additional examples assume TI_ARM_C_OPTION is set as shown above:
armcl *c ; compiles and links
armcl --compile_only *.c ; only compiles
armcl *.c --run_linker lnk.cmd ; compiles and links using a command file
armcl --compile_only *.c --run_linker lnk.cmd
; only compiles (--compile_only overrides --run_linker)
For details on compiler options, see Section 2.3. For details on linker options, see the Linker Description chapter in the ARM Assembly Language Tools User's Guide.
2.4.2 Naming One or More Alternate Directories (TI_ARM_C_DIR)
The linker uses the TI_ARM_C_DIR environment variable to name alternate directories that contain object libraries. The command syntaxes for assigning the environment variable are:
Operating System | Enter |
---|---|
UNIX (Bourne shell) | TI_ARM_C_DIR="pathname1 ;pathname2 ;..."; export TI_ARM_C_DIR |
Windows | set TI_ARM_C_DIR=pathname1 ;pathname2 ;... |
The pathnames are directories that contain input files. The pathnames must follow these constraints:
- Pathnames must be separated with a semicolon.
- Spaces or tabs at the beginning or end of a path are ignored. For example, the space before and after the semicolon in the following is ignored:
- Spaces and tabs are allowed within paths to accommodate Windows directories that contain spaces. For example, the pathnames in the following are valid:
set TI_ARM_C_DIR=c:\path\one\to\tools ; c:\path\two\to\tools
set TI_ARM_C_DIR=c:\first path\to\tools;d:\second path\to\tools
The environment variable remains set until you reboot the system or reset the variable by entering:
Operating System | Enter |
---|---|
UNIX (Bourne shell) | unset TI_ARM_C_DIR |
Windows | set TI_ARM_C_DIR= |
NOTE
The TI_ARM_C_DIR environment variable takes precedence over the older TMS470_C_DIR environment variable if both are defined. If only TMS470_C_DIR is set, it will continue to be used.
2.5 Controlling the Preprocessor
This section describes features that control the preprocessor, which is part of the parser. A general description of C preprocessing is in section A12 of K&R. The C/C++ compiler includes standard C/C++ preprocessing functions, which are built into the first pass of the compiler. The preprocessor handles:
- Macro definitions and expansions
- #include files
- Conditional compilation
- Various preprocessor directives, specified in the source file as lines beginning with the # character
The preprocessor produces self-explanatory error messages. The line number and the filename where the error occurred are printed along with a diagnostic message.
2.5.1 Predefined Macro Names
The compiler maintains and recognizes the predefined macro names listed in Table 2-29.
Table 2-29 Predefined ARM Macro Names
Macro Name | Description |
---|---|
_ _16bis_ _ | Defined if 16-BIS state is selected (the -code_state=16 option is used); otherwise, it is undefined. |
_ _32bis_ _ | Defined if 32-BIS state is selected (the -code_state=16 option is not used); otherwise, it is undefined. |
_ _DATE_ _(1) | Expands to the compilation date in the form mmm dd yyyy |
_ _FILE_ _(1) | Expands to the current source filename |
_ _LINE_ _(1) | Expands to the current line number |
_ _signed_chars_ _ | Defined if char types are signed by default |
_ _STDC_ _(1) | Defined to indicate that compiler conforms to ISO C Standard. See Section 5.1 for exceptions to ISO C conformance. |
_ _STDC_VERSION_ _ | C standard macro |
_ _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_SUPPORT_ _ | Defined to 1 if the EABI ABI is enabled (this is the default); otherwise, it is undefined. |
_ _TI_FPALIB_SUPPORT_ _ | Defined to 1 if the FPA endianness is used to store double-precision floating-point values; otherwise, it is undefined. |
_ _TI_GNU_ATTRIBUTE_SUPPORT_ _ | Defined if GCC extensions are enabled (which is the default) |
_ _TI_NEON_SUPPORT_ _ | Defined to 1 if NEON SIMD extension is targeted (the --neon option is used); otherwise, it is undefined. |
_ _TI_STRICT_ANSI_MODE__ | Defined if strict ANSI/ISO mode is enabled (the --strict_ansi option is used); otherwise, it is undefined. |
_ _TI_STRICT_FP_MODE_ _ | Defined to 1 if --fp_mode=strict is used (or implied); otherwise, it is undefined. |
_ _TI_ ARM_V4_ _ | Defined to 1 if the v4 architecture (ARM7) is targeted (the -mv4 option is used); otherwise, it is undefined. |
_ _TI_ ARM_V5_ _ | Defined to 1 if the v5E architecture (ARM9E) is targeted (the -mv5e option is used); otherwise, it is undefined. |
_ _TI_ ARM_V6_ _ | Defined to 1 if the v6 architecture (ARM11) is targeted (the -mv6 option is used); otherwise, it is undefined. |
_ _TI_ ARM_V6M0_ _ | Defined to 1 if the v6M0 architecture (Cortex-M0) is targeted (the -mv6M0 option is used); otherwise, it is undefined. |
_ _TI_ ARM_V7_ _ | Defined to 1 if any v7 architecture (Cortex) is targeted; otherwise, it is undefined. |
_ _TI_ ARM_V7A8_ _ | Defined to 1 if the v7A8 architecture (Cortex-A8) is targeted (the -mv7A8 option is used); otherwise, it is undefined. |
_ _TI_ ARM_V7M3_ _ | Defined to 1 if the v7M3 architecture (Cortex-M3) is targeted (the -mv7M3 option is used); otherwise, it is undefined. |
_ _TI_ ARM_V7M4_ _ | Defined to 1 if the v7M4 architecture (Cortex-M4) is targeted (the -mv7M4 option is used); otherwise, it is undefined. |
_ _TI_ ARM_V7R4_ _ | Defined to 1 if the v7R4 architecture (Cortex-R4) is targeted (the -mv7R4 option is used); otherwise, it is undefined. |
_ _TI_ ARM_V7R5_ _ | Defined to 1 if the v7R5 architecture (Cortex-R5) is targeted (the -mv7R5 option is used); otherwise, it is undefined. |
_ _TI_VFP_SUPPORT_ _ | Defined to 1 if the VFP coprocessor is enabled (any --float_support option is used); otherwise, it is undefined. |
_ _TI_VFPLIB_SUPPORT_ _ | Defined to 1 if the VFP endianness is used to store double-precision floating-point values; otherwise, it is undefined. |
_ _TI_VFPV3_SUPPORT_ _ | Defined to 1 if the VFP coprocessor is enabled (the --float_support=vfpv3 option is used); otherwise, it is undefined. |
_ _TI_VFPV3D16_SUPPORT_ _ | Defined to 1 if the VFP coprocessor is enabled (the --float_support=vfpv3d16 option is used); otherwise, it is undefined. |
_ _TI_FPV4SPD16_SUPPORT_ _ | Defined to 1 if the VFP coprocessor is enabled (the --float_support=fpv4spd16 option is used); otherwise, it is undefined. |
_ _TI_WCHAR_T_BITS_ _ | |
_ _TIME_ _(1) | Expands to the compilation time in the form "hh:mm:ss" |
_ _TI_ ARM_ _ | Always defined |
_ _unsigned_chars_ _ | Defined if char types are unsigned by default (default) |
_ _WCHAR_T_TYPE_ _ | |
_ _big_endian_ _ | Defined if big-endian mode is selected (the --endian=big option is used or the --endian=little option is not used); otherwise, it is undefined. |
_INLINE | Expands to 1 if optimization is used (--opt_level or -O option); undefined otherwise. |
_ _little_endian_ _ | Defined if little-endian mode is selected (the --endian=little option is used); otherwise, it is undefined. |
NOTE
Macros with names that contain _ _TI_ARM are duplicates of the older _ _TI_TMS470 macros. For example, _ _TI_ARM_V7_ _ is the newer name for the _ _TI_TMS470_V7_ _ macro. The old macro names still exist and can continue to be used.
You can use the names listed in Table 2-29 in the same manner as any other defined name. For example,
printf ( "%s %s" , __TIME__ , __DATE__);
translates to a line such as:
printf ("%s %s" , "13:58:17", "Jan 14 1997");
2.5.2 The Search Path for #include Files
The #include preprocessor directive tells the compiler to read source statements from another file. When specifying the file, you can enclose the filename in double quotes or in angle brackets. The filename can be a complete pathname, partial path information, or a filename with no path information.
- If you enclose the filename in double quotes (" "), the compiler searches for the file in the following directories in this order:
- The directory of the file that contains the #include directive and in the directories of any files that contain that file.
- Directories named with the --include_path option.
- Directories set with the TI_ARM_C_DIR environment variable.
- If you enclose the filename in angle brackets (< >), the compiler searches for the file in the following directories in this order:
- Directories named with the --include_path option.
- Directories set with the TI_ARM_C_DIR environment variable.
See Section 2.5.2.1 for information on using the --include_path option. See Section 2.4.2 for more information on input file directories.
2.5.2.1 Adding a Directory to the #include File Search Path (--include_path Option)
The --include_path option names an alternate directory that contains #include files. The --include_path option's short form is -I. The format of the --include_path option is:
--include_path=directory1 [--include_path=directory2 ...]
There is no limit to the number of --include_path options per invocation of the compiler; each --include_path option names one directory. In C source, you can use the #include directive without specifying any directory information for the file; instead, you can specify the directory information with the --include_path option.
For example, assume that a file called source.c is in the current directory. The file source.c contains the following directive statement:
#include "alt.h"
Assume that the complete pathname for alt.h is:
UNIX | /tools/files/alt.h |
Windows | c:\tools\files\alt.h |
The table below shows how to invoke the compiler. Select the command for your operating system:
Operating System | Enter |
---|---|
UNIX | armcl --include_path=/tools/files source.c |
Windows | armcl --include_path=c:\tools\files source.c |
NOTE
Specifying Path Information in Angle Brackets
If you specify the path information in angle brackets, the compiler applies that information relative to the path information specified with --include_path options and the TI_ARM_C_DIR environment variable.
For example, if you set up TI_ARM_C_DIR with the following command:
TI_ARM_C_DIR "/usr/include;/usr/ucb"; export TI_ARM_C_DIR
or invoke the compiler with the following command:
armcl --include_path=/usr/include file.c
and file.c contains this line:
#include <sys/proc.h>
the result is that the included file is in the following path:
/usr/include/sys/proc.h
2.5.3 Support for the #warning and #warn Directives
In strict ANSI mode, the TI preprocessor allows you to use the #warn directive to cause the preprocessor to issue a warning and continue preprocessing. The #warn directive is equivalent to the #warning directive supported by GCC, IAR, and other compilers.
If you use the --relaxed_ansi option (on by default), both the #warn and #warning preprocessor directives are supported.
2.5.4 Generating a Preprocessed Listing File (--preproc_only Option)
The --preproc_only option allows you to generate a preprocessed version of your source file with an extension of .pp. The compiler's preprocessing functions perform the following operations on the source file:
- Each source line ending in a backslash (\) is joined with the following line.
- Trigraph sequences are expanded.
- Comments are removed.
- #include files are copied into the file.
- Macro definitions are processed.
- All macros are expanded.
- All other preprocessing directives, including #line directives and conditional compilation, are expanded.
The --preproc_only option is useful when creating a source file for a technical support case or to ask a question about your code. It allows you to reduce the test case to a single source file, because #include files are incorporated when the preprocessor runs.
2.5.5 Continuing Compilation After Preprocessing (--preproc_with_compile Option)
If you are preprocessing, the preprocessor performs preprocessing only; it does not compile your source code. To override this feature and continue to compile after your source code is preprocessed, use the --preproc_with_compile option along with the other preprocessing options. For example, use --preproc_with_compile with --preproc_only to perform preprocessing, write preprocessed output to a file with a .pp extension, and compile your source code.
2.5.6 Generating a Preprocessed Listing File with Comments (--preproc_with_comment Option)
The --preproc_with_comment option performs all of the preprocessing functions except removing comments and generates a preprocessed version of your source file with a .pp extension. Use the --preproc_with_comment option instead of the --preproc_only option if you want to keep the comments.
2.5.7 Generating Preprocessed Listing with Line-Control Details (--preproc_with_line Option)
By default, the preprocessed output file contains no preprocessor directives. To include the #line directives, use the --preproc_with_line option. The --preproc_with_line option performs preprocessing only and writes preprocessed output with line-control information (#line directives) to a file named as the source file but with a .pp extension.
2.5.8 Generating Preprocessed Output for a Make Utility (--preproc_dependency Option)
The --preproc_dependency option performs preprocessing only. Instead of writing preprocessed output, it writes a list of dependency lines suitable for input to a standard make utility. If you do not supply an optional filename, the list is written to a file with the same name as the source file but a .pp extension.
2.5.9 Generating a List of Files Included with #include (--preproc_includes Option)
The --preproc_includes option performs preprocessing only, but instead of writing preprocessed output, writes a list of files included with the #include directive. If you do not supply an optional filename, the list is written to a file with the same name as the source file but with a .pp extension.
2.5.10 Generating a List of Macros in a File (--preproc_macros Option)
The --preproc_macros option generates a list of all predefined and user-defined macros. If you do not supply an optional filename, the list is written to a file with the same name as the source file but with a .pp extension. Predefined macros are listed first and indicated by the comment /* Predefined */. User-defined macros are listed next and indicated by the source filename.
2.6 Passing Arguments to main()
Some programs pass arguments to main() via argc and argv. This presents special challenges in an embedded program that is not run from the command line. In general, argc and argv are made available to your program through the .args section. There are various ways to populate the contents of this section for use by your program.
To cause the linker to allocate an .args section of the appropriate size, use the --arg_size=size linker option. This option tells the linker to allocate an uninitialized section named .args, which can be used by the loader to pass arguments from the command line of the loader to the program. The size is the number of bytes to be allocated. When you use the --arg_size option, the linker defines the __c_args__ symbol to contain the address of the .args section.
It is the responsibility of the loader to populate the .args section. The loader and the target boot code can use the .args section and the __c_args__ symbol to determine whether and how to pass arguments from the host to the target program. The format of the arguments is an array of pointers to char on the target. Due to variations in loaders, it is not specified how the loader determines which arguments to pass to the target.
If you are using Code Composer Studio to run your application, you can use the Scripting Console tool to populate the .args section. To open this tool, choose View > Scripting Console from the CCS menus. You can use the loadProg command to load an object file and its associated symbol table into memory and pass an array of arguments to main(). These arguments are automatically written to the allocated .args section.
The loadProg syntax is as follows, where file is an executable file and args is an object array of arguments. Use JavaScript to declare the array of arguments before using this command.
loadProg(file, args)
The .args section is loaded with the following data for non-SYS/BIOS-based executables, where each element in the argv[] array contains a string corresponding to that argument:
Int argc;
Char * argv[0];
Char * argv[1];
...
Char * argv[n];
For SYS/BIOS-based executables, the elements in the .args section are as follows:
Int argc;
Char ** argv; /* points to argv[0] */
Char * envp; /* ignored by loadProg command */
Char * argv[0];
Char * argv[1];
...
Char * argv[n];
For more details, see the "Scripting Console" topic in the TI Processors Wiki.
2.7 Understanding Diagnostic Messages
One of the primary functions of the compiler and linker is to report diagnostic messages for the source program. A diagnostic message indicates that something may be wrong with the program. When the compiler or linker detects a suspect condition, it displays a message in the following format:
" file.c ", line n : diagnostic severity : diagnostic message
" file.c " | The name of the file involved |
linen: | The line number where the diagnostic applies |
diagnostic severity | The diagnostic message severity (severity category descriptions follow) |
diagnostic message | The text that describes the problem |
Diagnostic messages have a severity, as follows:
- A fatal error indicates a problem so severe that the compilation cannot continue. Examples of such problems include command-line errors, internal errors, and missing include files. If multiple source files are being compiled, any source files after the current one will not be compiled.
- An error indicates a violation of the syntax or semantic rules of the C/C++ language. Compilation may continue, but object code is not generated.
- A warning indicates something that is likely to be a problem, but cannot be proven to be an error. For example, the compiler emits a warning for an unused variable. An unused variable does not affect program execution, but its existence suggests that you might have meant to use it. Compilation continues and object code is generated (if no errors are detected).
- A remark is less serious than a warning. It may indicate something that is a potential problem in rare cases, or the remark may be strictly informational. Compilation continues and object code is generated (if no errors are detected). By default, remarks are not issued. Use the --issue_remarks compiler option to enable remarks.
- Advice provides information about recommended usage. It is not provided in the same way as the other diagnostic categories described here. Instead, it is only available in Code Composer Studio in the Advice area, which is a tab that appears next to the Problems tab. This advice cannot be controlled or accessed via the command line. The advice provided includes suggested settings for the --opt_level and --opt_for_speed options. In addition, messages about suggested code changes from the ULP (Ultra-Low Power) Advisor are provided in this tab.
Diagnostic messages are written to standard error with a form like the following example:
"test.c", line 5: error: a break statement may only be used within a loop or switch
break;
^
By default, the source code line is not printed. Use the --verbose_diagnostics compiler option to display the source line and the error position. The above example makes use of this option.
The message identifies the file and line involved in the diagnostic, and the source line itself (with the position indicated by the ^ character) follows the message. If several diagnostic messages apply to one source line, each diagnostic has the form shown; the text of the source line is displayed several times, with an appropriate position indicated each time.
Long messages are wrapped to additional lines, when necessary.
You can use the --display_error_number command-line option to request that the diagnostic's numeric identifier be included in the diagnostic message. When displayed, the diagnostic identifier also indicates whether the diagnostic can have its severity overridden on the command line. If the severity can be overridden, the diagnostic identifier includes the suffix -D (for discretionary); otherwise, no suffix is present. For example:
"Test_name.c", line 7: error #64-D: declaration does not declare anything
struct {};
^
"Test_name.c", line 9: error #77: this declaration has no storage class or type specifier
xxxxx;
^
Because errors are determined to be discretionary based on the severity in a specific context, an error can be discretionary in some cases and not in others. All warnings and remarks are discretionary.
For some messages, a list of entities (functions, local variables, source files, etc.) is useful; the entities are listed following the initial error message:
"test.c", line 4: error: more than one instance of overloaded function "f"
matches the argument list:
function "f(int)" function "f(float)" argument types are: (double)
f(1.5);
^
In some cases, additional context information is provided. Specifically, the context information is useful when the front end issues a diagnostic while doing a template instantiation or while generating a constructor, destructor, or assignment operator function. For example:
"test.c", line 7: error: "A::A()" is inaccessible
B x;
^
detected during implicit generation of "B::B()" at line 7
Without the context information, it is difficult to determine to what the error refers.
2.7.1 Controlling Diagnostic Messages
The C/C++ compiler provides diagnostic options to control compiler- and linker-generated diagnostic messages. The diagnostic options must be specified before the --run_linker option.
--diag_error=num | Categorizes the diagnostic identified by num as an error. To determine the numeric identifier of a diagnostic message, use the --display_error_number option first in a separate compile. Then use --diag_error=num to recategorize the diagnostic as an error. You can only alter the severity of discretionary diagnostic messages. |
--diag_remark=num | Categorizes the diagnostic identified by num as a remark. To determine the numeric identifier of a diagnostic message, use the --display_error_number option first in a separate compile. Then use --diag_remark=num to recategorize the diagnostic as a remark. You can only alter the severity of discretionary diagnostic messages. |
--diag_suppress=num | Suppresses the diagnostic identified by num. To determine the numeric identifier of a diagnostic message, use the --display_error_number option first in a separate compile. Then use --diag_suppress=num to suppress the diagnostic. You can only suppress discretionary diagnostic messages. |
--diag_warning=num | Categorizes the diagnostic identified by num as a warning. To determine the numeric identifier of a diagnostic message, use the --display_error_number option first in a separate compile. Then use --diag_warning=num to recategorize the diagnostic as a warning. You can only alter the severity of discretionary diagnostic messages. |
--display_error_number | Displays a diagnostic's numeric identifier along with its text. Use this option in determining which arguments you need to supply to the diagnostic suppression options (--diag_suppress, --diag_error, --diag_remark, and --diag_warning). This option also indicates whether a diagnostic is discretionary. A discretionary diagnostic is one whose severity can be overridden. A discretionary diagnostic includes the suffix -D; otherwise, no suffix is present. See Section 2.7. |
--emit_warnings_as_
errors |
Treats all warnings as errors. This option cannot be used with the --no_warnings option. The --diag_remark option takes precedence over this option. This option takes precedence over the --diag_warning option. |
--issue_remarks | Issues remarks (non-serious warnings), which are suppressed by default. |
--no_warnings | Suppresses diagnostic warnings (errors are still issued). |
--section_sizes={on|off} | Generates section size information, including sizes for sections containing executable code and constants, constant or initialized data (global and static variables), and uninitialized data. Section size information is output during both the assembly and linking phases. This option should be placed on the command line with the compiler options (that is, before the --run_linker or --z option). |
--set_error_limit=num | Sets the error limit to num, which can be any decimal value. The compiler abandons compiling after this number of errors. (The default is 100.) |
--verbose_diagnostics | Provides verbose diagnostic messages that display the original source with line-wrap and indicate the position of the error in the source line. Note that this command-line option cannot be used within the Code Composer Studio IDE. |
--write_diagnostics_file | Produces a diagnostic message information file with the same source file name with an .err extension. (The --write_diagnostics_file option is not supported by the linker.) Note that this command-line option cannot be used within the Code Composer Studio IDE. |
2.7.2 How You Can Use Diagnostic Suppression Options
The following example demonstrates how you can control diagnostic messages issued by the compiler. You control the linker diagnostic messages in a similar manner.
int one();
int I;
int main()
{
switch (I){
case 1;
return one ();
break;
default:
return 0;
break;
}
}
If you invoke the compiler with the --quiet option, this is the result:
"err.c", line 9: warning: statement is unreachable
"err.c", line 12: warning: statement is unreachable
Because it is standard programming practice to include break statements at the end of each case arm to avoid the fall-through condition, these warnings can be ignored. Using the --display_error_number option, you can find out the diagnostic identifier for these warnings. Here is the result:
[err.c]
"err.c", line 9: warning #111-D: statement is unreachable
"err.c", line 12: warning #111-D: statement is unreachable
Next, you can use the diagnostic identifier of 111 as the argument to the --diag_remark option to treat this warning as a remark. This compilation now produces no diagnostic messages (because remarks are disabled by default).
NOTE
You can suppress any non-fatal errors, but be careful to make sure you only suppress diagnostic messages that you understand and are known not to affect the correctness of your program.
2.8 Other Messages
Other error messages that are unrelated to the source, such as incorrect command-line syntax or inability to find specified files, are usually fatal. They are identified by the symbol >> preceding the message.
2.9 Generating Cross-Reference Listing Information (--gen_cross_reference Option)
The --gen_cross_reference option generates a cross-reference listing file that contains reference information for each identifier in the source file. (The --gen_cross_reference option is separate from --asm_listing_cross_reference, which is an assembler rather than a compiler option.) The cross-reference listing file has the same name as the source file with a .crl extension.
The information in the cross-reference listing file is displayed in the following format:
sym-id name X filename line number column number
sym-id | An integer uniquely assigned to each identifier | |
name | The identifier name | |
X | One of the following values: | |
D | Definition | |
d | Declaration (not a definition) | |
M | Modification | |
A | Address taken | |
U | Used | |
C | Changed (used and modified in a single operation) | |
R | Any other kind of reference | |
E | Error; reference is indeterminate | |
filename | The source file | |
line number | The line number in the source file | |
column number | The column number in the source file |
2.10 Generating a Raw Listing File (--gen_parser_listing Option)
The --gen_parser_listing option generates a raw listing file that can help you understand how the compiler is preprocessing your source file. Whereas the preprocessed listing file (generated with the --preproc_only, --preproc_with_comment, --preproc_with_line, and --preproc_dependency preprocessor options) shows a preprocessed version of your source file, a raw listing file provides a comparison between the original source line and the preprocessed output. The raw listing file has the same name as the corresponding source file with an .rl extension.
The raw listing file contains the following information:
- Each original source line
- Transitions into and out of include files
- Diagnostic messages
- Preprocessed source line if nontrivial processing was performed (comment removal is considered trivial; other preprocessing is nontrivial)
Each source line in the raw listing file begins with one of the identifiers listed in Table 2-30.
Table 2-30 Raw Listing File Identifiers
Identifier | Definition |
---|---|
N | Normal line of source |
X | Expanded line of source. It appears immediately following the normal line of source if nontrivial preprocessing occurs. |
S | Skipped source line (false #if clause) |
L | Change in source position, given in the following format: L line number filename key |
Where line number is the line number in the source file. The key is present only when the change is due to entry/exit of an include file. Possible values of key are: | |
1 = entry into an include file 2 = exit from an include file |
The --gen_parser_listing option also includes diagnostic identifiers as defined in Table 2-31.
Table 2-31 Raw Listing File Diagnostic Identifiers
Diagnostic Identifier | Definition |
---|---|
E | Error |
F | Fatal |
R | Remark |
W | Warning |
Diagnostic raw listing information is displayed in the following format:
Sfilenameline numbercolumn numberdiagnostic |
S | One of the identifiers in Table 2-31 that indicates the severity of the diagnostic |
filename | The source file |
line number | The line number in the source file |
column number | The column number in the source file |
diagnostic | The message text for the diagnostic |
Diagnostic messages after the end of file are indicated as the last line of the file with a column number of 0. When diagnostic message text requires more than one line, each subsequent line contains the same file, line, and column information but uses a lowercase version of the diagnostic identifier. For more information about diagnostic messages, see Section 2.7. |
2.11 Using Inline Function Expansion
When an inline function is called, a copy of the C/C++ source code for the function is inserted at the point of the call. This is known as inline function expansion, commonly called function inlining or just inlining. Inline function expansion can speed up execution by eliminating function call overhead. This is particularly beneficial for very small functions that are called frequently. Function inlining involves a tradeoff between execution speed and code size, because the code is duplicated at each function call site. Large functions that are called frequently are poor candidates for inlining.
Function inlining is triggered by the following situations:
- The use of built-in intrinsic operations. Intrinsic operations look like function calls, and are inlined automatically, even though no function body exists.
- Use of the inline keyword or the equivalent __inline keyword. Functions declared with the inline keyword may be inlined by the compiler if you set --opt_level=3 (the default) or greater. The inline keyword is a suggestion from the programmer to the compiler. Even if your optimization level is high, inlining is still optional for the compiler. The compiler decides whether to inline a function based on the length of the function, the number of times it is called, your --opt_for_speed setting, and any contents of the function that disqualify it from inlining (see Section 2.11.3). Functions can be inlined at --opt_level=3 if the function body is visible in the same module or if -pm is also used and the function is visible in one of the modules being compiled. Functions may be inlined at link time if the file containing the definition and the call site were both compiled with --opt_level=4.
- Use of static inline functions. Functions defined as both static and inline are more likely to be inlined.
- When --opt_level=3 or greater is used, the compiler may automatically inline eligible functions even if they are not declared as inline functions. The same list of decision factors listed for functions explicitly defined with the inline keyword is used. For more about automatic function inlining, see Section 3.9
- The pragma FUNC_ALWAYS_INLINE forces a function to be inlined (where it is legal to do so) unless --opt_level=off. That is, the pragma FUNC_ALWAYS_INLINE forces function inlining even if --opt_level=0 or --opt_level=1.
- The pragma FUNC_CANNOT_INLINE prevents a function from being inlined.
NOTE
Function Inlining Can Greatly Increase Code Size
Function inlining increases code size, especially inlining a function that is called in a number of places. Function inlining is optimal for functions that are called only from a small number of places and for small functions.
The semantics of the inline keyword in C code follow the C99 standard. The semantics of the inline keyword in C++ code follow the C++ standard.
The inline keyword is supported in all C++ modes, in relaxed ANSI mode for all C standards, and in strict ANSI mode for C99. It is disabled in strict ANSI mode for C89, because it is a language extension that could conflict with a strictly conforming program. If you want to define inline functions while in strict ANSI C89 mode, use the alternate keyword _ _inline.
Compiler options that affect inlining are: --opt_level, --auto_inline, -remove_hooks_when_inlining, and -opt_for_speed.
In most cases, inlining will reduce the code size by a small amount.
2.11.1 Inlining Intrinsic Operators
The compiler has built-in function-like operations called intrinsics. The implementation of an intrinsic function is handled by the compiler, which substitutes a sequence of instructions for the function call. This is similar to the way inline function are handled, however, because the compiler knows the code of the intrinsic function, it can perform better optimization.
Intrinsic operations look like function calls, and can be implemented very efficiently with the target's instruction set. The compiler automatically inlines the intrinsic operators of the target system by default. Inlining happens whether or not you use the optimizer. For details about intrinsics, and a list of the intrinsics, see Section 5.13.
These are some of the functions that are considered intrinsic operators.
- abs
- labs
- fabs
2.11.2 Automatic Inlining
When optimizing with the --opt_level=3 (aliased as -O3), the compiler automatically inlines certain functions. For more information, see Section 3.9.
2.11.3 Inlining Restrictions
The compiler makes decisions about which functions to inline based on the factors mentioned in Section 2.11. In addition, there are several restrictions that can disqualify a function from being inlined by automatic inlining or inline keyword-based inlining. The FUNC_ALWAYS_INLINE pragma overrides these disqualifications, so you should be aware of situations that can cause problems if you are using the FUNC_ALWAYS_INLINE pragma.
- Has a FUNC_CANNOT_INLINE pragma
- Is not defined in the current compilation unit and you are not using -O4 optimization
- Never returns
- Is a recursive or nonleaf function that exceeds the depth limit
- Has a variable-length argument list
- Has a different number of arguments than the call site
- Has an argument whose type is incompatible with the corresponding call site argument
- Has a class, struct, or union parameter
- Contains a volatile local variable or argument
- Contains local static variables but is not a static inline function.
- Is not declared inline and contains an asm() statement that is not a comment
- Is the main() function
- Is an interrupt function
- Is not declared inline and returns void but its return value is needed.
- Is not declared inline and will require too much stack space for local array or structure variables.
Furthermore, inlining should be used for small functions or functions that are called in a few places (though the compiler does not enforce this).
NOTE
Excessive Inlining Can Degrade Performance
Excessive inlining can make the compiler dramatically slower and degrade the performance of generated code.
2.12 Using Interlist
The compiler tools include a feature that interlists C/C++ source statements into the assembly language output of the compiler. The interlist feature enables you to inspect the assembly code generated for each C statement. The interlist behaves differently, depending on whether or not the optimizer is used, and depending on which options you specify.
The easiest way to invoke the interlist feature is to use the --c_src_interlist option. To compile and run the interlist on a program called function.c, enter:
armcl --c_src_interlist function
The --c_src_interlist option prevents the compiler from deleting the interlisted assembly language output file. The output assembly file, function.asm, is assembled normally.
When you invoke the interlist feature without the optimizer, the interlist runs as a separate pass between the code generator and the assembler. It reads both the assembly and C/C++ source files, merges them, and writes the C/C++ statements into the assembly file as comments.
Using the --c_src_interlist option can cause performance and/or code size degradation.
Example 2-1 shows a typical interlisted assembly file.
For more information about using the interlist feature with the optimizer, see Section 3.10.
Example 2-1 An Interlisted Assembly Language File
_main:
STMFD SP!, {LR}
;------------------------------------------------------------------------------
; 5 | printf("Hello, world\n");
;------------------------------------------------------------------------------
ADR A1, SL1
BL _printf
;------------------------------------------------------------------------------
; 6 | return 0;
;------------------------------------------------------------------------------
MOV A1, #0
LDMFD SP!, {PC}
2.13 Controlling Application Binary Interface
Application Binary Interface (ABI) defines the low level interface between object files, and between an executable and its execution environment. An ABI allows ABI-compliant object files to be linked together, regardless of their source, and allows the resulting executable to run on any system that supports that ABI.
Object files conforming to different ABIs cannot be linked together. The linker detects this situation and generates an error.
The ARM compiler now supports only the Embedded Application Binary Interface (EABI) ABI, which uses the ELF object format and the DWARF debug format. If you want support for the legacy TI_ARM9_ABI and TIARM ABIs, please use the ARM v5.2 Code Generation Tools and refer to SPNU151J and SPNU118J for documentation.
An industry consortium founded by ARM Ltd defined a standard ABI for binary code intended for the ARM architecture. This ABI is called the Application Binary Interface (ABI) for the ARM Architecture Version 2 (ARM ABIv2). This ABI is also referred to as Embedded Application Binary Interface (EABI). The terms ABIv2 and EABI can be used interchangeably.
For more details on the ABI, see Section 5.12.
2.14 VFP Support
The compiler includes support for generating vector floating-point (VFP) co-processor instructions through the --float_support=vfp option. The VFP co-processor is available in many variants of ARM11 and higher. The valid vfp entries are:
-
vfpv3
VFPv3 architecture and instruction set
-
vfpv3d16
VFPv3d16 architecture and instruction set
-
fpv4spd16
FPv4-SP architecture and instruction set
-
fpalib
FPA endianness is used to store double-precision floating-point values (most significant word occupies the lower memory address).
-
vfplib
VFP endianness is used to store double-precision floating-point values (endianness used is that of the memory system). All VFP coprocessors use this endianness to represent doubles.
This is the current support for VFP:
- You must link any VFP compiled code with a separate version of the run-time support library. See Section 7.1.8 for information on library-naming conventions.
- The compiler follows the VFP argument passing and returning calling convention for qualified VFP arguments.
- Object files that do not contain any functions with floating point arguments or return values can be linked with both VFP and non-VFP files.
- Object files that do contain functions with floating point arguments or return values can only be linked with objects that were compiled with matching VFP support.
- All hand-coded VFP assembly must follow VFP calling conventions and EABI conventions to correctly compile and link. In addition to these, the appropriate VFP build attributes for EABI must be correctly set.
- The compile-time predefined macro __TI_VFP_SUPPORT__ can be used for conditionally compiling/assembling user code. VFP-specific user code can use this macro to ensure that the conditionally included code is compiled only when VFP is enabled.
Refer to the ARM architecture manual for more details on the VFPv3 and VFPv3D16 architectures and ISAs. Refer to the ARM AAPCS and EABI documents for more details on VFP calling conventions and build attributes.
2.15 Enabling Entry Hook and Exit Hook Functions
An entry hook is a routine that is called upon entry to each function in the program. An exit hook is a routine that is called upon exit of each function. Applications for hooks include debugging, trace, profiling, and stack overflow checking.
Entry and exit hooks are enabled using the following options:
--entry_hook[=name] | Enables entry hooks. If specified, the hook function is called name. Otherwise, the default entry hook function name is __entry_hook. |
--entry_parm{=name| address|none} |
Specify the parameters to the hook function. The name parameter specifies that the name of the calling function is passed to the hook function as an argument. In this case the signature for the hook function is: void hook(const char *name); The address parameter specifies that the address of the calling function is passed to the hook function. In this case the signature for the hook function is: void hook(void (*addr)()); The none parameter specifies that the hook is called with no parameters. This is the default. In this case the signature for the hook function is: void hook(void); |
--exit_hook[=name] | Enables exit hooks. If specified, the hook function is called name. Otherwise, the default exit hook function name is __exit_hook. |
--exit_parm{=name| address|none} |
Specify the parameters to the hook function. The name parameter specifies that the name of the calling function is passed to the hook function as an argument. In this case the signature for the hook function is: void hook(const char *name); The address parameter specifies that the address of the calling function is passed to the hook function. In this case the signature for the hook function is: void hook(void (*addr)()); The none parameter specifies that the hook is called with no parameters. This is the default. In this case the signature for the hook function is: void hook(void); |
The presence of the hook options creates an implicit declaration of the hook function with the given signature. If a declaration or definition of the hook function appears in the compilation unit compiled with the options, it must agree with the signatures listed above.
In C++, the hooks are declared extern "C". Thus you can define them in C (or assembly) without being concerned with name mangling.
Hooks can be declared inline, in which case the compiler tries to inline them using the same criteria as other inline functions.
Entry hooks and exit hooks are independent. You can enable one but not the other, or both. The same function can be used as both the entry and exit hook.
You must take care to avoid recursive calls to hook functions. The hook function should not call any function which itself has hook calls inserted. To help prevent this, hooks are not generated for inline functions, or for the hook functions themselves.
You can use the --remove_hooks_when_inlining option to remove entry/exit hooks for functions that are auto-inlined by the optimizer.
See Section 5.10.19 for information about the NO_HOOKS pragma.
Copyright© 2016, Texas Instruments Incorporated. An IMPORTANT NOTICE for this document addresses availability, warranty, changes, use in safety-critical applications, intellectual property matters and other important disclaimers.