ARM Optimizing C/C++ Compiler
ARM Optimizing C/C++ Compiler
ARM Optimizing C/C++ Compiler
v20.2.0.LTS
User's Guide
Preface ........................................................................................................................................ 9
1 Introduction to the Software Development Tools .................................................................... 12
1.1 Software Development Tools Overview ................................................................................. 13
1.2 Compiler Interface .......................................................................................................... 15
1.3 ANSI/ISO Standard ........................................................................................................ 15
1.4 Output Files ................................................................................................................. 15
1.5 Utilities ....................................................................................................................... 16
2 Using the C/C++ Compiler ................................................................................................... 17
2.1 About the Compiler......................................................................................................... 18
2.2 Invoking the C/C++ Compiler ............................................................................................. 18
2.3 Changing the Compiler's Behavior with Options ....................................................................... 19
2.3.1 Linker Options ..................................................................................................... 25
2.3.2 Frequently Used Options ......................................................................................... 27
2.3.3 Miscellaneous Useful Options ................................................................................... 28
2.3.4 Run-Time Model Options ......................................................................................... 30
2.3.5 Symbolic Debugging and Profiling Options .................................................................... 32
2.3.6 Specifying Filenames ............................................................................................. 33
2.3.7 Changing How the Compiler Interprets Filenames ........................................................... 33
2.3.8 Changing How the Compiler Processes C Files .............................................................. 34
2.3.9 Changing How the Compiler Interprets and Names Extensions ............................................ 34
2.3.10 Specifying Directories............................................................................................ 34
2.3.11 Assembler Options ............................................................................................... 35
2.3.12 Deprecated Options .............................................................................................. 35
2.4 Controlling the Compiler Through Environment Variables ............................................................ 35
2.4.1 Setting Default Compiler Options (TI_ARM_C_OPTION).................................................... 36
2.4.2 Naming One or More Alternate Directories (TI_ARM_C_DIR) .............................................. 37
2.5 Controlling the Preprocessor ............................................................................................. 38
2.5.1 Predefined Macro Names ........................................................................................ 38
2.5.2 The Search Path for #include Files ............................................................................. 41
2.5.3 Support for the #warning and #warn Directives ............................................................... 42
2.5.4 Generating a Preprocessed Listing File (--preproc_only Option) ........................................... 43
2.5.5 Continuing Compilation After Preprocessing (--preproc_with_compile Option) ........................... 43
2.5.6 Generating a Preprocessed Listing File with Comments (--preproc_with_comment Option) ........... 43
2.5.7 Generating Preprocessed Listing with Line-Control Details (--preproc_with_line Option) ............... 43
2.5.8 Generating Preprocessed Output for a Make Utility (--preproc_dependency Option) ................... 43
2.5.9 Generating a List of Files Included with #include (--preproc_includes Option) ........................... 43
2.5.10 Generating a List of Macros in a File (--preproc_macros Option) ......................................... 43
2.6 Passing Arguments to main() ............................................................................................. 44
2.7 Understanding Diagnostic Messages .................................................................................... 44
2.7.1 Controlling Diagnostic Messages ............................................................................... 46
2.7.2 How You Can Use Diagnostic Suppression Options ......................................................... 47
2.8 Other Messages ............................................................................................................ 47
2.9 Generating Cross-Reference Listing Information (--gen_cross_reference Option) ................................ 47
2.10 Generating a Raw Listing File (--gen_preprocessor_listing Option) ................................................. 48
2.11 Using Inline Function Expansion ......................................................................................... 49
List of Figures
1-1. ARM Software Development Flow ....................................................................................... 13
6-1. Char and Short Data Storage Format .................................................................................. 144
6-2. 32-Bit Data Storage Format ............................................................................................. 145
6-3. Double-Precision Floating-Point Data Storage Format .............................................................. 146
6-4. Bit-Field Packing in Big-Endian and Little-Endian Formats ......................................................... 148
6-5. Use of the Stack During a Function Call ............................................................................... 153
6-6. Autoinitialization at Run Time ........................................................................................... 166
6-7. Initialization at Load Time ............................................................................................... 170
6-8. Constructor Table ......................................................................................................... 170
6-9. Format of Initialization Records in the .cinit Section ................................................................. 171
6-10. Format of Initialization Records in the .pinit Section ................................................................. 172
List of Tables
2-1. Processor Options ......................................................................................................... 19
2-2. Optimization Options ...................................................................................................... 19
2-3. Advanced Optimization Options ......................................................................................... 20
2-4. Debug Options .............................................................................................................. 20
2-5. Include Options ............................................................................................................ 20
2-6. ULP Advisor Options ....................................................................................................... 20
2-7. Control Options ............................................................................................................ 21
2-8. Language Options .......................................................................................................... 21
2-9. Parser Preprocessing Options ............................................................................................ 21
2-10. Predefined Macro Options ............................................................................................... 22
2-11. Diagnostic Message Options ............................................................................................. 22
2-12. Supplemental Information Options ...................................................................................... 22
2-13. Run-Time Model Options .................................................................................................. 23
2-14. Entry/Exit Hook Options ................................................................................................... 23
2-15. Feedback Options ......................................................................................................... 23
2-16. Assembler Options ......................................................................................................... 23
2-17. File Type Specifier Options ............................................................................................... 24
2-18. Directory Specifier Options................................................................................................ 24
2-19. Default File Extensions Options .......................................................................................... 24
2-20. Command Files Options ................................................................................................... 24
2-21. MISRA-C 2004 Options ................................................................................................... 24
2-22. Linker Basic Options ....................................................................................................... 25
2-23. File Search Path Options .................................................................................................. 25
2-24. Command File Preprocessing Options .................................................................................. 25
2-25. Diagnostic Message Options ............................................................................................. 25
2-26. Linker Output Options ..................................................................................................... 26
2-27. Symbol Management Options ............................................................................................ 26
2-28. Run-Time Environment Options .......................................................................................... 26
2-29. Miscellaneous Options..................................................................................................... 27
2-30. Predefined ARM Macro Names .......................................................................................... 38
2-31. ACLE Pre-Defined Macros ................................................................................................ 39
2-32. Raw Listing File Identifiers ................................................................................................ 48
2-33. Raw Listing File Diagnostic Identifiers ................................................................................... 49
3-1. Options That You Can Use With --opt_level=3 ......................................................................... 58
Notational Conventions
This document uses the following conventions:
• Program listings, program examples, and interactive displays are shown in a special typeface.
Interactive displays use a bold version of the special typeface to distinguish commands that you enter
from items that the system displays (such as prompts, command output, error messages, etc.). Here is
a sample of C code:
#include <stdio.h>
main()
{ printf("Hello World\n");
}
• In syntax descriptions, instructions, commands, and directives are in a bold typeface and parameters
are in an italic typeface. Portions of a syntax that are in bold should be entered as shown; portions of a
syntax that are in italics describe the type of information that should be entered.
• Square brackets ( [ and ] ) identify an optional parameter. If you use an optional parameter, you specify
the information within the brackets. Unless the square brackets are in the bold typeface, do not enter
the brackets themselves. The following is an example of a command that has an optional parameter:
• Braces ( { and } ) indicate that you must choose one of the parameters within the braces; you do not
enter the braces themselves. This is an example of a command with braces that are not included in the
actual syntax but indicate that you must specify either the --rom_model or --ram_model option:
• In assembler syntax statements, the leftmost column is reserved for the first character of a label or
symbol. If the label or symbol is optional, it is usually not shown. If a label or symbol is a required
parameter, it is shown starting against the left margin of the box, as in the example below. No
instruction, command, directive, or parameter, other than a symbol or label, can begin in the leftmost
column.
• Some directives can have a varying number of parameters. For example, the .byte directive. This
syntax is shown as [, ..., parameter].
• The ARM® 16-bit instruction set is referred to as 16-BIS.
• The ARM 32-bit instruction set is referred to as 32-BIS.
Related Documentation
You can use the following books to supplement this user's guide:
ANSI X3.159-1989, Programming Language - C (Alternate version of the 1989 C Standard), American
National Standards Institute
ISO/IEC 9899:1989, International Standard - Programming Languages - C (The 1989 C Standard),
International Organization for Standardization
ISO/IEC 9899:1999, International Standard - Programming Languages - C (The 1999 C Standard),
International Organization for Standardization
ISO/IEC 9899:2011, International Standard - Programming Languages - C (The 2011 C Standard),
International Organization for Standardization
ISO/IEC 14882-2014, International Standard - Programming Languages - C++ (The 2014 C++
Standard), International Organization for Standardization
The C Programming Language (second edition), by Brian W. Kernighan and Dennis M. Ritchie,
published by Prentice-Hall, Englewood Cliffs, New Jersey, 1988
The Annotated C++ Reference Manual, Margaret A. Ellis and Bjarne Stroustrup, published by Addison-
Wesley Publishing Company, Reading, Massachusetts, 1990
C: A Reference Manual (fourth edition), by Samuel P. Harbison, and Guy L. Steele Jr., published by
Prentice Hall, Englewood Cliffs, New Jersey
Programming Embedded Systems in C and C++, by Michael Barr, Andy Oram (Editor), published by
O'Reilly & Associates; ISBN: 1565923545, February 1999
Programming in C, Steve G. Kochan, Hayden Book Company
The C++ Programming Language (second edition), Bjarne Stroustrup, published by Addison-Wesley
Publishing Company, Reading, Massachusetts, 1990
Tool Interface Standards (TIS) DWARF Debugging Information Format Specification Version 2.0,
TIS Committee, 1995
DWARF Debugging Information Format Version 3, DWARF Debugging Information Format Workgroup,
Free Standards Group, 2005 (http://dwarfstd.org)
DWARF Debugging Information Format Version 4, DWARF Debugging Information Format Workgroup,
Free Standards Group, 2010 (http://dwarfstd.org)
System V ABI specification (http://www.sco.com/developers/gabi/)
ARM C Language Extensions (ACLE) specification (ACLE Version ACLE Q2 2017)
The ARM® is supported by a set of software development tools, which includes an optimizing C/C++
compiler, an assembler, a linker, and assorted utilities.
This chapter provides an overview of these tools and introduces the features of the optimizing C/C++
compiler. The assembler and linker are discussed in detail in the ARM Assembly Language Tools User's
Guide.
12 Introduction to the Software Development Tools SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Software Development Tools Overview
C/C++
source
files
Macro
source C/C++
files compiler
C/C++ name
Assembler
Archiver demangling
source
utility
Macro
library Assembler
Library-build Debugging
Object
Archiver utility tools
files
Run-time-
Library of support
object library
files Linker
Executable
object file
Hex-conversion
utility
SPNU151V – January 1998 – Revised February 2020 Introduction to the Software Development Tools 13
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Software Development Tools Overview www.ti.com
The following list describes the tools that are shown in Figure 1-1:
• The compiler accepts C/C++ source code and produces ARM assembly language source code. See
Chapter 2.
• The assembler translates assembly language source files into machine language relocatable object
files. See the ARM Assembly Language Tools User's Guide.
• The linker combines relocatable object files into a single absolute executable object file. As it creates
the executable file, it performs relocation and resolves external references. The linker accepts
relocatable object files and object libraries as input. See Chapter 4 for an overview of the linker. See
the ARM Assembly Language Tools User's Guide for details.
• The archiver allows you to collect a group of files into a single archive file, called a library. The
archiver allows you to modify such libraries by deleting, replacing, extracting, or adding members. One
of the most useful applications of the archiver is building a library of object files. See the ARM
Assembly Language Tools User's Guide.
• The run-time-support libraries contain the standard ISO C and C++ library functions, compiler-utility
functions, floating-point arithmetic functions, and C I/O functions that are supported by the compiler.
See Chapter 7.
The library-build utility automatically builds the run-time-support library if compiler and linker options
require a custom version of the library. See Section 7.4. Source code for the standard run-time-support
library functions for C and C++ is provided in the lib\src subdirectory of the directory where the
compiler is installed.
• The hex conversion utility converts an object file into other object formats. You can download the
converted file to an EPROM programmer. See the ARM Assembly Language Tools User's Guide.
• The absolute lister accepts linked object files as input and creates .abs files as output. You can
assemble these .abs files to produce a listing that contains absolute, rather than relative, addresses.
Without the absolute lister, producing such a listing would be tedious and would require many manual
operations. See the ARM Assembly Language Tools User's Guide.
• The cross-reference lister uses object files to produce a cross-reference listing showing symbols,
their definitions, and their references in the linked source files. See the ARM Assembly Language
Tools User's Guide.
• The C++ name demangler is a debugging aid that converts names mangled by the compiler back to
their original names as declared in the C++ source code. As shown in Figure 1-1, you can use the C++
name demangler on the assembly file that is output by the compiler; you can also use this utility on the
assembler listing file and the linker map file. See Chapter 8.
• The disassembler decodes object files to show the assembly instructions that they represent. See the
ARM Assembly Language Tools User's Guide.
• The main product of this development process is an executable object file that can be executed on a
ARM device.
14 Introduction to the Software Development Tools SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Compiler Interface
SPNU151V – January 1998 – Revised February 2020 Introduction to the Software Development Tools 15
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Utilities www.ti.com
1.5 Utilities
These features are compiler utilities:
• Library-build utility
The library-build utility lets you custom-build object libraries from source for any combination of run-
time models. For more information, see Section 7.4.
• C++ name demangler
The C++ name demangler (armdem) is a debugging aid that translates each mangled name it detects
in compiler-generated assembly code, disassembly output, or compiler diagnostic messages to its
original name found in the C++ source code. For more information, see Chapter 8.
• Hex conversion utility
For stand-alone embedded applications, the compiler has the ability to place all code and initialization
data into ROM, allowing C/C++ code to run from reset. The ELF files output by the compiler can be
converted to EPROM programmer data files by using the hex conversion utility, as described in the
ARM Assembly Language Tools User's Guide.
16 Introduction to the Software Development Tools SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Chapter 2
SPNU151V – January 1998 – Revised February 2020
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 file. All of these
steps are executed at once by using the compiler.
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 17
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
About the Compiler www.ti.com
For a complete description of the assembler and the linker, see the ARM Assembly Language Tools
User's Guide.
18 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Changing the Compiler's Behavior with Options
(1)
Note: Machine-specific options (see Table 2-13) can also affect optimization.
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 19
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Changing the Compiler's Behavior with Options www.ti.com
(1)
Table 2-3. Advanced Optimization Options
Option Alias Effect Section
--auto_inline=[size] -oi Sets automatic inlining size (--opt_level=3 only). If size is not Section 3.5
specified, the default is 1.
--call_assumptions=n -opn Level 0 (-op0) specifies that the module contains functions and Section 3.4.1
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.
--disable_inlining Prevents any inlining from occurring. Section 2.11
--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
--gen_opt_info=n -onn Level 0 (-on0) disables the optimization information file. Section 3.3.1
Level 1 (-on2) produces an optimization information file.
Level 2 (-on2) produces a verbose optimization information file.
--optimizer_interlist -os Interlists optimizer comments with assembly statements. Section 3.11
--program_level_compile -pm Combines source files to perform program-level optimization. Section 3.4
--sat_reassoc={on|off} Enables or disables the reassociation of saturating arithmetic. Section 2.3.3
Default is --sat_reassoc=off.
--aliased_variables -ma Indicates that a specific aliasing technique is used. Section 3.9
(1)
Note: Machine-specific options (see Table 2-13) can also affect optimization.
20 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Changing the Compiler's Behavior with Options
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 21
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Changing the Compiler's Behavior with Options www.ti.com
22 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Changing the Compiler's Behavior with Options
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 23
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Changing the Compiler's Behavior with Options www.ti.com
24 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Changing the Compiler's Behavior with Options
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 25
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Changing the Compiler's Behavior with Options www.ti.com
26 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Changing the Compiler's Behavior with Options
--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.11. 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:
• For Windows, use --define=name="\"string def\"". For example, --
define=car="\"sedan\""
• For UNIX, use --define=name='"string def"'. For example, --
define=car='"sedan"'
• For Code Composer Studio, enter the definition in a file and include
that file with the --cmd_file option.
--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.
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 27
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Changing the Compiler's Behavior with Options www.ti.com
--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.
--advice:power={all|none| Enables checking code against ULP (ultra low power) Advisor rules
rulespec} 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| Sets the diagnostic severity for ULP Advisor rules.
warning|remark|suppress}
--check_misra={all|required| Displays the specified amount or type of MISRA-C documentation.
advisory|none|rulespec} This option must be used if you want to enable use of the
CHECK_MISRA and RESET_MISRA pragmas within the source
code. The rulespec parameter is a comma-separated list of specifiers.
See Section 5.3 for details.
28 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Changing the Compiler's Behavior with Options
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 29
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Changing the Compiler's Behavior with Options www.ti.com
--printf_support={full| Enables support for smaller, limited versions of the printf function
nofloat|minimal} family (sprintf, fprintf, etc.) and the scanf function family (sscanf,
fscanf, etc.) run-time-support functions. The valid values are:
• full: Supports all format specifiers. This is the default.
• nofloat: Excludes support for printing and scanning floating-point
values. Supports all format specifiers except %a, %A, %f, %F, %g,
%G, %e, and %E.
• minimal: Supports the printing and scanning of integer, char, or
string values without width or precision flags. Specifically, only
the %%, %d, %o, %c, %s, and %x format specifiers are supported
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.
30 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Changing the Compiler's Behavior with Options
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 31
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Changing the Compiler's Behavior with Options www.ti.com
--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.
--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.12.
For more information on the DWARF debug format, see The DWARF
Debugging Standard.
--symdebug:dwarf_ Specifies the DWARF debugging format version (2, 3, or 4) to be
version={2|3|4} 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 is removed. This method of type merging is
superior to DWARF 2 or 3 and results in a smaller executable. In
addition, DWARF 4 reduces the size of intermediate object files in
comparison to DWARF 3. For more about 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.
32 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Changing the Compiler's Behavior with Options
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
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
NOTE: The default file extensions for object files created by the compiler have been changed in
order to prevent conflicts when C and C++ files have the same names. Object files
generated from C source files have the .c.obj extension. Object files generated from C++
source files have the .cpp.obj extension.
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 33
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Changing the Compiler's Behavior with Options www.ti.com
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
--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
34 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Changing the Compiler's Behavior with Options
NOTE: C_OPTION and C_DIR -- The C_OPTION and C_DIR environment variables are
deprecated. Use device-specific environment variables instead.
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 35
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Controlling the Compiler Through Environment Variables www.ti.com
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.
36 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Controlling the Compiler Through Environment Variables
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:
set TI_ARM_C_DIR=c:\path\one\to\tools ; c:\path\two\to\tools
• 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:\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:
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.
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 37
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Controlling the Preprocessor www.ti.com
(1)
Specified by the ISO standard
38 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Controlling the Preprocessor
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-30 in the same manner as any other defined name. For example,
printf ( "%s %s" , __TIME__ , __DATE__);
In addition, the ARM C Language Extensions (ACLE) v2.0 specification describes macros that identify
features of the ARM architecture and how the C/C++ implementation uses the architecture. All ACLE
predefined macros begin with the prefix __ARM. Table 2-31 lists the macros mentioned in the ACLE
specification and the section of the specification that provides more information. Some macros are
undefined because they are not applicable for any Cortex-M or Cortex-R processor variant.
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 39
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Controlling the Preprocessor www.ti.com
40 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Controlling the Preprocessor
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"
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:
42 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Controlling the Preprocessor
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 43
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Passing Arguments to main() www.ti.com
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.
44 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Understanding Diagnostic Messages
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);
^
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 45
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Understanding Diagnostic Messages www.ti.com
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.
46 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Understanding Diagnostic Messages
--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.
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 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.
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 47
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Generating a Raw Listing File (--gen_preprocessor_listing Option) www.ti.com
The information in the cross-reference listing file is displayed in the following format:
sym-id name X filename line number column number
48 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Using Inline Function Expansion
The --gen_preprocessor_listing option also includes diagnostic identifiers as defined in Table 2-33.
S One of the identifiers in Table 2-33 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.
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 49
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Using Inline Function Expansion www.ti.com
• The pragma FUNC_ALWAYS_INLINE (Section 5.11.13) and the equivalent always_inline attribute
(Section 5.17.2) force 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 the function is not declared as
inline and the --opt_level=0 or --opt_level=1.
• The FORCEINLINE pragma (Section 5.11.11) forces functions to be inlined in the annotated
statement. That is, it has no effect on those functions in general, only on function calls in a single
statement. The FORCEINLINE_RECURSIVE pragma forces inlining not only of calls visible in the
statement, but also in the inlined bodies of calls from that statement.
• The --disable_inlining option prevents any inlining. The pragma FUNC_CANNOT_INLINE prevents a
function from being inlined. The NOINLINE pragma prevents calls within a single statement from being
inlined. (NOINLINE is the inverse of the FORCEINLINE pragma.)
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 and C11. 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, --
opt_for_speed, and --disable_inlining.
50 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Using Inline Function Expansion
A call in a statement that is annotated with a NOINLINE pragma will not be inlined, regardless of other
indications (including a FUNC_ALWAYS_INLINE pragma or always_inline attribute on the called function).
A call in a statement that is annotated with a FORCEINLINE pragma will always be inlined, if it is not
disqualified for one of the reasons above, even if the called function has a FUNC_CANNOT_INLINE
pragma or cannot_inline attribute.
In other words, a statement-level pragma overrides a function-level pragma or attribute. If both NOINLINE
and FORCEINLINE apply to the same statement, then the one that appears first will be used and the rest
will be ignored.
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 51
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Using Interlist www.ti.com
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.11.
_main:
STMFD SP!, {LR}
;------------------------------------------------------------------------------
; 5 | printf("Hello, world\n");
;------------------------------------------------------------------------------
ADR A1, SL1
BL _printf
;------------------------------------------------------------------------------
; 6 | return 0;
;------------------------------------------------------------------------------
MOV A1, #0
LDMFD SP!, {PC}
52 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Controlling Application Binary Interface
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 53
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
VFP Support www.ti.com
54 Using the C/C++ Compiler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Enabling Entry Hook and Exit Hook Functions
--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| Specify the parameters to the hook function. The name parameter specifies
address|none} 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| Specify the parameters to the hook function. The name parameter specifies
address|none} 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.11.22 for information about the NO_HOOKS pragma.
SPNU151V – January 1998 – Revised February 2020 Using the C/C++ Compiler 55
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Chapter 3
SPNU151V – January 1998 – Revised February 2020
The compiler tools can perform many optimizations to improve the execution speed and reduce the size of
C and C++ programs by simplifying loops, rearranging statements and expressions, and allocating
variables into registers.
This chapter describes how to invoke different levels of optimization and describes which optimizations are
performed at each level. This chapter also describes how you can use the Interlist feature when
performing optimization and how you can profile or debug optimized code.
The levels of optimizations are performed by the stand-alone optimization pass. The code generator
performs several additional optimizations, particularly processor-specific optimizations. It does so
regardless of whether you invoke the optimizer. These optimizations are always enabled, although they
are more effective when the optimizer is used.
In certain circumstances, the compiler reverts to a different --call_assumptions level from the one you
specified, or it might disable program-level optimization altogether. Table 3-4 lists the combinations of --
call_assumptions levels and conditions that cause the compiler to revert to other --call_assumptions
levels.
In some situations when you use --program_level_compile and --opt_level=3, you must use a --
call_assumptions option or the FUNC_EXT_CALLED pragma. See Section 3.4.2 for information about
these situations.
Solution — Add the volatile keyword to the C/C++ variables that may be modified by the interrupts. Then,
you can optimize your code in one of these ways:
• You achieve the best optimization by applying the FUNC_EXT_CALLED pragma to all of the
entry-point functions called from the assembly language interrupts, and then compiling with --
program_level_compile --opt_level=3 --call_assumptions=2. Be sure that you use the pragma
with all of the entry-point functions. If you do not, the compiler might remove the entry-point
functions that are not preceded by the FUNC_EXT_CALLED pragma.
• Compile with --program_level_compile --opt_level=3 --call_assumptions=3. Because you do not
use the FUNC_EXT_CALLED pragma, you must use the --call_assumptions=3 option, which is
less aggressive than the --call_assumptions=2 option, and your optimization may not be as
effective.
Keep in mind that if you use --program_level_compile --opt_level=3 without additional options, the
compiler removes the C functions that the assembly functions call. Use the FUNC_EXT_CALLED
pragma to keep these functions.
--gen_profile_info tells the compiler to add instrumentation code to collect profile information. When
the program executes the run-time-support exit() function, the profile data is
written to a PDAT file. This option applies to all the C/C++ source files being
compiled on the command-line.
If the environment variable TI_PROFDATA on the host is set, the data is written
into the specified file. Otherwise, it uses the default filename: pprofout.pdat. The
full pathname of the PDAT file (including the directory name) can be specified
using the TI_PROFDATA host environment variable.
By default, the RTS profile data output routine uses the C I/O mechanism to write
data to the PDAT file. You can install a device handler for the PPHNDL device to
re-direct the profile data to a custom device driver routine. For example, this could
be used to send the profile data to a device that does not use a file system.
Feedback directed optimization requires you to turn on at least some debug
information when using the --gen_profile_info option. This enables the compiler to
output debug information that allows armpdd to correlate compiled functions and
their associated profile data.
--use_profile_info specifies the profile information file(s) to use for performing phase 2 of feedback
directed optimization. More than one profile information file can be specified on the
command line; the compiler uses all input data from multiple information files. The
syntax for the option is:
--use_profile_info==file1[, file2, ..., filen]
If no filename is specified, the compiler looks for a file named pprofout.prf in the
directory where the compiler in invoked.
-a Computes the average of the data values in the data sets instead of
accumulating data values
-e exec.out Specifies exec.out is the name of the application executable.
-o application.prf Specifies application.prf is the formatted profile feedback file that is used as the
argument to --use_profile_info during recompilation. If no output file is specified,
the default output filename is pprofout.prf.
filename .pdat Is the name of the profile data file generated by the run-time-support function.
This is the default name and it can be overridden by using the host environment
variable TI_PROFDATA.
The run-time-support function and armpdd append to their respective output files and do not overwrite
them. This enables collection of data sets from multiple runs of the application.
--gen_profile_info Adds instrumentation to the compiled code. Execution of the code results in
profile data being emitted to a PDAT file.
--use_profile_info=file.prf Uses profile information for optimization and/or generating code coverage
information.
--analyze=codecov Generates a code coverage information file and continues with profile-based
compilation. Must be used with --use_profile_info.
--analyze_only Generates only a code coverage information file. Must be used with --
use_profile_info. You must specify both --analyze=codecov and --
analyze_only to do code coverage analysis of the instrumented application.
API
Files Created
*.pdat Profile data file, which is created by executing an instrumented program and
used as input to the profile data decoder
*.prf Profiling feedback file, which is created by the profile data decoder and
used as input to the re-compilation step
You can specify two environment variables to control the destination of the code-coverage information file.
• The TI_COVDIR environment variable specifies the directory where the code-coverage file should be
generated. The default is the directory where the compiler is invoked.
• The TI_COVDATA environment variable specifies the name of the code-coverage data file generated
by the compiler. the default is filename.csv where filename is the base-name of the file being compiled.
For example, if foo.c is being compiled, the default code-coverage data file name is foo.csv.
If the code-coverage data file already exists, the compiler appends the new dataset at the end of the file.
Code-coverage data is a comma-separated list of data items that can be conveniently handled by data-
processing tools and scripting languages. The following is the format of code-coverage data:
"filename-with-full-path","funcname",line#,column#,exec-frequency,"comments"
The full filename, function name, and comments appear within quotation marks ("). For example:
"/some_dir/zlib/arm/deflate.c","_deflateInit2_",216,5,1,"( strm->zalloc )"
Other tools, such as a spreadsheet program, can be used to format and view the code coverage data.
For further information about profile-based optimization and a more detailed description of the profiling
infrastructure, see Section 3.7.
--analyze=codecov Instructs the compiler to generate code coverage analysis information. This
option replaces the previous --codecov option.
--analyze_only Halts compilation after generation of analysis information is completed.
TI_ANALYSIS_DIR Specifies the directory in which the output analysis file will be generated.
When you use the --c_src_interlist and --optimizer_interlist options with optimization, the compiler inserts
its comments and the interlist feature runs before the assembler, merging the original C/C++ source into
the assembly file.
Example 3-2 shows the function from Example 3-1 compiled with the optimization (--opt_level=2) and the -
-c_src_interlist and --optimizer_interlist options. The assembly file contains compiler comments and C
source interlisted with assembly code.
Example 3‑1. The Function From Example 2-1 Compiled With the -O2 and --optimizer_interlist Options
_main:
STMFD SP!, {LR}
;** 5 ----------------------- printf("Hello, world\n");
ADR A1, SL1
BL _printf
;** 6 ----------------------- return 0;
MOV A1, #0
LDMFD SP!, {PC}
Example 3‑2. The Function From Example 2-1 Compiled with the --opt_level=2, --optimizer_interlist, and -
-c_src_interlist Options
_main:
STMFD SP!, {LR}
;** 5 ----------------------- printf("Hello, world\n");
;------------------------------------------------------------------------------
; 5 | printf("Hello, world\n");
;------------------------------------------------------------------------------
ADR A1, SL1
BL _printf
;** 6 ----------------------- return 0;
;------------------------------------------------------------------------------
; 6 | return 0;
;------------------------------------------------------------------------------
MOV A1, #0
LDMFD SP!, {PC}
Optimization See
Cost-based register allocation Section 3.13.1
Alias disambiguation Section 3.13.1
Branch optimizations and control-flow simplification Section 3.13.3
Data flow optimizations Section 3.13.4
• Copy propagation
• Common subexpression elimination
• Redundant assignment elimination
Expression simplification Section 3.13.5
Inline expansion of functions Section 3.13.6
Function Symbol Aliasing Section 3.13.7
Induction variable optimizations and strength reduction Section 3.13.8
Loop-invariant code motion Section 3.13.9
Loop rotation Section 3.13.10
Instruction scheduling Section 3.13.11
For this example, the compiler makes aaa an alias of bbb, so that at link time all calls to function aaa
should be redirected to bbb. If the linker can successfully redirect all references to aaa, then the body of
function aaa can be removed and the symbol aaa is defined at the same address as bbb.
For information about using the GCC function attribute syntax to declare function aliases, see
Section 5.17.2
int main(int a)
{
if (a < 0)
a = a-3;
else
a = a*3;
return ++a;
}
;*********************************************************
;* FUNCTION DEF: _main *
;*********************************************************
_main:
CMP A1, #0
ADDPL A1, A1, A1, LSL #1
SUBMI A1, A1, #3
ADD A1, A1, #1
BX LR
If L10 is far away from LAB1 (large offset), the assembler converts BR into a sequence of branch around
and unconditional branches, resulting in a sequence of two instructions that are either four or six bytes
long. Instead, if the branch at LAB1 can jump to LAB2, and LAB2 is close enough that BR can be
replaced by a single short branch instruction, the resulting code is smaller as the BR in LAB1 would be
converted into one instruction that is two bytes long. LAB2 can in turn jump to another branch if L10 is too
far away from LAB2. Thus, branch chaining can be extended to arbitrary depths.
When you compile in thumb mode (--code_state=16) and for code size (--opt_for_speed is not used), the
compiler generates two psuedo instructions:
• BTcc instead of BRcc. The format is BRcc target, #[depth].
The #depth is an optional argument. If depth is not specified, it is set to the default branch chaining
depth. If specified, the chaining depth for this branch instruction is set to #depth. The assembler issues
a warning if #depth is less than zero and sets the branch chaining depth for this instruction to zero.
• BQcc instead of Bcc. The format is BQcc target , #[depth].
The #depth is the same as for the BTcc psuedo instruction.
The BT pseudo instruction replaces the BR (pseudo branch) instruction. Similarly, BQ replaces B. The
assembler performs branch chain optimizations for these instructions, if branch chaining is enabled. The
assembler replaces the BT and BQ jump targets with the offset to the branch to which these instructions
jump.
The default branch chaining depth is 10. This limit is designed to prevent longer branch chains from
impeding performance.
You can the BT and BQ instructions in assembly language programs to enable the assembler to perform
branch chaining. You can control the branch chaining depth for each instruction by specifying the
(optional) #depth argument. You must use the BR and B instructions to prevent branch chaining for any
BT or BQ branches.
The C/C++ Code Generation Tools provide two methods for linking your programs:
• You can compile individual modules and link them together. This method is especially useful when you
have multiple source files.
• You can compile and link in one step. This method is useful when you have a single source module.
This chapter describes how to invoke the linker with each method. It also discusses special requirements
of linking C/C++ code, including the run-time-support libraries, specifying the type of initialization, and
allocating the program into memory. For a complete description of the linker, see the ARM Assembly
Language Tools User's Guide.
4.1 Invoking the Linker Through the Compiler (-z Option) ............................................ 78
4.2 Linker Code Optimizations .................................................................................. 80
4.3 Controlling the Linking Process ........................................................................... 81
NOTE: The default file extensions for object files created by the compiler have been changed.
Object files generated from C source files have the .c.obj extension. Object files generated
from C++ source files have the .cpp.obj extension.
When you specify a library as linker input, the linker includes and links only those library members that
resolve undefined references. The linker uses a default allocation algorithm to allocate your program into
memory. You can use the MEMORY and SECTIONS directives in the linker command file to customize
the allocation process. For information, see the ARM Assembly Language Tools User's Guide.
You can link a C/C++ program consisting of object files prog1.c.obj, prog2.c.obj, and prog3.cpp.obj, with
an executable object file filename of prog.out with the command:
armcl --run_linker --rom_model prog1 prog2 prog3 --output_file=prog.out
--library=rtsv4_A_be_eabi.lib
The --run_linker option divides the command line into the compiler options (the options before --
run_linker) and the linker options (the options following --run_linker). The --run_linker option must follow all
source files and compiler options on the command line.
All arguments that follow --run_linker on the command line are passed to the linker. These arguments can
be linker command files, additional object files, linker options, or libraries. These arguments are the same
as described in Section 4.1.1.
All arguments that precede --run_linker on the command line are compiler arguments. These arguments
can be C/C++ source files, assembly files, or compiler options. These arguments are described in
Section 2.2.
You can compile and link a C/C++ program consisting of object files prog1.c, prog2.c, and prog3.c, with an
executable object file filename of prog.out with the command:
armcl prog1.c prog2.c prog3.c --run_linker --rom_model --output_file=prog.out
--library=rtsv4_A_be_eabi.lib
When you use armcl --run_linker after listing at least one C/C++ file to be compiled on the same command
line, by default the --rom_model is used for automatic variable initialization at run time. See Section 4.3.5
for details about using the --rom_model and --ram_model options.
<Linking>
remark: linking in "libc.a"
remark: linking in "rtsv4_A_be_eabi.lib" in place of "libc.a"
When you link your program, you must specify where to allocate the sections in memory. In general,
initialized sections are linked into ROM or RAM; uninitialized sections are linked into RAM.
The linker provides MEMORY and SECTIONS directives for allocating sections. For more information
about allocating sections into memory, see the ARM Assembly Language Tools User's Guide.
MEMORY
{
P_MEM : org = 0x00000000 len = 0x00030000 /* PROGRAM MEMORY (ROM) */
D_MEM : org = 0x00030000 len = 0x00050000 /* DATA MEMORY (RAM) */
}
SECTIONS
{
.intvecs : {} > 0x0 /* INTERRUPT VECTORS */
.bss : {} > D_MEM /* GLOBAL & STATIC VARS */
.sysmem : {} > D_MEM /* DYNAMIC MEMORY ALLOCATION AREA */
.stack : {} > D_MEM /* SOFTWARE SYSTEM STACK */
The C language supported by the ARM was developed by a committee of the American National
Standards Institute (ANSI) and subsequently adopted by the International Standards Organization (ISO).
The C++ language supported by the ARM is defined by the ANSI/ISO/IEC 14882:2014 standard with
certain exceptions.
The section numbers in the lists that follow correspond to section numbers in Appendix J of the C99
standard. The numbers in parentheses at the end of each item are sections in the C99 standard that
discuss the topic. Certain items listed in Appendix J of the C99 standard have been omitted from this list.
J.3.1 Translation
• The compiler and related tools emit diagnostic messages with several distinct formats. Diagnostic
messages are emitted to stderr; any text on stderr may be assumed to be a diagnostic. If any errors
are present, the tool will exit with an exit status indicating failure (non-zero). (3.10, 5.1.1.3)
• Nonempty sequences of white-space characters are preserved and are not replaced by a single space
character in translation phase 3. (5.1.1.2)
J.3.2 Environment
• The compiler does not support multibyte characters in identifiers, string literals, or character constants.
There is no mapping from multibyte characters to the source character set. However, the compiler
accepts multibyte characters in comments. See Section 5.6 for details. (5.1.1.2)
• The name of the function called at program startup is "main" (5.1.2.1)
• Program termination does not affect the environment; there is no way to return an exit code to the
environment. By default, the program is known to have halted when execution reaches the special
C$$EXIT label. (5.1.2.1)
• In relaxed ANSI mode, the compiler accepts "void main(void)" and "void main(int argc, char *argv[])" as
alternate definitions of main. The alternate definitions are rejected in strict ANSI mode. (5.1.2.2.1)
• If space is provided for program arguments at link time with the --args option and the program is run
under a system that can populate the .args section (such as CCS), argv[0] will contain the filename of
the executable, argv[1] through argv[argc-1] will contain the command-line arguments to the program,
and argv[argc] will be NULL. Otherwise, the value of argv and argc are undefined. (5.1.2.2.1)
• Interactive devices include stdin, stdout, and stderr (when attached to a system that honors CIO
requests). Interactive devices are not limited to those output locations; the program may access
hardware peripherals that interact with the external state. (5.1.2.3)
• Signals are not supported. The function signal is not supported. (7.14) (7.14.1.1)
• The library function getenv is implemented through the CIO interface. If the program is run under a
system that supports CIO, the system performs getenv calls on the host system and passes the result
back to the program. Otherwise the operation of getenv is undefined. No method of changing the
environment from inside the target program is provided. (7.20.4.5)
• The system function is not supported. (7.20.4.6).
J.3.3. Identifiers
• The compiler does not support multibyte characters in identifiers. See Section 5.6 for details. (6.4.2)
• The number of significant initial characters in an identifier is unlimited. (5.2.4.1, 6.4.2)
J.3.4 Characters
• The number of bits in a byte (CHAR_BIT) is 8. See Section 5.5 for details about data types. (3.6)
• The execution character set is the same as the basic execution character set: plain ASCII. Characters
in the ISO 8859 extended character set are also supported. (5.2.1)
• The values produced for the standard alphabetic escape sequences are as follows: (5.2.2)
• The value of a char object into which any character other than a member of the basic execution
character set has been stored is the ASCII value of that character. (6.2.5)
• Plain char is identical to unsigned char, but can be changed to signed char with the --
plain_char=signed option. (6.2.5, 6.3.1.1)
• The source character set and execution character set are both plain ASCII, so the mapping between
them is one-to-one. The compiler accepts multibyte characters in comments. See Section 5.6 for
details. (6.4.4.4, 5.1.1.2)
• The compiler currently supports only one locale, "C". (6.4.4.4).
• The compiler currently supports only one locale, "C". (6.4.5).
J.3.5 Integers
• No extended integer types are provided. (6.2.5)
• Negative values for signed integer types are represented as two's complement, and there are no trap
representations. (6.2.6.2)
• No extended integer types are provided, so there is no change to the integer ranks. (6.3.1.1)
• When an integer is converted to a signed integer type which cannot represent the value, the value is
truncated (without raising a signal) by discarding the bits which cannot be stored in the destination
type; the lowest bits are not modified. (6.3.1.3)
• Right shift of a signed integer value performs an arithmetic (signed) shift. The bitwise operations other
than right shift operate on the bits in exactly the same way as on an unsigned value. That is, after the
usual arithmetic conversions, the bitwise operation is performed without regard to the format of the
integer type, in particular the sign bit. (6.5)
J.3.6 Floating point
• The accuracy of floating-point operations (+ - * /) is bit-exact. The accuracy of library functions that
return floating-point results is not specified. (5.2.4.2.2)
• The compiler does not provide non-standard values for FLT_ROUNDS (5.2.4.2.2)
• The compiler does not provide non-standard negative values of FLT_EVAL_METHOD (5.2.4.2.2)
• The rounding direction when an integer is converted to a floating-point number is IEEE-754 "round to
even". (6.3.1.4)
• The rounding direction when a floating-point number is converted to a narrower floating-point number
is IEEE-754 "round to even". (6.3.1.5)
• For floating-point constants that are not exactly representable, the implementation uses the nearest
representable value. (6.4.4.2)
• The compiler does not contract float expressions. (6.5)
• The default state for the FENV_ACCESS pragma is off. (7.6.1)
• The TI compiler does not define any additional float exceptions (7.6, 7.12)
• The default state for the FP_CONTRACT pragma is off. (7.12.2)
• The "inexact" floating-point exception cannot be raised if the rounded result equals the mathematical
result. (F.9)
• The "underflow" and "inexact" floating-point exceptions cannot be raised if the result is tiny but not
inexact. (F.9)
J.3.7 Arrays and pointers
• When converting a pointer to an integer or vice versa, the pointer is considered an unsigned integer of
the same size, and the normal integer conversion rules apply.
• When converting a pointer to an integer or vice versa, if the bitwise representation of the destination
can hold all of the bits in the bitwise representation of the source, the bits are copied exactly. (6.3.2.3)
• The size of the result of subtracting two pointers to elements of the same array is the size of ptrdiff_t,
which is defined in Section 5.5. (6.5.6)
J.3.8 Hints
• When the optimizer is used, the register storage-class specifier is ignored. When the optimizer is not
used, the compiler will preferentially place register storage class objects into registers to the extent
possible. The compiler reserves the right to place any register storage class object somewhere other
than a register. (6.7.1)
• The inline function specifier is ignored unless the optimizer is used. For other restrictions on inlining,
see Section 2.11.2. (6.7.4)
J.3.9 Structures, unions, enumerations, and bit-fields
• A "plain" int bit-field is treated as a signed int bit-field. (6.7.2, 6.7.2.1)
• In addition to _Bool, signed int, and unsigned int, the compiler allows char, signed char, unsigned char,
signed short, unsigned shot, signed long, unsigned long, signed long long, unsigned long long, and
enum types as bit-field types. (6.7.2.1)
• Bit-fields may not straddle a storage-unit boundary.(6.7.2.1)
• Bit-fields are allocated in endianness order within a unit. See Section 6.2.2. (6.7.2.1)
• Non-bit-field members of structures are aligned as specified in Section 6.2.1. (6.7.2.1)
• The integer type underlying each enumerated type is described in Section 5.5.1. (6.7.2.2)
J.3.10 Qualifiers
• The TI compiler does not shrink or grow volatile accesses. It is the user's responsibility to make sure
the access size is appropriate for devices that only tolerate accesses of certain widths. The TI compiler
does not change the number of accesses to a volatile variable unless absolutely necessary. This is
significant for read-modify-write expressions such as += ; for an architecture which does not have a
corresponding read-modify-write instruction, the compiler will be forced to use two accesses, one for
the read and one for the write. Even for architectures with such instructions, it is not guaranteed that
the compiler will be able to map such expressions to an instruction with a single memory operand. It is
not guaranteed that the memory system will lock that memory location for the duration of the
instruction. In a multi-core system, some other core may write the location after a RMW instruction
reads it, but before it writes the result. The TI compiler will not reorder two volatile accesses, but it may
reorder a volatile and a non-volatile access, so volatile cannot be used to create a critical section. Use
some sort of lock if you need to create a critical section. (6.7.3)
J.3.11 Preprocessing directives
• Include directives may have one of two forms, " " or < >. For both forms, the compiler will look for a
real file on-disk by that name using the include file search path. See Section 2.5.2. (6.4.7).
• The value of a character constant in a constant expression that controls conditional inclusion matches
the value of the same character constant in the execution character set (both are ASCII). (6.10.1).
• The compiler uses the file search path to search for an included < > delimited header file. See
Section 2.5.2. (6.10.2).
• he compiler uses the file search path to search for an included " " delimited header file. See
Section 2.5.2. (6.10.2). (6.10.2).
• There is no arbitrary nesting limit for #include processing. (6.10.2).
• See Section 5.11 for a description of the recognized non-standard pragmas. (6.10.6).
• The date and time of translation are always available from the host. (6.10.8).
--check_misra={all|required|advisory|none|rulespec}
#pragma CHECK_MISRA ("{all|required|advisory|none|rulespec}")
#pragma RESET_MISRA ("{all|required|advisory|rulespec}")
--misra_advisory={error|warning|remark|suppress}
--misra_required={error|warning|remark|suppress}
--advice:power={all|none|rulespec}
The rulespec parameter is a comma-separated list of rule numbers to enable. For example, --
advice:power=1.1,7.2,7.3,7.4 enables rules 1.1, 7.2, 7.3, and 7.4.
The --advice:power_severity option sets the diagnostic severity for ULP Advisor rules. The syntax is:
--advice:power_severity={error|warning|remark|suppress}
Negative values for signed types are represented using two's complement.
The type of the storage container for an enumerated type is the smallest integer type that contains all the
enumerated values. The container types for enumerators are shown in Table 5-2.
The compiler determines the type based on the range of the lowest and highest elements of the
enumerator. For example, the following code results in an enumerator type of int:
enum COLORS
{ green = -200,
blue = 1,
yellow = 2,
red = 60000
};
The following enum fits into 16 bits instead of 32 when the --small_enum option is used.
enum a_short_enum {
bottom = -32768,
middle = 0,
top = 32767
};
NOTE: Do not link object files compiled with the --small_enum option with object files that were
compiled without it. If you use the --small_enum option, you must use it with all of your
C/C++ files; otherwise, you will encounter errors that cannot be detected until run time.
5.7 Keywords
The ARM C/C++ compiler supports all of the standard C89 keywords, including const, volatile, and
register. It supports all of the standard C99 keywords, including inline and restrict. It supports all of the
standard C11 keywords. It also supports TI extension keywords __interrupt, and __asm. Some keywords
are not available in strict ANSI mode.
The following keywords may appear in other target documentation and require the same treatment as the
interrupt and restrict keywords:
• trap
• reentrant
• cregister
Using the const keyword, you can define large constant tables and allocate them into system ROM. For
example, to allocate a ROM table, you could use the following definition:
const int digits[] = {0,1,2,3,4,5,6,7,8,9};
The name c_int00 is the C/C++ entry point. This name is reserved for the system reset interrupt. This
special interrupt routine initializes the system and calls the main() function. Because it has no caller,
c_int00 does not save any registers.
Any variable which might be modified by something external to the obvious control flow of the program
(such as an interrupt service routine) must be declared volatile. This tells the compiler that an interrupt
function might modify the value at any time, so the compiler should not perform optimizations which will
change the number or order of accesses of that variable. This is the primary purpose of the volatile
keyword. In the following example, the loop intends to wait for a location to be read as 0xFF:
unsigned int *ctrl;
while (*ctrl !=0xFF);
However, in this example, *ctrl is a loop-invariant expression, so the loop is optimized down to a single-
memory read. To get the desired result, define ctrl as:
volatile unsigned int *ctrl;
Here the *ctrl pointer is intended to reference a hardware location, such as an interrupt flag.
The volatile keyword must also be used when accessing memory locations that represent memory-
mapped peripheral devices. Such memory locations might change value in ways that the compiler cannot
predict. These locations might change if accessed, or when some other memory location is accessed, or
when some signal occurs.
Volatile must also be used for local variables in a function which calls setjmp, if the value of the local
variables needs to remain valid if a longjmp occurs.
#include <stdlib.h>
jmp_buf context;
void function()
{
volatile int x = 3;
switch(setjmp(context))
{
case 0: setup(); break;
default:
{
/* We only reach here if longjmp occurs. Because x's lifetime begins before setjmp
and lasts through longjmp, the C standard requires x be declared "volatile". */
printf("x == %d\n", x);
break;
}
}
}
The regid parameter can be __R5, __R6, or __R9. The identifiers _ _R5, _ _R6, and _ _R9 are each
bound to their corresponding register R5, R6 and R9, respectively.
When you use this declaration at the file level, the register is permanently reserved from any other use by
the optimizer and code generator for that file. You cannot assign an initial value to the register. You can
use a #define directive to assign a meaningful name to the register; for example:
register struct data_struct *__R5
#define data_pointer __R5
data_pointer->element;
data_pointer++;
There are two reasons that you would be likely to use a global register variable:
• You are using a global variable throughout your program, and it would significantly reduce code size
and execution speed to assign this variable to a register permanently.
• You are using an interrupt service routine that is called so frequently that it would significantly reduce
execution speed if the routine did not have to save and restore the register(s) it uses every time it is
called.
You need to consider very carefully the implications of reserving a global register variable. Registers are a
precious resource to the compiler, and using this feature indiscriminately may result in poorer code.
You also need to consider carefully how code with a globally declared register variable interacts with other
code, including library functions, that does not recognize the restriction placed on the register.
Because the registers that can be global register variables are save-on-entry registers, a normal function
call and return does not affect the value in the register and neither does a normal interrupt. However,
when you mix code that has a globally declared register variable with code that does not have the register
reserved, it is still possible for the value in the register to become corrupted. To avoid the possibility of
corruption, you must follow these rules:
• Functions that alter global register variables cannot be called by functions that are not aware of the
global register. Use the -r shell option to reserve the register in code that is not aware of the global
register declaration. You must be careful if you pass a pointer to a function as an argument. If the
passed function alters the global register variable and the called function saves the register, the value
in the register will be corrupted.
• You cannot access a global register variable in an interrupt service routine unless you recompile all
code, including all libraries, to reserve the register. This is because the interrupt routine can be called
from any point in the program.
• The longjmp ( ) function restores global register variables to the values they had at the setjmp ( )
location. If this presents a problem in your code, you must alter the code for the function and recompile
rts.src.
The -r register compiler command-line option allows you to prevent the compiler from using the named
register. This lets you reserve the named register in modules that do not have the global register
variable declaration, such as the run-time-support libraries, if you need to compile the modules to
prevent some of the above occurrences.
The compiler copies the argument string directly into your output file. The assembler text must be
enclosed in double quotes. All the usual character string escape codes retain their definitions. For
example, you can insert a .byte directive that contains quotes as follows:
__asm("STR: .byte \"abc\"");
The naked function attribute can be used to identify functions that are written as embedded assembly
functions using __asm statements. See Section 5.17.2.
The inserted code must be a legal assembly language statement. Like all assembly language statements,
the line of code inside the quotes must begin with a label, a blank, a tab, or a comment (asterisk or
semicolon). The compiler performs no checking on the string; if there is an error, the assembler detects it.
For more information about the assembly language statements, see the ARM Assembly Language Tools
User's Guide.
The __asm statements do not follow the syntactic restrictions of normal C/C++ statements. Each can
appear as a statement or a declaration, even outside of blocks. This is useful for inserting directives at the
very beginning of a compiled module.
The __asm statement does not provide any way to refer to local variables. If your assembly code needs to
refer to local variables, you will need to write the entire function in assembly code.
For more information, refer to Section 6.6.5.
100 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Pragma Directives
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 101
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Pragma Directives www.ti.com
The arguments func and symbol cannot be defined or declared inside the body of a function. You must
specify the pragma outside the body of a function; and the pragma specification must occur before any
declaration, definition, or reference to the func or symbol argument. If you do not follow these rules, the
compiler issues a warning and may ignore the pragma.
For pragmas that apply to functions or symbols, the syntax differs between C and C++.
• In C, you must supply the name of the object or function to which you are applying the pragma as the
first argument. Because the entity operated on is specified, a pragma in C can appear some distance
way from the definition of that entity.
• In C++, pragmas are positional. They do not name the entity on which they operate as an argument.
Instead, they always operate on the next entity defined after the pragma.
Note that in C++, the arguments to the CALLS pragma must be the full mangled names for the functions
that can be indirectly called from the calling function.
The GCC-style "calls" function attribute (see Section 5.17.2), which has the same effect as the CALLS
pragma, has the following syntax:
__attribute__((calls("function_1","function_2",..., "function_n")))
The rulespec parameter is a comma-separated list of rule numbers. See Section 5.3 for details.
The RESET_MISRA pragma can be used to reset any CHECK_MISRA pragmas; see Section 5.11.25.
102 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Pragma Directives
The rulespec parameter is a comma-separated list of rule numbers. See Section 5.4 for the syntax. See
www.ti.com/ulpadvisor for a list of rules.
The RESET_ULP pragma can be used to reset any CHECK_ULP pragmas; see Section 5.11.26.
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 103
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Pragma Directives www.ti.com
int fn(int x)
{
return x;
}
.sect "my_sect"
.align 4
.state32
.global fn
;*****************************************************************************
;* FUNCTION NAME: fn *
;* *
;* Regs Modified : SP *
;* Regs Used : A1,SP *
;* Local Frame Size : 0 Args + 4 Auto + 0 Save = 4 byte *
;*****************************************************************************
fn:
;* --------------------------------------------------------------------------*
SUB SP, SP, #8
STR A1, [SP, #0] ; |4|
ADD SP, SP, #8
BX LR
104 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Pragma Directives
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 105
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Pragma Directives www.ti.com
Example 5-4 through Example 5-6 demonstrate the use of the DATA_SECTION pragma.
char bufferA[512];
#pragma DATA_SECTION("my_sect")
char bufferB[512];
.global _bufferA
.bss _bufferA,512,4
.global _bufferB
_bufferB: .usect "my_sect",512,4
106 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Pragma Directives
The syntax of the diag_suppress, diag_remark, diag_warning, and diag_error pragmas in C is:
#pragma DUAL_STATE
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 107
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Pragma Directives www.ti.com
#pragma FORCEINLINE
For example, in the following example, the mytest() and getname() functions are inlined, but the error()
function is not.
#pragma FORCEINLINE
if (!mytest(getname(myvar))) {
error();
}
Placing the FORCEINLINE pragma before the call to error() would inline that function but not the others.
For information about interactions between command-line options, pragmas, and keywords that affect
inlining, see Section 2.11.
Notice that the FORCEINLINE, FORCEINLINE_RECURSIVE, and NOINLINE pragmas affect only the
C/C++ statement that follows the pragma. The FUNC_ALWAYS_INLINE and FUNC_CANNOT_INLINE
pragmas affect an entire function.
#pragma FORCEINLINE_RECURSIVE
For information about interactions between command-line options, pragmas, and keywords that affect
inlining, see Section 2.11.
108 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Pragma Directives
#pragma FUNC_ALWAYS_INLINE
#pragma FUNC_CANNOT_INLINE
#pragma FUNC_EXT_CALLED
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 109
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Pragma Directives www.ti.com
Except for _c_int00, which is the name reserved for the system reset interrupt for C/C++programs, the
name of the interrupt (the func argument) does not need to conform to a naming convention.
When you use program-level optimization, you may need to use the FUNC_EXT_CALLED pragma with
certain options. See Section 3.4.2.
Supported options for this pragma are --opt_level, --auto_inline, --code_state, and --opt_for_speed. In
order to use --opt_level and --auto_inline with the FUNCTION_OPTIONS pragma, the compiler must be
invoked with some optimization level (that is, at least --opt_level=0).
The GCC interrupt attribute syntax, which has the same effects as the INTERRUPT pragma, is as follows.
Note that the interrupt attribute can precede either the function's definition or its declaration.
110 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Pragma Directives
In C, the argument func is the name of a function. In C++, the pragma applies to the next function
declared. The optional argument interrupt_type specifies an interrupt type. The registers that are saved
and the return sequence depend upon the interrupt type. If the interrupt type is omitted from the interrupt
pragma, the interrupt type IRQ is assumed. These are the valid interrupt types:
Except for _c_int00, which is the name reserved for the system reset interrupt for C programs, the name
of the interrupt (the func argument) does not need to conform to a naming convention.
For the Cortex-M architectures, the interrupt_type can be nothing (default) or SWI. The hardware performs
the necessary saving and restoring of context for interrupts. Therefore, the compiler does not distinguish
between the different interrupt types. The only exception is for software interrupts (SWIs) which are
allowed to have arguments (for Cortex-M architectures, C SWI handlers cannot return values).
#pragma LOCATION(address )
int x
The NOINIT pragma may be used in conjunction with the LOCATION pragma to map variables to special
memory locations; see Section 5.11.20.
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 111
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Pragma Directives www.ti.com
The arguments min and max are programmer-guaranteed minimum and maximum trip counts. The trip
count is the number of times a loop iterates. The trip count of the loop must be evenly divisible by multiple.
All arguments are optional. For example, if the trip count could be 5 or greater, you can specify the
argument list as follows:
#pragma MUST_ITERATE(5)
However, if the trip count could be any nonzero multiple of 5, the pragma would look like this:
#pragma MUST_ITERATE(5, , 5) /* Note the blank field for max */
It is sometimes necessary for you to provide min and multiple in order for the compiler to perform
unrolling. This is especially the case when the compiler cannot easily determine how many iterations the
loop will perform (that is, the loop has a complex exit condition).
When specifying a multiple via the MUST_ITERATE pragma, results of the program are undefined if the
trip count is not evenly divisible by multiple. Also, results of the program are undefined if the trip count is
less than the minimum or greater than the maximum specified.
If no min is specified, zero is used. If no max is specified, the largest possible number is used. If multiple
MUST_ITERATE pragmas are specified for the same loop, the smallest max and largest min are used.
In this example, the compiler attempts to generate a loop even without the pragma. However, if
MUST_ITERATE is not specified for a loop such as this, the compiler generates code to bypass the loop,
to account for the possibility of 0 iterations. With the pragma specification, the compiler knows that the
loop iterates at least once and can eliminate the loop-bypassing code.
MUST_ITERATE can specify a range for the trip count as well as a factor of the trip count. The following
example tells the compiler that the loop executes between 8 and 48 times and the trip_count variable is a
multiple of 8 (8, 16, 24, 32, 40, 48). The multiple argument allows the compiler to unroll the loop.
#pragma MUST_ITERATE(8, 48, 8)
for(i = 0; i < trip_count; i++) { ...
112 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Pragma Directives
You should consider using MUST_ITERATE for loops with complicated bounds. In the following example,
the compiler would have to generate a divide function call to determine, at run time, the number of
iterations performed.
for(i2 = ipos[2]; i2 < 40; i2 += 5) { ...
The compiler will not do the above. In this case, using MUST_ITERATE to specify that the loop always
executes eight times allows the compiler to attempt to generate a loop:
#pragma MUST_ITERATE(8, 8)
NOTE: When using these pragmas in non-volatile FRAM memory, the memory region could be
protected against unintended writes through the device's Memory Protection Unit. Some
devices have memory protection enabled by default. Please see the information about
memory protection in the datasheet for your device. If the Memory Protection Unit is enabled,
it first needs to be disabled before modifying the variables.
If you are using non-volatile RAM, you can define a persistent variable with an initial value of zero loaded
into RAM. The program can increment that variable over time as a counter, and that count will not
disappear if the device loses power and restarts, because the memory is non-volatile and the boot
routines do not initialize it back to zero. For example:
#pragma PERSISTENT(x)
#pragma location = 0xC200 // memory address in RAM
int x = 0;
void main() {
run_init();
while (1) {
run_actions(x);
__delay_cycles(1000000);
x++;
}
}
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 113
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Pragma Directives www.ti.com
#pragma NOINIT (x )
int x;
#pragma PERSISTENT (x )
int x=10;
#pragma NOINIT
int x;
#pragma PERSISTENT
int x=10;
int x __attribute__((noinit));
int x __attribute__((persistent)) = 0;
#pragma NOINLINE
For information about interactions between command-line options, pragmas, and keywords that affect
inlining, see Section 2.11.
#pragma NO_HOOKS
114 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Pragma Directives
struct foo
{
int member;
};
This pragma is not part of the C or C++ standard, but it is a widely-supported preprocessor directive. Note
that this pragma does not protect against the inclusion of a header file with the same contents that has
been copied to another directory.
The above form of the pack pragma affects all class, struct, or union type declarations that follow this
pragma in a file. It forces the maximum alignment of each field to be the value specified by n. Valid values
for n are 1, 2, 4, 8, and 16 bytes.
The above form of the pack pragma affects only class, struct, and union type declarations between push
and pop directives. (A pop directive with no prior push results in a warning diagnostic from the compiler.)
The maximum alignment of all fields declared is n. Valid values for n are 1, 2, 4, 8, and 16 bytes.
The above form of the pack pragma sends a warning diagnostic to stderr to record the current state of the
pack pragma stack. You can use this form while debugging.
For more about packed fields, see Section 5.17.4.
The rulespec parameter is a comma-separated list of rule numbers. See Section 5.3 for details.
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 115
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Pragma Directives www.ti.com
The rulespec parameter is a comma-separated list of rule numbers. See Section 5.4 for details. See
www.ti.com/ulpadvisor for a list of rules.
#pragma RETAIN
116 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Pragma Directives
In Example 5-7 x and y are put in the section mydata. To reset the current section to the default used by
the compiler, a blank parameter should be passed to the pragma. An easy way to think of the pragma is
that it is like applying the CODE_SECTION or DATA_SECTION pragma to all symbols below it.
#pragma SET_DATA_SECTION("mydata")
int x;
int y;
#pragma SET_DATA_SECTION()
The pragmas apply to both declarations and definitions. If applied to a declaration and not the definition,
the pragma that is active at the declaration is used to set the section for that symbol. Here is an example:
#pragma SET_CODE_SECTION("func1")
extern void func1();
#pragma SET_CODE_SECTION()
...
void func1() { ... }
In Example 5-8 func1 is placed in section func1. If conflicting sections are specified at the declaration and
definition, a diagnostic is issued.
The current CODE_SECTION and DATA_SECTION pragmas and GCC attributes can be used to override
the SET_CODE_SECTION and SET_DATA_SECTION pragmas. For example:
In Example 5-9 x is placed in x_data and y is placed in mydata. No diagnostic is issued for this case.
The pragmas work for both C and C++. In C++, the pragmas are ignored for templates and for implicitly
created objects, such as implicit constructors and virtual function tables.
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 117
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Pragma Directives www.ti.com
Calls to the applied function are compiled as software interrupts whose number is swi_number. The
swi_number variable must be an integer constant.
A function prototype must exist for the alias and it must occur after the pragma and before the alias is
used. Software interrupts whose number is not known until run time are not supported.
For information about using the GCC function attribute syntax to declare function aliases, see
Section 5.17.2.
For more information about using software interrupts, including restrictions on passing arguments and
register usage, see Section 6.7.5.
main()
{
if (!put("one", 1)) /* calling "put" invokes SWI #48 with 2 arguments */
error(); /* and returns a result. */
}
;***************************************************************
;* FUNCTION DEF: _main *
;***************************************************************
_main:
STMFD SP!, {LR}
ADR A1, SL1
MOV A2, #1
SWI #48 ; SWI #48 is generated for the function call
CMP A1, #0
BLEQ _error
MOV A1, #0
LDMFD SP!, {PC}
118 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Pragma Directives
#pragma TASK
#pragma UNROLL( n )
If possible, the compiler unrolls the loop so there are n copies of the original loop. The compiler only
unrolls if it can determine that unrolling by a factor of n is safe. In order to increase the chances the loop is
unrolled, the compiler needs to know certain properties:
• The loop iterates a multiple of n times. This information can be specified to the compiler via the
multiple argument in the MUST_ITERATE pragma.
• The smallest possible number of iterations of the loop
• The largest possible number of iterations of the loop
The compiler can sometimes obtain this information itself by analyzing the code. However, sometimes the
compiler can be overly conservative in its assumptions and therefore generates more code than is
necessary when unrolling. This can also lead to not unrolling at all. Furthermore, if the mechanism that
determines when the loop should exit is complex, the compiler may not be able to determine these
properties of the loop. In these cases, you must tell the compiler the properties of the loop by using the
MUST_ITERATE pragma.
Specifying #pragma UNROLL(1) asks that the loop not be unrolled. Automatic loop unrolling also is not
performed in this case.
If multiple UNROLL pragmas are specified for the same loop, it is undefined which pragma is used, if any.
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 119
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Pragma Directives www.ti.com
#pragma WEAK
The WEAK pragma makes symbol a weak reference if it is a reference, or a weak definition, if it is a
definition. The symbol can be a data or function variable. In effect, unresolved weak references do not
cause linker errors and do not have any effect at run time. The following apply for weak references:
• Libraries are not searched to resolve weak references. It is not an error for a weak reference to remain
unresolved.
• During linking, the value of an undefined weak reference is:
– Zero if the relocation type is absolute
– The address of the place if the relocation type is PC-relative
– The address of the nominal base address if the relocation type is base-relative.
A weak definition does not change the rules by which object files are selected from libraries. However, if a
link set contains both a weak definition and a non-weak definition, the non-weak definition is always used.
The WEAK pragma has the same effect as using the weak function or variable attribute. See
Section 5.17.2 and Section 5.17.3, respectively.
The argument string_literal is interpreted in the same way the tokens following a #pragma directive are
processed. The string_literal must be enclosed in quotes. A quotation mark that is part of the string_literal
must be preceded by a backward slash.
You can use the _Pragma operator to express #pragma directives in macros. For example, the
DATA_SECTION syntax:
#pragma DATA_SECTION( func ," section ")
Is represented by the _Pragma() operator syntax:
_Pragma ("DATA_SECTION( func ,\" section \")")
The following code illustrates using _Pragma to specify the DATA_SECTION pragma in a macro:
...
#define EMIT_PRAGMA(x) _Pragma(#x)
#define COLLECT_DATA(var) EMIT_PRAGMA(DATA_SECTION(var,"mysection"))
COLLECT_DATA(x)
int x;
...
The EMIT_PRAGMA macro is needed to properly expand the quotes that are required to surround the
section argument to the DATA_SECTION pragma.
120 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Application Binary Interface
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 121
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
ARM Instruction Intrinsics www.ti.com
122 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com ARM Instruction Intrinsics
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 123
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
ARM Instruction Intrinsics www.ti.com
Table 5-4 shows the calling syntax for each intrinsic, along with the corresponding assembly instruction
and a description. See Table 5-3 for a list of which intrinsics are available on the different ARM targets.
Additional intrinsices for getting and setting the CPSR register and to enable/disable interrupts are
provided in Section 6.8.1.
124 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com ARM Instruction Intrinsics
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 125
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
ARM Instruction Intrinsics www.ti.com
126 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com ARM Instruction Intrinsics
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 127
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
ARM Instruction Intrinsics www.ti.com
128 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com ARM Instruction Intrinsics
In addition, the compiler supports many of the intrinsics described in the ARM C Language Extensions
(ACLE) specification. These intrinsics are applicable for the Cortex-M and Cortex-R processor variants.
The ACLE intrinsics are implemented in order to support the development of source code that can be
compiled using ACLE-compliant compilers from multiple vendors for a variety of ARM processors. A
number of the intrinsics are duplicates of intrinsics listed in the previous table but with slightly different
names (such as one vs. two leading underscores).
The compiler does not support all of the ACLE intrinsics listed in the ACLE specification. For example, the
__cls, __clsl, and __clsll ACLE intrinsics are not supported, because the CLS instruction is not available
on the Cortex-M or Cortex-R architectures.
In order to use the ACLE intrinsics, your code must include the provided arm_acle.h header file. For
details about the ACLE intrinsics, see the ACLE specification. For information about which ACLE intrinsics
are supported, see the arm_acle.h file. Where applicable, the declarations of ACLE intrinsics that are not
supported are enclosed in comments in that header file along with a brief explanation of why the intrinsic
is not supported and a reference to the appropriate section in the ACLE specification where the intrinsic is
described.
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 129
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Object File Symbol Naming Conventions (Linknames) www.ti.com
The linkname of foo is $__foo__Fi, indicating that foo is a 16-bit function that takes a single argument of
type int. To aid inspection and debugging, a name demangling utility is provided that demangles names
into those found in the original C++ source. See Chapter 8 for more information.
The mangling algorithm follows that described in the Itanium C++ ABI (http://www.codesourcery.com/cxx-
abi/abi.html).
int foo(int i) { } would be mangled "_Z3fooi"
130 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Changing the ANSI/ISO C/C++ Language Mode
The default is relaxed ANSI/ISO mode. Under relaxed ANSI/ISO mode, the compiler accepts language
extensions that could potentially conflict with ANSI/ISO C/C++. Under strict ANSI mode, these language
extensions are suppressed so that the compiler will accept all strictly conforming programs. (See
Section 5.16.3.)
If you want to link object files created with the TI CodeGen tools with object files generated by other
compiler tool chains, the ARM standard specifies that you should define the
_AEABI_PORTABILITY_LEVEL preprocessor symbol as follows before #including any standard header
files, such as <stdlib.h>.
#define _AEABI_PORTABILITY_LEVEL 1
This definition enables full portability. Defining the symbol to 0 specifies that the "C standard" portability
level will be used.
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 131
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Changing the ANSI/ISO C/C++ Language Mode www.ti.com
5.16.3 Strict ANSI Mode and Relaxed ANSI Mode (--strict_ansi and --relaxed_ansi)
Under relaxed ANSI/ISO mode (the default), the compiler accepts language extensions that could
potentially conflict with a strictly conforming ANSI/ISO C/C++ program. Under strict ANSI mode, these
language extensions are suppressed so that the compiler will accept all strictly conforming programs.
Use the --strict_ansi option when you know your program is a conforming program and it will not compile
in relaxed mode. In this mode, language extensions that conflict with ANSI/ISO C/C++ are disabled and
the compiler will emit error messages where the standard requires it to do so. Violations that are
considered discretionary by the standard may be emitted as warnings instead.
Examples:
The following is strictly conforming C code, but will not be accepted by the compiler in the default relaxed
mode. To get the compiler to accept this code, use strict ANSI mode. The compiler will suppress the
interrupt keyword language exception, and interrupt may then be used as an identifier in the code.
int main()
{
int interrupt = 0;
return 0;
}
The following is not strictly conforming code. The compiler will not accept this code in strict ANSI mode.
To get the compiler to accept it, use relaxed ANSI mode. The compiler will provide the interrupt keyword
extension and will accept the code.
interrupt void isr(void);
int main()
{
return 0;
}
The following code is accepted in all modes. The __interrupt keyword does not conflict with the ANSI/ISO
C standard, so it is always available as a language extension.
__interrupt void isr(void);
int main()
{
return 0;
}
The default mode is relaxed ANSI. This mode can be selected with the --relaxed_ansi (or -pr) option.
Relaxed ANSI mode accepts the broadest range of programs. It accepts all TI language extensions, even
those which conflict with ANSI/ISO, and ignores some ANSI/ISO violations for which the compiler can do
something reasonable. Some GCC language extensions described in Section 5.17 may conflict with strict
ANSI/ISO standards, but many do not conflict with the standards.
132 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com GNU, Clang, and ACLE Language Extensions
5.17.1 Extensions
Most of the GCC language extensions are available in the TI compiler when compiling in relaxed ANSI
mode (--relaxed_ansi).
The extensions that the TI compiler supports are listed in Table 5-5, which is based on the list of
extensions found at the GNU web site. The shaded rows describe extensions that are not supported.
(1)
Feature defined for GCC 3.0; definition and examples at http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/C-Extensions.html#C-
Extensions
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 133
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
GNU, Clang, and ACLE Language Extensions www.ti.com
134 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com GNU, Clang, and ACLE Language Extensions
• malloc
• naked
• noinline
• noreturn
• pure
• ramfunc
• section
• target
• unused
• used
• warn_unused_result
• weak
The following additional TI-specific function attribute is supported:
• retain
For example, this function declaration uses the alias attribute to make "my_alias" a function alias for the
"myFunc" function:
void my_alias() __attribute__((alias("myFunc")));
The aligned function attribute has the same effect as the CODE_ALIGN pragma. See Section 5.11.4
The always_inline function attribute has the same effect as the FUNC_ALWAYS_INLINE pragma. See
Section 5.11.13
The calls attribute has the same effect as the CALLS pragma, which is described in Section 5.11.1.
The format attribute is applied to the declarations of printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf,
vsnprintf, scanf, fscanf, vfscanf, vscanf, vsscanf, and sscanf in stdio.h. Thus when GCC extensions are
enabled, the data arguments of these functions are type checked against the format specifiers in the
format string argument and warnings are issued when there is a mismatch. These warnings can be
suppressed in the usual ways if they are not desired.
See Section 5.11.17 for more about using the interrupt function attribute.
The malloc attribute is applied to the declarations of malloc, calloc, realloc and memalign in stdlib.h.
The naked attribute identifies functions that are written as embedded assembly functions using __asm
statements. The compiler does not generate prologue and epilog sequences for such functions. See
Section 5.10.
The noinline function attribute has the same effect as the FUNC_CANNOT_INLINE pragma. See
Section 5.11.14
The ramfunc attribute specifies that a function will be placed in and executed from RAM. The ramfunc
attribute allows the compiler to optimize functions for RAM execution, as well as to automatically copy
functions to RAM on flash-based devices. For example:
__attribute__((ramfunc))
void f(void) {
...
}
The --ramfunc=on option specifies that all functions compiled with this option are placed in and executed
from RAM, even if this function attribute is not used.
Newer TI linker command files support the ramfunc attribute automatically by placing functions with this
attribute 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 Placing functions in RAM wiki page for more about the ramfunc attribute and option. See
the ARM Assembly Language Tools User's Guide for details on section placement.
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 135
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
GNU, Clang, and ACLE Language Extensions www.ti.com
The target attribute causes the function to be compiled in either ARM (32-bit) or Thumb (16-bit) mode.
The target attribute has the same effect as using the CODE_STATE pragma. The following examples use
the target attribute.
__attribute__((target("arm"))) void foo(int arg1, int arg2)
__attribute__((target("thumb"))) void foo(int arg1, int arg2)
Note that the "pcs" attribute described in the ACLE specification is not supported.
The retain attribute has the same effect as the RETAIN pragma (Section 5.11.27). That is, the section that
contains the function will not be omitted from conditionally linked output even if it is not referenced
elsewhere in the application.
The section attribute when used on a function has the same effect as the CODE_SECTION pragma. See
Section 5.11.5
The weak attribute has the same effect as the WEAK pragma (Section 5.11.32).
136 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com GNU, Clang, and ACLE Language Extensions
However, the members of a packed struct are byte-aligned. Thus the following does not have any bytes of
padding between or after members and totals 6 bytes:
struct __attribute__((__packed__)) packed_struct { char c1; int i; char c2; };
Subsequently, packed structures in an array are packed together without trailing padding between array
elements.
Bit fields of a packed structure are bit-aligned. The byte alignment of adjacent struct members that are not
bit fields does not change. However, there are no bits of padding between adjacent bit fields.
The packed attribute can only be applied to the original definition of a structure or union type. It cannot be
applied with a typedef to a non-packed structure that has already been defined, nor can it be applied to
the declaration of a struct or union object. Therefore, any given structure or union type can only be packed
or non-packed, and all objects of that type will inherit its packed or non-packed attribute.
The packed attribute is not applied recursively to structure types that are contained within a packed
structure. Thus, in the following example the member s retains the same internal layout as in the first
example above. There is no padding between c and s, so s falls on an unaligned boundary:
struct __attribute__((__packed__)) outer_packed_struct { char c; struct unpacked_struct s; };
It is illegal to implicitly or explicitly cast the address of a packed struct member as a pointer to any non-
packed type except an unsigned char. In the following example, p1, p2, and the call to foo are all illegal.
void foo(int *param);
struct packed_struct ps;
However, it is legal to explicitly cast the address of a packed struct member as a pointer to an unsigned
char:
unsigned char *pc = (unsigned char *)&ps.i;
The TI compiler also supports an unpacked attribute for an enumeration type to allow you to indicate that
the representation is to be an integer type that is no smaller than int; in other words, it is not packed.
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 137
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
GNU, Clang, and ACLE Language Extensions www.ti.com
If the built-in function is supported and the device has the appropriate hardware support, the built-in
function will invoke the hardware support.
If the built-in function is supported but the device does not have the appropriate hardware enabled, the
built-in function will usually become a call to an RTS library function. For example, __builtin_sqrt() will
become a call to the library function sqrt().
The __builtin_return_address() function always returns zero.
5.18 AUTOSAR
The ARM compiler supports the AUTOSAR 3.1 standard by providing the following header files:
• Compiler.h
• Platform_Types.h
• Std_Types.h
• Compiler_Cfg.h
Compiler_Cfg.h is an empty file, the contents of which should be provided by the end user. The provided
file contains information on what the contents of the file should look like. It is included by Compiler.h. If a
new Compiler_Cfg.h file is provided by the user, its include path must come before the path to the run-
time-support header files.
More information on AUTOSAR can be found at http://www.autosar.org.
138 C/C++ Language Implementation SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Compiler Limits
SPNU151V – January 1998 – Revised February 2020 C/C++ Language Implementation 139
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Chapter 6
SPNU151V – January 1998 – Revised February 2020
Run-Time Environment
This chapter describes the ARM C/C++ run-time environment. To ensure successful execution of C/C++
programs, it is critical that all run-time code maintain this environment. It is also important to follow the
guidelines in this chapter if you write assembly language functions that interface with C/C++ code.
6.1.1 Sections
The compiler produces relocatable blocks of code and data called sections. The sections are allocated
into memory in a variety of ways to conform to a variety of system configurations. For more information
about sections and allocating them, see the introductory object file information in the ARM Assembly
Language Tools User's Guide.
There are two basic types of sections:
• Initialized sections contain data or executable code. Initialized sections are usually, but not always,
read-only. The C/C++ compiler creates the following initialized sections:
– The .binit section contains boot time copy tables. This is a read-only section. For details on BINIT,
see the ARM Assembly Language Tools User's Guide.
– The .init_array section contains global constructor tables.
– The .ovly section contains copy tables for unions in which different sections have the same run
address. This is a read-only section.
– The .data section contains initialized global and static variables.
– The .const section contains read-only data, typically string constants and static-scoped objects
defined with the C/C++ qualifier const. Note that not all static-scoped objects marked "const" are
placed in the .const section (see Section 5.7.1). This is a read-only section.
– contains string constants and data defined with the C/C++ qualifier const (provided the constant is
not also defined as volatile).
– The .text section contains all the executable code. It also contains string literals, switch tables, and
compiler-generated constants. This section is usually read-only. Note that some string literals may
instead be placed in .const:.string. The placement of string literals depends on the size of the string
and the use of the --embedded_constants option.
– The .TI.crctab section contains CRC checking tables. This is a read-only section.
• Uninitialized sections reserve space in memory (usually RAM). A program can use this space at run
time to create and store variables. The compiler creates the following uninitialized sections:
– For EABI only, the .bss section reserves space for uninitialized global and static variables.
Uninitialized variables that are also unused are usually created as common symbols (unless you
specify --common=off) instead of being placed in .bss so that they can be excluded from the
resulting application.
– The .stack section reserves memory for the C/C++ software stack.
– The .sysmem section reserves space for dynamic memory allocation. This space is used by
dynamic memory allocation routines, such as malloc(), calloc(), realloc(), or new(). If a C/C++
program does not use these functions, the compiler does not create the .sysmem section.
The assembler creates the default sections .text, .bss, and .data. You can instruct the compiler to create
additional sections by using the CODE_SECTION and DATA_SECTION pragmas (see Section 5.11.5 and
Section 5.11.8).
The linker takes the individual sections from different object files and combines sections that have the
same name. The resulting output sections and the appropriate placement in memory for each section are
listed in Table 6-1. You can place these output sections anywhere in the address space as needed to
meet system requirements.
You can use the SECTIONS directive in the linker command file to customize the section-allocation
process. For more information about allocating sections into memory, see the linker description chapter in
the ARM Assembly Language Tools User's Guide.
Stack Overflow
NOTE: The compiler provides no means to check for stack overflow during compilation or at run
time. A stack overflow disrupts the run-time environment, causing your program to fail. Be
sure to allow enough space for the stack to grow. You can use the --entry_hook option to
add code to the beginning of each function to check for stack overflow; see Section 2.15.
When allocating from a heap, make sure the size of the heap is large enough for the allocation. This is
particularly important when allocating variable-length arrays.
(1)
Negative values are sign-extended to bit 31.
(2)
64-bit data is aligned on a 64-bit boundary.
For details about the size of an enum type, see Table 5-2.
S S S S S S S S S S S S S S S S S S S S S S S S S S I I I I I I
31 7 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 U U U U U U U
31 7 0
S S S S S S S S S S S S S S S S S I I I I I I I I I I I I I I I
31 15 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 U U U U U U U U U U U U U U U U
31 15 0
LEGEND: S = sign, I = signed integer, U = unsigned integer, MS = most significant, LS = least significant
6.2.1.2 float, int, and long Data Types (signed and unsigned)
The int, unsigned int, float, long and unsigned long data types are stored in memory as 32-bit objects at
word (4 byte) aligned addresses. Objects of these types are loaded to and stored from bits 0-31 of a
register, as shown in Figure 6-2. In big-endian mode, 4-byte objects are loaded to registers by moving the
first byte (that is, the lower address) of memory to bits 24-31 of the register, moving the second byte of
memory to bits 16-23, moving the third byte to bits 8-15, and moving the fourth byte to bits 0-7. In little-
endian mode, 4-byte objects are loaded to registers by moving the first byte (that is, the lower address) of
memory to bits 0-7 of the register, moving the second byte to bits 8-15, moving the third byte to bits 16-23,
and moving the fourth byte to bits 24-31.
6.2.1.3 double, long double, and long long Data Types (signed and unsigned)
Double, long double, long long and unsigned long long data types are stored in memory in a pair of
registers and are always referenced as a pair. These types are stored as 64-bit objects at word (4 byte)
aligned addresses. For FPA mode, the word at the lowest address contains the sign bit, the exponent, and
the most significant part of the mantissa. The word at the higher address contains the least significant part
of the mantissa. This is true regardless of the endianness of the target. For VFP mode, the words are
ordered based upon the endianness of the target.
Objects of this type are loaded into and stored in register pairs, as shown in Figure 6-3. The most
significant memory word contains the sign bit, exponent, and the most significant part of the mantissa. The
least significant memory word contains the least significant part of the mantissa.
Address x+ 4
LS
M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M
31 0
LEGEND: S = sign, M = mantissa, E = exponent, MS = most significant, LS = least significant
The parameter d is the offset to be added to the beginning of the class object for this pointer. The
parameter I is the index into the virtual function table, offset by 1. The index enables the NULL pointer to
be represented. Its value is -1 if the function is non-virtual. The parameter f is the pointer to the member
function if it is non-virtual, when I is 0. The 0 is the offset to the virtual function pointer within the class
object.
foo()
{
if (S.a < 0)
bar();
}
In this example, bar () is never called as bit field 'a' is unsigned. Use signed int if you need a signed bit
field.
• Bit fields of type long long are supported.
• Bit fields are treated as the declared type.
• The size and alignment of the struct containing the bit field depends on the declared type of the bit
field. For example, consider the struct:
struct st {int a:4};
This struct uses up 4 bytes and is aligned at 4 bytes.
• Unnamed bit fields affect the alignment of the struct or union. For example, consider the struct:
struct st{char a:4; int :22;};
This struct uses 4 bytes and is aligned at a 4-byte boundary.
• Bit fields declared volatile are accessed according to the bit field's declared type. A volatile bit field
reference generates exactly one reference to its storage; multiple volatile bit field accesses are not
merged.
Figure 6-4 illustrates bit-field packing, using the following bit field definitions:
struct{
int A:7
int B:10
int C:3
int D:2
int E:9
}x;
A0 represents the least significant bit of the field A; A1 represents the next least significant bit, etc. Again,
storage of bit fields in memory is done with a byte-by-byte, rather than bit-by-bit, transfer.
Big-endian memory
Byte 0 Byte 1 Byte 2 Byte 3
A A A A A A A B B B B B B B B B B C C C D D E E E E E E E E E X
6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 2 1 0 1 0 8 7 6 5 4 3 2 1 0 X
Little-endian register
MS LS
X E E E E E E E E E D D C C C B B B B B B B B B B A A A A A A A
X 8 7 6 5 4 3 2 1 0 1 0 2 1 0 9 8 7 6 5 4 3 2 1 0 6 5 4 3 2 1 0
31 0
Little-endian memory
Byte 0 Byte 1 Byte 2 Byte 3
B A A A A A A A B B B B B B B B E E D D C C C B X E E E E E E E
0 6 5 4 3 2 1 0 8 7 6 5 4 3 2 1 1 0 1 0 2 1 0 9 X 8 7 6 5 4 3 2
LEGEND: X = not used, MS = most significant, LS = least significant
Figure 6-5 illustrates a typical function call. In this example, arguments are passed to the function, and the
function uses local variables and calls another function. The first four arguments are passed to registers
R0-R3. This example also shows allocation of a local frame and argument block for the called function.
Functions that have no local variables and do not require an argument block do not allocate a local frame.
Callee’s SP
argument
block
Callee’s
local variables
Register
save area
Caller’s SP SP AP
Argument 5... Argument 1 → register R0 Argument 5...
argument
argument n Argument 2 → register R1 argument n
block
Argument 3 → register R2
Caller’s Caller’s Caller’s
Argument 4 → register R3
local variables local variables local variables
Register Register Register
High save area High High
save area save area
Since the stack grows toward smaller addresses, the local and argument data on the stack for the C/C++
function is accessed with a positive offset from the SP or the AP register.
• Any object or function declared in assembly language that is accessed or called from C/C++ must be
declared with the .def or .global directive in the assembly language modifier. This declares the symbol
as external and allows the linker to resolve references to it.
Likewise, to access a C/C++ function or object from assembly language, declare the C/C++ object with
the .ref or .global directive in the assembly language module. This creates an undeclared external
reference that the linker resolves.
extern "C" {
extern int asmfunc(int a); /* declare external asm function */
int gvar = 0; /* define global variable */
}
void main()
{
int I = 5;
.global asmfunc
.global gvar
asmfunc:
LDR r1, gvar_a
LDR r2, [r1, #0]
ADD r0, r0, r2
STR r0, [r1, #0]
MOV pc, lr
gvar_a .field gvar, 32
In the C++ program in Example 6-1, the extern "C" declaration tells the compiler to use C naming
conventions (that is, no name mangling). When the linker resolves the .global _asmfunc reference, the
corresponding definition in the assembly file will match.
The parameter i is passed in R0, and the result is returned in R0. R1 holds the address of the global gvar.
R2 holds the value of gvar before adding the value i to it.
Because you are referencing only the symbol's value as stored in the symbol table, the symbol's declared
type is unimportant. In Example 6-5, int is used. You can reference linker-defined symbols in a similar
manner.
If a C/C++ interrupt routine does not call any other functions, only those registers that the interrupt handler
uses are saved and restored. However, if a C/C++ interrupt routine does call other functions, these
functions can modify unknown registers that the interrupt handler does not use. For this reason, the
routine saves all the save-on-call registers if any other functions are called. (This excludes banked
registers.) Do not call interrupt handling functions directly.
Interrupts can be handled directly with C/C++ functions by using the INTERRUPT pragma or the
__interrupt keyword. For information, see Section 5.11.17 and Section 5.7.2, respectively.
To map Cortex-A interrupt routines to interrupt vectors you need to include a intvecs.asm file. This file will
contain assembly language directives that can be used to set up the ARM's interrupt vectors with
branches to your interrupt routines. Follow these steps to use this file:
1. Using Example 6-7 as a guide, create intvecs.asm and include your interrupt routines. For each
routine:
a. At the beginning of the file, add a .global directive that names the routine.
b. Modify the appropriate .word directive to create a branch to the name of your routine.
2. Assemble and link intvecs.asm with your applications code and with the compiler's linker control file
(lnk16.cmd or lnk32.cmd). The control file contains a SECTIONS directive that maps the .intvecs
section into the memory locations 0x00-0x1F.
For example, on an ARM v4 target, if you have written a C interrupt routine for the IRQ interrupt called
c_intIRQ and an assembly language routine for the FIQ interrupt called tim1_int, you should create
intvecs.asm as in Example 6-7.
.if __TI_EABI_ASSEMBLER
.asg c_intIRQ, C_INTIRQ
.else
.asg _c_intIRQ, C_INTIRQ
.endif
.global _c_int00
.global C_INTIRQ
.global tim1_int
.sect ".intvecs"
The compiler allocates the variables 'i' and 'a[] to .data section and the initial values are placed directly.
.global i
.data
.align 4
i:
.field 23,32 ; i @ 0
.global a
.data
.align 4
a:
.field 1,32 ; a[0] @ 0
.field 2,32 ; a[1] @ 32
.field 3,32 ; a[2] @ 64
.field 4,32 ; a[3] @ 96
.field 5,32 ; a[4] @ 128
Each compiled module that defines static or global variables contains these .data sections. The linker
treats the .data section like any other initialized section and creates an output section. In the load-time
initialization model, the sections are loaded into memory and used by the program. See Section 6.10.3.5.
In the run-time initialization model, the linker uses the data in these sections to create initialization data
and an additional compressed initialization table. The boot routine processes the initialization table to copy
data from load addresses to run addresses. See Section 6.10.3.3.
C auto init
table and data C auto init
(ROM) Loader table and data
(.cinit section) (ROM)
Boot
routine
.data
uninitialized
(RAM)
The linker defined symbols __TI_CINIT_Base and __TI_CINIT_Limit point to the start and end of the
table, respectively. Each entry in this table corresponds to one output section that needs to be initialized.
The initialization data for each output section could be encoded using different encoding.
The load address in the C auto initialization record points to initialization data with the following format:
The first 8-bits of the initialization data is the handler index. It indexes into a handler table to get the
address of a handler function that knows how to decode the following data.
The handler table is a list of 32-bit function pointers.
_TI_Handler_Table_Base:
32-bit handler 1 address
The encoded data that follows the 8-bit index can be in one of the following format types. For clarity the 8-
bit index is also depicted for each format.
8-bit index 24-bit padding 32-bit length (N) N byte initialization data (not compressed)
The compiler uses 24-bit padding to align the length field to a 32-bit boundary. The 32-bit length field
encodes the length of the initialization data in bytes (N). N byte initialization data is not compressed and is
copied to the run address as is.
The run-time support library has a function __TI_zero_init() to process this type of initialization data. The
first argument to this function is the address pointing to the byte after the 8-bit index. The second
argument is the run address from the C auto initialization record.
The compiler uses 24-bit padding to align the length field to a 32-bit boundary. The 32-bit length field
encodes the number of bytes to be zero initialized.
The run-time support library has a function __TI_zero_init() to process the zero initialization. The first
argument to this function is the address pointing to the byte after the 8-bit index. The second argument is
the run address from the C auto initialization record.
The data following the 8-bit index is compressed using Run Length Encoded (RLE) format. uses a simple
run length encoding that can be decompressed using the following algorithm:
1. Read the first byte, Delimiter (D).
2. Read the next byte (B).
3. If B != D, copy B to the output buffer and go to step 2.
4. Read the next byte (L).
a. If L == 0, then length is either a 16-bit, a 24-bit value, or we’ve reached the end of the data, read
next byte (L).
1. If L == 0, length is a 24-bit value or the end of the data is reached, read next byte (L).
a. If L == 0, the end of the data is reached, go to step 7.
b. Else L <<= 16, read next two bytes into lower 16 bits of L to complete 24-bit value for L.
2. Else L <<= 8, read next byte into lower 8 bits of L to complete 16-bit value for L.
b. Else if L > 0 and L < 4, copy D to the output buffer L times. Go to step 2.
c. Else, length is 8-bit value (L).
5. Read the next byte (C); C is the repeat character.
6. Write C to the output buffer L times; go to step 2.
7. End of processing.
The run-time support library has a routine __TI_decompress_rle24() to decompress data compressed
using RLE. The first argument to this function is the address pointing to the byte after the 8-bit index. The
second argument is the run address from the C auto initialization record.
The data following the 8-bit index is compressed using LZSS compression. The run-time support library
has the routine __TI_decompress_lzss() to decompress the data compressed using LZSS. The first
argument to this function is the address pointing to the byte after the 8-bit index. The second argument is
the run address from the C auto initialization record.
void auto_initialize()
{
unsigned char **table_ptr;
unsigned char **table_limit;
/*--------------------------------------------------------------*/
/* Check if Handler table has entries. */
/*--------------------------------------------------------------*/
if (&__TI_Handler_Table_Base >= &__TI_Handler_Table_Limit)
return;
/*---------------------------------------------------------------*/
/* Get the Start and End of the CINIT Table. */
/*---------------------------------------------------------------*/
table_ptr = (unsigned char **)&__TI_CINIT_Base;
table_limit = (unsigned char **)&__TI_CINIT_Limit;
while (table_ptr < table_limit)
{
/*-------------------------------------------------------------*/
/* 1. Get the Load and Run address. */
/* 2. Read the 8-bit index from the load address. */
/* 3. Get the handler function pointer using the index from */
/* handler table. */
/*-------------------------------------------------------------*/
unsigned char *load_addr = *table_ptr++;
unsigned char *run_addr = *table_ptr++;
unsigned char handler_idx = *load_addr++;
handler_fptr handler =
(handler_fptr)(&HANDLER_TABLE)[handler_idx];
/*-------------------------------------------------------------*/
/* 4. Call the handler and pass the pointer to the load data */
/* after index and the run address. */
/*-------------------------------------------------------------*/
(*handler)((const unsigned char *)load_addr, run_addr);
}
}
When you use the --ram_model link option, the linker does not generate C autoinitialization tables and
data. The direct initialized sections (.data) in the compiled object files are combined according to the linker
command file to generate initialized output sections. The loader loads the initialized output sections into
memory. After the load, the variables are assigned their initial values.
Since the linker does not generate the C autoinitialization tables, no boot time initialization is performed.
Figure 6-7 illustrates the initialization of variables at load time.
.data
Loader
section
.data section
(initialized)
(RAM)
Address of constructor 1
Address of constructor 2
Address of constructor n
SHT$$INIT_ARRAY$$Limit:
Initialization record n
int i = 23;
int a[5] = { 1, 2, 3, 4, 5 };
The .cinit section must contain only initialization tables in this format. When interfacing assembly language
modules, do not use the .cinit section for any other purpose.
The table in the .pinit section simply consists of a list of addresses of constructors to be called (see
Figure 6-10). The constructors appear in the table after the .cinit initialization.
Address of constructor 1
Address of constructor 2
Address of constructor 3
•
•
Address of constructor n
When you use the --rom_model or --ram_model option, the linker combines the .cinit sections from all the
C/C++ modules and appends a null word to the end of the composite .cinit section. This terminating record
appears as a record with a size field of 0 and marks the end of the initialization tables.
Likewise, the --rom_model or --ram_model link option causes the linker to combine all of the .pinit sections
from all C/C++ modules and append a null word to the end of the composite .pinit section. The boot
routine knows the end of the global constructor table when it encounters a null constructor address.
The const-qualified variables are initialized differently; see Section 5.7.1.
• None. Dual-state interworking is disabled. This level is invoked with the -md shell option. Functions
with this support can directly call the following functions:
– Functions compiled in the same state
– Functions in a different state that support dual-state interworking
Functions with this support level can indirectly call only functions that do not require a state change
and do not support dual-state interworking. Because functions with this support level do not provide
dual-state interworking, they cannot be called by a function requiring a state change.
Use this support level if you do not require dual-state interworking, have frequent indirect calls, and
cannot tolerate the additional code size or speed incurred by the indirect calls supporting dual-state
interworking.
When a program does not require any state changes, the only difference between specifying no support
and default support is that indirect calls are more complex in the default support level.
6.11.2 Implementation
Dual-state support is implemented by providing an alternate entry point for a function. This alternate entry
point is used by functions requiring a state change. Dual-state support handles the change to the correct
state and, if needed, changes the function back to the state of the caller when it returns. Also, indirect
calls set up the return address so that once the called function returns, the state can be reliably changed
back to that of the caller.
int total = 0;
total += val;
}
;***********************************************************
;* FUNCTION VENEER: _sum *
;***********************************************************
_sum:
.state32
STMFD sp!, {lr}
ADD lr, pc, #1
BX lr
.state16
BL $sum
BX pc
NOP
.state32
LDMFD sp!, {pc}
.state16
.sect ".text"
.global sum
;***********************************************************
;* FUNCTION DEF: $sum *
;***********************************************************
$sum:
PUSH {LR}
BL $max
LDR A2, CON1 ; {_total+0}
LDR A3, [A2, #0]
ADD A1, A1, A3
STR A1, [A2, #0]
POP {PC}
;***********************************************************
;* CONSTANT TABLE *
;***********************************************************
.sect ".text"
.align 4
CON1: .field _total, 32
;***********************************************************
;* FUNCTION VENEER: $max *
;***********************************************************
$max:
.state16
BX pc
NOP
.state32
B _max
.text
.global _max
;***********************************************************
;* FUNCTION DEF: _max *
;***********************************************************
_max:
CMP A1, A2
MOVLE A1, A2
BX LR
Since sum( ) is a 16-bit function, its entry point is $sum. Because it was compiled for dual-state
interworking, an alternate entry point, _sum, located in a different section is included. All calls to sum( )
requiring a state change use the _sum entry point.
The call to max( ) in sum( ) references $max, because sum( ) is a 16-bit function. If max( ) were a 16-bit
function, sum( ) would call the actual entry point for max( ). However, since max( ) is a 32-bit function,
$max is the alternate entry point for max( ) and handles the state change required by sum( ).
Some of the features of C/C++ (such as I/O, dynamic memory allocation, string operations, and
trigonometric functions) are provided as an ANSI/ISO C/C++ standard library, rather than as part of the
compiler itself. The TI implementation of this library is the run-time-support library (RTS). The C/C++
compiler implements the ISO standard library except for those facilities that handle exception conditions,
signal and locale issues (properties that depend on local language, nationality, or culture). Using the
ANSI/ISO standard library ensures a consistent set of functions that provide for greater portability.
In addition to the ANSI/ISO-specified functions, the run-time-support library includes routines that give you
processor-specific commands and direct C language I/O requests. These are detailed in Section 7.1 and
Section 7.2.
A library-build utility is provided with the code generation tools that lets you create customized run-time-
support libraries. This process is described in Section 7.4 .
SPNU151V – January 1998 – Revised February 2020 Using Run-Time-Support Functions and Building Libraries 177
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
C and C++ Run-Time Support Libraries www.ti.com
This definition enables full portability. Defining the symbol to 0 specifies that the "C standard" portability
level will be used.
• file.h -- Declares functions used by low-level I/O functions in the RTS library.
• _lock.h -- Used when declaring system-wide mutex locks. This header file is deprecated; use
_reg_mutex_api.h and _mutex.h instead.
• memory.h -- Provides the memalign() function, which is not required by the C standard.
• _mutex.h -- Declares functions used by the RTS library to help facilitate mutexes for specific resources
that are owned by the RTS. For example, these functions are used for heap or file table allocation.
• _pthread.h -- Declares low-level mutex infrastructure functions and provides support for recursive
mutexes.
• _reg_mutex_api.h -- Declares a function that can be used by an RTOS to register an underlying lock
mechanism and/or thread ID mechanism that is implemented in the RTOS but is called indirectly by the
RTS’ _mutex.h functions.
• _reg_synch_api.h -- Declares a function that can be used by an RTOS to register an underlying cache
synchronization mechanism that is implemented in the RTOS but is called indirectly by the RTS’
_data_synch.h functions.
• strings.h -- Provides additional string functions, including bcmp(), bcopy(), bzero(), ffs(), index(),
rindex(), strcasecmp(), and strncasecmp().
SPNU151V – January 1998 – Revised February 2020 Using Run-Time-Support Functions and Building Libraries 179
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
C and C++ Run-Time Support Libraries www.ti.com
See Section 5.6 for more information about extended character sets.
• The C library includes the header file <locale.h> but with a minimal implementation. The only
supported locale is the C locale. That is, library behavior that is specified to vary by locale is hard-
coded to the behavior of the C locale, and attempting to install a different locale via a call to setlocale()
will return NULL.
ArchVersion The version of the ARM architecture that the library was built for. This can be one of the
following: v4, v5, v6, v6M0, v7A8, v7R4, v7R5, or v7M3.
mode Indicates compilation mode:
T Thumb mode
A ARM mode
endian Indicates endianness:
le Little-endian library
be Big-endian library
n Indicates the library contains NEON support.
vn Indicates the library has VFP support. n designates the version. Current values are:
2 VFPv2
3 VFPv3
3D16 VFPv3D16
abi Indicates the application binary interface (ABI) used. Although the TI_ARM9_ABI and
TIARM ABIs are no longer supported, the library filename still contains "_eabi" to
distinguish the EABI libraries from older libraries.
eh Indicates the library has exception handling support
180 Using Run-Time-Support Functions and Building Libraries SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com The C I/O Functions
SPNU151V – January 1998 – Revised February 2020 Using Run-Time-Support Functions and Building Libraries 181
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
The C I/O Functions www.ti.com
void main()
{
FILE *fid;
fid = fopen("myfile","w");
fprintf(fid,"Hello, world\n");
fclose(fid);
Issuing the following compiler command compiles, links, and creates the file main.out from the run-time-
support library:
armcl main.c --run_linker --heap_size=400 --library=rtsv4_A_be_eabi.lib --output_file=main.out
182 Using Run-Time-Support Functions and Building Libraries SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com open — Open File for I/O
Description The open function opens the file specified by path and prepares it for I/O.
• The path is the filename of the file to be opened, including an optional directory path
and an optional device specifier (see Section 7.2.5).
• The flags are attributes that specify how the file is manipulated. The flags are
specified using the following symbols:
O_RDONLY (0x0000) /* open for reading */
O_WRONLY (0x0001) /* open for writing */
O_RDWR (0x0002) /* open for read & write */
O_APPEND (0x0008) /* append on each write */
O_CREAT (0x0200) /* open with file create */
O_TRUNC (0x0400) /* open with truncation */
O_BINARY (0x8000) /* open in binary mode */
Low-level I/O routines allow or disallow some operations depending on the flags used
when the file was opened. Some flags may not be meaningful for some devices,
depending on how the device implements files.
• The file_descriptor is assigned by open to an opened file.
The next available file descriptor is assigned to each new file opened.
SPNU151V – January 1998 – Revised February 2020 Using Run-Time-Support Functions and Building Libraries 183
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
close — Close File for I/O www.ti.com
Description The close function closes the file associated with file_descriptor.
The file_descriptor is the number assigned by open to an opened file.
Description The read function reads count characters into the buffer from the file associated with
file_descriptor.
• The file_descriptor is the number assigned by open to an opened file.
• The buffer is where the read characters are placed.
• The count is the number of characters to read from the file.
Description The write function writes the number of characters specified by count from the buffer to
the file associated with file_descriptor.
• The file_descriptor is the number assigned by open to an opened file.
• The buffer is where the characters to be written are located.
• The count is the number of characters to write to the file.
184 Using Run-Time-Support Functions and Building Libraries SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com lseek — Set File Position Indicator
Description The lseek function sets the file position indicator for the given file to a location relative to
the specified origin. The file position indicator measures the position in characters from
the beginning of the file.
• The file_descriptor is the number assigned by open to an opened file.
• The offset indicates the relative offset from the origin in characters.
• The origin is used to indicate which of the base locations the offset is measured from.
The origin must be one of the following macros:
SEEK_SET (0x0000) Beginning of file
SEEK_CUR (0x0001) Current value of the file position indicator
SEEK_END (0x0002) End of file
Return Value The return value is one of the following:
# new value of the file position indicator if successful
(off_t)-1 on failure
Description The unlink function deletes the file specified by path. Depending on the device, a deleted
file may still remain until all file descriptors which have been opened for that file have
been closed. See Section 7.2.3.
The path is the filename of the file, including path information and optional device prefix.
(See Section 7.2.5.)
SPNU151V – January 1998 – Revised February 2020 Using Run-Time-Support Functions and Building Libraries 185
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
rename — Rename File www.ti.com
NOTE: The optional device specified in the new name must match the device of
the old name. If they do not match, a file copy would be required to
perform the rename, and rename is not capable of this action.
186 Using Run-Time-Support Functions and Building Libraries SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com DEV_open — Open File for I/O
Syntax int DEV_open (const char * path , unsigned flags , int llv_fd );
Description This function finds a file matching path and opens it for I/O as requested by flags.
• The path is the filename of the file to be opened. If the name of a file passed to open
has a device prefix, the device prefix will be stripped by open, so DEV_open will not
see it. (See Section 7.2.5 for details on the device prefix.)
• The flags are attributes that specify how the file is manipulated. The flags are
specified using the following symbols:
O_RDONLY (0x0000) /* open for reading */
O_WRONLY (0x0001) /* open for writing */
O_RDWR (0x0002) /* open for read & write */
O_APPEND (0x0008) /* append on each write */
O_CREAT (0x0200) /* open with file create */
O_TRUNC (0x0400) /* open with truncation */
O_BINARY (0x8000) /* open in binary mode */
See POSIX for further explanation of the flags.
• The llv_fd is treated as a suggested low-level file descriptor. This is a historical
artifact; newly-defined device drivers should ignore this argument. This differs from
the low-level I/O open function.
This function must arrange for information to be saved for each file descriptor, typically
including a file position indicator and any significant flags. For the HOST version, all the
bookkeeping is handled by the debugger running on the host machine. If the device uses
an internal buffer, the buffer can be created when a file is opened, or the buffer can be
created during a read or write.
Return Value This function must return -1 to indicate an error if for some reason the file could not be
opened; such as the file does not exist, could not be created, or there are too many files
open. The value of errno may optionally be set to indicate the exact error (the HOST
device does not set errno). Some devices might have special failure conditions; for
instance, if a device is read-only, a file cannot be opened O_WRONLY.
On success, this function must return a non-negative file descriptor unique among all
open files handled by the specific device. The file descriptor need not be unique across
devices. The device file descriptor is used only by low-level functions when calling the
device-driver-level functions. The low-level function open allocates its own unique file
descriptor for the high-level functions to call the low-level functions. Code that uses only
high-level I/O functions need not be aware of these file descriptors.
SPNU151V – January 1998 – Revised February 2020 Using Run-Time-Support Functions and Building Libraries 187
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
DEV_close — Close File for I/O www.ti.com
Return Value This function should return -1 to indicate an error if the file descriptor is invalid in some
way, such as being out of range or already closed, but this is not required. The user
should not call close() with an invalid file descriptor.
Description The read function reads count bytes from the input file associated with dev_fd.
• The dev_fd is the number assigned by open to an opened file.
• The buf is where the read characters are placed.
• The count is the number of characters to read from the file.
Return Value This function must return -1 to indicate an error if for some reason no bytes could be
read from the file. This could be because of an attempt to read from a O_WRONLY file,
or for device-specific reasons.
If count is 0, no bytes are read and this function returns 0.
This function returns the number of bytes read, from 0 to count. 0 indicates that EOF
was reached before any bytes were read. It is not an error to read less than count bytes;
this is common if the are not enough bytes left in the file or the request was larger than
an internal device buffer size.
Syntax int DEV_write (int dev_fd , const char * buf , unsigned count );
Return Value This function must return -1 to indicate an error if for some reason no bytes could be
written to the file. This could be because of an attempt to read from a O_RDONLY file,
or for device-specific reasons.
188 Using Run-Time-Support Functions and Building Libraries SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com DEV_lseek — Set File Position Indicator
Description This function sets the file's position indicator for this file descriptor as lseek.
If lseek is supported, it should not allow a seek to before the beginning of the file, but it
should support seeking past the end of the file. Such seeks do not change the size of
the file, but if it is followed by a write, the file size will increase.
Return Value If successful, this function returns the new value of the file position indicator.
This function must return -1 to indicate an error if for some reason no bytes could be
written to the file. For many devices, the lseek operation is nonsensical (e.g. a computer
monitor).
Description Remove the association of the pathname with the file. This means that the file may no
longer be opened using this name, but the file may not actually be immediately removed.
Depending on the device, the file may be immediately removed, but for a device which
allows open file descriptors to point to unlinked files, the file will not actually be deleted
until the last file descriptor is closed. See Section 7.2.3.
Return Value This function must return -1 to indicate an error if for some reason the file could not be
unlinked (delayed removal does not count as a failure to unlink.)
If successful, this function returns 0.
Description This function changes the name associated with the file.
• The old_name is the current name of the file.
• The new_name is the new name for the file.
Return Value This function must return -1 to indicate an error if for some reason the file could not be
renamed, such as the file doesn't exist, or the new name already exists.
SPNU151V – January 1998 – Revised February 2020 Using Run-Time-Support Functions and Building Libraries 189
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
The C I/O Functions www.ti.com
#include <stdio.h>
#include <file.h>
#include "mydevice.h"
void main()
{
add_device("mydevice", _MSA,
MYDEVICE_open, MYDEVICE_close,
MYDEVICE_read, MYDEVICE_write,
MYDEVICE_lseek, MYDEVICE_unlink, MYDEVICE_rename);
/*-----------------------------------------------------------------------*/
/* Re-open stderr as a MYDEVICE file */
/*-----------------------------------------------------------------------*/
if (!freopen("mydevice:stderrfile", "w", stderr))
{
puts("Failed to freopen stderr");
exit(EXIT_FAILURE);
}
/*-----------------------------------------------------------------------*/
/* stderr should not be fully buffered; we want errors to be seen as */
/* soon as possible. Normally stderr is line-buffered, but this example */
/* doesn't buffer stderr at all. This means that there will be one call */
/* to write() for each character in the message. */
/*-----------------------------------------------------------------------*/
if (setvbuf(stderr, NULL, _IONBF, 0))
{
puts("Failed to setvbuf stderr");
exit(EXIT_FAILURE);
}
/*-----------------------------------------------------------------------*/
/* Try it out! */
/*-----------------------------------------------------------------------*/
printf("This goes to stdout\n");
fprintf(stderr, "This goes to stderr\n"); }
190 Using Run-Time-Support Functions and Building Libraries SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com The C I/O Functions
Use the low-level function add_device() to add your device to the device_table. The device table is a
statically defined array that supports n devices, where n is defined by the macro _NDEVICE found in
stdio.h/cstdio.
The first entry in the device table is predefined to be the host device on which the debugger is running.
The low-level routine add_device() finds the first empty position in the device table and initializes the
device fields with the passed-in arguments. For a complete description, see the add_device function.
If no device prefix is used, the HOST device will be used to open the file.
Description The add_device function adds a device record to the device table allowing that device to
be used for I/O from C. The first entry in the device table is predefined to be the HOST
device on which the debugger is running. The function add_device() finds the first empty
position in the device table and initializes the fields of the structure that represent a
device.
To open a stream on a newly added device use fopen( ) with a string of the format
devicename : filename as the first argument.
• The name is a character string denoting the device name. The name is limited to 8
characters.
• The flags are device characteristics. The flags are as follows:
_SSA Denotes that the device supports only one open stream at a time
_MSA Denotes that the device supports multiple open streams
More flags can be added by defining them in file.h.
• The dopen, dclose, dread, dwrite, dlseek, dunlink, and drename specifiers are
function pointers to the functions in the device driver that are called by the low-level
functions to perform I/O on the specified device. You must declare these functions
with the interface specified in Section 7.2.2. The device driver for the HOST that the
ARM debugger is run on are included in the C I/O library.
SPNU151V – January 1998 – Revised February 2020 Using Run-Time-Support Functions and Building Libraries 191
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
add_device — Add Device to Device Table www.ti.com
#include <file.h>
#include <stdio.h>
/****************************************************************************/
/* Declarations of the user-defined device drivers */
/****************************************************************************/
extern int MYDEVICE_open(const char *path, unsigned flags, int fno);
extern int MYDEVICE_close(int fno);
extern int MYDEVICE_read(int fno, char *buffer, unsigned count);
extern int MYDEVICE_write(int fno, const char *buffer, unsigned count);
extern off_t MYDEVICE_lseek(int fno, off_t offset, int origin);
extern int MYDEVICE_unlink(const char *path);
extern int MYDEVICE_rename(const char *old_name, char *new_name);
main()
{
FILE *fid;
add_device("mydevice", _MSA, MYDEVICE_open, MYDEVICE_close, MYDEVICE_read,
MYDEVICE_write, MYDEVICE_lseek, MYDEVICE_unlink, MYDEVICE_rename);
fid = fopen("mydevice:test","w");
fprintf(fid,"Hello, world\n");
fclose(fid);
}
192 Using Run-Time-Support Functions and Building Libraries SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Handling Reentrancy (_register_lock() and _register_unlock() Functions)
The arguments to _register_lock() and _register_unlock() should be functions which take no arguments
and return no values, and which implement some sort of global semaphore locking:
extern volatile sig_atomic_t *sema = SHARED_SEMAPHORE_LOCATION;
static int sema_depth = 0;
static void my_lock(void)
{
while (ATOMIC_TEST_AND_SET(sema, MY_UNIQUE_ID) != MY_UNIQUE_ID);
sema_depth++;
}
static void my_unlock(void)
{
if (!--sema_depth) ATOMIC_CLEAR(sema);
}
The run-time-support nests calls to _lock(), so the primitives must keep track of the nesting level.
SPNU151V – January 1998 – Revised February 2020 Using Run-Time-Support Functions and Building Libraries 193
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Library-Build Process www.ti.com
All three of these programs are provided as a non-optional feature of CCS 5.1. They are also available as
part of the optional XDC Tools feature if you are using an earlier version of CCS.
The mklib program looks for these executables in the following order:
1. in your PATH
2. in the directory getenv("CCS_UTILS_DIR")/cygwin
3. in the directory getenv("CCS_UTILS_DIR")/bin
4. in the directory getenv("XDCROOT")
5. in the directory getenv("XDCROOT")/bin
If you are invoking mklib from the command line, and these executables are not in your path, you must set
the environment variable CCS_UTILS_DIR such that getenv("CCS_UTILS_DIR")/bin contains the correct
programs.
194 Using Run-Time-Support Functions and Building Libraries SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Library-Build Process
Now that the linker has decided which library to use, it checks whether the run-time-support library is
present in TI_ARM_C_DIR . The library must be in exactly the same directory as the index library libc.a. If
the library is not present, the linker invokes mklib to build it. This happens when the library is missing,
regardless of whether the user specified the name of the library directly or allowed the linker to pick the
best library from the index library.
The mklib program builds the requested library and places it in 'lib' directory part of TI_ARM_C_DIR in the
same directory as the index library, so it is available for subsequent compilations.
Things to watch out for:
• The linker invokes mklib and waits for it to finish before finishing the link, so you will experience a one-
time delay when an uncommonly-used library is built for the first time. Build times of 1-5 minutes have
been observed. This depends on the power of the host (number of CPUs, etc).
• In a shared installation, where an installation of the compiler is shared among more than one user, it is
possible that two users might cause the linker to rebuild the same library at the same time. The mklib
program tries to minimize the race condition, but it is possible one build will corrupt the other. In a
shared environment, all libraries which might be needed should be built at install time; see
Section 7.4.2.2 for instructions on invoking mklib directly to avoid this problem.
• The index library must exist, or the linker is unable to rebuild libraries automatically.
• The index library must be in a user-writable directory, or the library is not built. If the compiler
installation must be installed read-only (a good practice for shared installation), any missing libraries
must be built at installation time by invoking mklib directly.
• The mklib program is specific to a certain version of a certain library; you cannot use one compiler
version's run-time support's mklib to build a different compiler version's run-time support library.
Some targets have many libraries, so this step can take a long time. To build a subset of the libraries,
invoke mklib individually for each desired library.
SPNU151V – January 1998 – Revised February 2020 Using Run-Time-Support Functions and Building Libraries 195
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Library-Build Process www.ti.com
Examples:
To build all standard libraries and place them in the compiler's library directory:
mklib --all --index=$C_DIR/lib
To build one standard library and place it in the compiler's library directory:
mklib --pattern=rtsv4_A_be_eabi.lib --index=$C_DIR/lib
To build a custom library that is just like rtsv4_A_be_eabi.lib, but has symbolic debugging support
enabled:
mklib --pattern=rts16.lib --extra_options="-g" --index=$C_DIR/lib --install_to=$Project/Debug
--name=rtsv4_A_be_eabi_debug.lib
196 Using Run-Time-Support Functions and Building Libraries SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Library-Build Process
SPNU151V – January 1998 – Revised February 2020 Using Run-Time-Support Functions and Building Libraries 197
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Chapter 8
SPNU151V – January 1998 – Revised February 2020
The C++ compiler implements function overloading, operator overloading, and type-safe linking by
encoding a function's prototype and namespace in its link-level name. The process of encoding the
prototype into the linkname is often referred to as name mangling. When you inspect mangled names,
such as in assembly files, disassembler output, or compiler or linker diagnostic messages, it can be
difficult to associate a mangled name with its corresponding name in the C++ source code. The C++ name
demangler is a debugging aid that translates each mangled name it detects to its original name found in
the C++ source code.
These topics tell you how to invoke and use the C++ name demangler. The C++ name demangler reads
in input, looking for mangled names. All unmangled text is copied to output unaltered. All mangled names
are demangled before being copied to output.
198 C++ Name Demangler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
www.ti.com Invoking the C++ Name Demangler
By default, the C++ name demangler outputs to standard output. You can use the -o file option if you want
to output to a file.
The following options apply only to the C++ name demangler:
SPNU151V – January 1998 – Revised February 2020 C++ Name Demangler 199
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Sample Usage of the C++ Name Demangler www.ti.com
class banana {
public:
int calories(void);
banana();
~banana();
};
int calories_in_a_banana(void)
{
banana x;
return x.calories();
}
_Z20calories_in_a_bananav:
STMFD SP!, {A3, A4, V1, LR}
MOV A1, SP
BL _ZN6bananaC1Ev
BL _ZN6banana8caloriesEv
MOV V1, A1
MOV A1, SP
BL _ZN6bananaD1Ev
MOV A1, V1
LDMFD SP!, {A3, A4, V1, LR}
BX LR
Executing the C++ name demangler demangles all names that it believes to be mangled. Enter:
armdem calories_in_a_banana.asm
The result is shown in Example 8-3. The linknames in Example 8-2 _ZN6bananaC1Ev,
_ZN6banana8caloriesEv, and _ZN6bananaD1Ev are demangled.
calories_in_a_banana():
STMFD SP!, {A3, A4, V1, LR}
MOV A1, SP
BL banana::banana()
BL banana::calories()
MOV V1, A1
MOV A1, SP
BL banana::~banana()
MOV A1, V1
LDMFD SP!, {A3, A4, V1, LR}
BX LR
200 C++ Name Demangler SPNU151V – January 1998 – Revised February 2020
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Appendix A
SPNU151V – January 1998 – Revised February 2020
Glossary
A.1 Terminology
absolute lister— A debugging tool that allows you to create assembler listings that contain absolute
addresses.
alias disambiguation— A technique that determines when two pointer expressions cannot point to the
same location, allowing the compiler to freely optimize such expressions.
aliasing— The ability for a single object to be accessed in more than one way, such as when two
pointers point to a single object. It can disrupt optimization, because any indirect reference could
refer to any other object.
allocation— A process in which the linker calculates the final memory addresses of output sections.
ANSI— American National Standards Institute; an organization that establishes standards voluntarily
followed by industries.
Application Binary Interface (ABI)— A standard that specifies the interface between two object
modules. An ABI specifies how functions are called and how information is passed from one
program component to another.
archive library— A collection of individual files grouped into a single file by the archiver.
archiver— A software program that collects several individual files into a single file called an archive
library. With the archiver, you can add, delete, extract, or replace members of the archive library.
assembler— A software program that creates a machine-language program from a source file that
contains assembly language instructions, directives, and macro definitions. The assembler
substitutes absolute operation codes for symbolic operation codes and absolute or relocatable
addresses for symbolic addresses.
assignment statement— A statement that initializes a variable with a value.
autoinitialization— The process of initializing global C variables (contained in the .cinit section) before
program execution begins.
autoinitialization at run time— An autoinitialization method used by the linker when linking C code. The
linker uses this method when you invoke it with the --rom_model link option. The linker loads the
.cinit section of data tables into memory, and variables are initialized at run time.
big endian— An addressing protocol in which bytes are numbered from left to right within a word. More
significant bytes in a word have lower numbered addresses. Endian ordering is hardware-specific
and is determined at reset. See also little endian
BIS— Bit instruction set.
block— A set of statements that are grouped together within braces and treated as an entity.
.bss section— One of the default object file sections. You use the assembler .bss directive to reserve a
specified amount of space in the memory map that you can use later for storing data. The .bss
section is uninitialized.
byte— Per ANSI/ISO C, the smallest addressable unit that can hold a character.
C/C++ compiler— A software program that translates C source statements into assembly language
source statements.
code generator— A compiler tool that takes the file produced by the parser or the optimizer and
produces an assembly language source file.
COFF— Common object file format; a system of object files configured according to a standard
developed by AT&T. This ABI is no longer supported.
command file— A file that contains options, filenames, directives, or commands for the linker or hex
conversion utility.
comment— A source statement (or portion of a source statement) that documents or improves
readability of a source file. Comments are not compiled, assembled, or linked; they have no effect
on the object file.
compiler program— A utility that lets you compile, assemble, and optionally link in one step. The
compiler runs one or more source modules through the compiler (including the parser, optimizer,
and code generator), the assembler, and the linker.
configured memory— Memory that the linker has specified for allocation.
constant— A type whose value cannot change.
cross-reference listing— An output file created by the assembler that lists the symbols that were
defined, what line they were defined on, which lines referenced them, and their final values.
.data section— One of the default object file sections. The .data section is an initialized section that
contains initialized data. You can use the .data directive to assemble code into the .data section.
direct call— A function call where one function calls another using the function's name.
directives— Special-purpose commands that control the actions and functions of a software tool (as
opposed to assembly language instructions, which control the actions of a device).
disambiguation— See alias disambiguation
dynamic memory allocation— A technique used by several functions (such as malloc, calloc, and
realloc) to dynamically allocate memory for variables at run time. This is accomplished by defining a
large memory pool (heap) and using the functions to allocate memory from the heap.
ELF— Executable and Linkable Format; a system of object files configured according to the System V
Application Binary Interface specification.
emulator— A hardware development system that duplicates the ARM operation.
entry point— A point in target memory where execution starts.
environment variable— A system symbol that you define and assign to a string. Environmental variables
are often included in Windows batch files or UNIX shell scripts such as .cshrc or .profile.
epilog— The portion of code in a function that restores the stack and returns.
executable object file— A linked, executable object file that is downloaded and executed on a target
system.
expression— A constant, a symbol, or a series of constants and symbols separated by arithmetic
operators.
external symbol— A symbol that is used in the current program module but defined or declared in a
different program module.
file-level optimization— A level of optimization where the compiler uses the information that it has about
the entire file to optimize your code (as opposed to program-level optimization, where the compiler
uses information that it has about the entire program to optimize your code).
function inlining— The process of inserting code for a function at the point of call. This saves the
overhead of a function call and allows the optimizer to optimize the function in the context of the
surrounding code.
global symbol— A symbol that is either defined in the current module and accessed in another, or
accessed in the current module but defined in another.
high-level language debugging— The ability of a compiler to retain symbolic and high-level language
information (such as type and function definitions) so that a debugging tool can use this
information.
indirect call— A function call where one function calls another function by giving the address of the
called function.
initialization at load time— An autoinitialization method used by the linker when linking C/C++ code. The
linker uses this method when you invoke it with the --ram_model link option. This method initializes
variables at load time instead of run time.
initialized section— A section from an object file that will be linked into an executable object file.
input section— A section from an object file that will be linked into an executable object file.
integrated preprocessor— A C/C++ preprocessor that is merged with the parser, allowing for faster
compilation. Stand-alone preprocessing or preprocessed listing is also available.
interlist feature— A feature that inserts as comments your original C/C++ source statements into the
assembly language output from the assembler. The C/C++ statements are inserted next to the
equivalent assembly instructions.
intrinsics— Operators that are used like functions and produce assembly language code that would
otherwise be inexpressible in C, or would take greater time and effort to code.
ISO— International Organization for Standardization; a worldwide federation of national standards
bodies, which establishes international standards voluntarily followed by industries.
K&R C— Kernighan and Ritchie C, the de facto standard as defined in the first edition of The C
Programming Language (K&R). Most K&R C programs written for earlier, non-ISO C compilers
should correctly compile and run without modification.
label— A symbol that begins in column 1 of an assembler source statement and corresponds to the
address of that statement. A label is the only assembler statement that can begin in column 1.
linker— A software program that combines object files to form an executable object file that can be
allocated into system memory and executed by the device.
listing file— An output file, created by the assembler, which lists source statements, their line numbers,
and their effects on the section program counter (SPC).
little endian— An addressing protocol in which bytes are numbered from right to left within a word. More
significant bytes in a word have higher numbered addresses. Endian ordering is hardware-specific
and is determined at reset. See also big endian
loader— A device that places an executable object file into system memory.
loop unrolling— An optimization that expands small loops so that each iteration of the loop appears in
your code. Although loop unrolling increases code size, it can improve the performance of your
code.
macro— A user-defined routine that can be used as an instruction.
macro call— The process of invoking a macro.
macro definition— A block of source statements that define the name and the code that make up a
macro.
macro expansion— The process of inserting source statements into your code in place of a macro call.
SPNU151V – January 1998 – Revised February 2020 Glossary 203
Submit Documentation Feedback
Copyright © 1998–2020, Texas Instruments Incorporated
Terminology www.ti.com
map file— An output file, created by the linker, which shows the memory configuration, section
composition, section allocation, symbol definitions and the addresses at which the symbols were
defined for your program.
memory map— A map of target system memory space that is partitioned into functional blocks.
name mangling— A compiler-specific feature that encodes a function name with information regarding
the function's arguments return types.
object file— An assembled or linked file that contains machine-language object code.
object library— An archive library made up of individual object files.
operand— An argument of an assembly language instruction, assembler directive, or macro directive
that supplies information to the operation performed by the instruction or directive.
optimizer— A software tool that improves the execution speed and reduces the size of C programs.
options— Command-line parameters that allow you to request additional or specific functions when you
invoke a software tool.
output section— A final, allocated section in a linked, executable module.
parser— A software tool that reads the source file, performs preprocessing functions, checks the syntax,
and produces an intermediate file used as input for the optimizer or code generator.
partitioning— The process of assigning a data path to each instruction.
pop— An operation that retrieves a data object from a stack.
pragma— A preprocessor directive that provides directions to the compiler about how to treat a particular
statement.
preprocessor— A software tool that interprets macro definitions, expands macros, interprets header
files, interprets conditional compilation, and acts upon preprocessor directives.
program-level optimization— An aggressive level of optimization where all of the source files are
compiled into one intermediate file. Because the compiler can see the entire program, several
optimizations are performed with program-level optimization that are rarely applied during file-level
optimization.
prolog— The portion of code in a function that sets up the stack.
push— An operation that places a data object on a stack for temporary storage.
quiet run— An option that suppresses the normal banner and the progress information.
raw data— Executable code or initialized data in an output section.
relocation— A process in which the linker adjusts all the references to a symbol when the symbol's
address changes.
run-time environment— The run time parameters in which your program must function. These
parameters are defined by the memory and register conventions, stack organization, function call
conventions, and system initialization.
run-time-support functions— Standard ISO functions that perform tasks that are not part of the C
language (such as memory allocation, string conversion, and string searches).
run-time-support library— A library file, rts.src, which contains the source for the run time-support
functions.
section— A relocatable block of code or data that ultimately will be contiguous with other sections in the
memory map.
sign extend— A process that fills the unused MSBs of a value with the value's sign bit.
Revision History
Previous Revisions:
The default file extensions for object files created by the compiler have
been changed in order to prevent conflicts when C and C++ files have
SPNU151U -- throughout -- the same names. Object files generated from C source files have the
.c.obj extension. Object files generated from C++ source files have the
.cpp.obj extension.
SPNU151T Using the Compiler Section 2.3.1 Added the --emit_references:file linker option.
Documented that C standard macros such as __STDC_VERSION__
SPNU151T Using the Compiler Section 2.5.1
are supported.
SPNU151T C/C++ Language Section 5.11.4 Added documentation for the CODE_ALIGN pragma.
SPNU151T C/C++ Language Section 5.11.20 Clarify section placement for the NOINIT and PERSISTENT pragmas.
SPNU151T C/C++ Language Section 5.14 Corrected syntax for the _norm intrinsic.
SPNU151T C/C++ Language Section 5.16.1 Updated list of C99 non-supported run-time functions.
Added documentation for the aligned, calls, naked, and weak function
SPNU151T C/C++ Language Section 5.17.2
attributes.
SPNU151T C/C++ Language Section 5.17.3 Added documentation for the location and packed variable attributes.
Run-Time Support
SPNU151T DEV_lseek topic Corrected syntax documented for DEV_lseek function.
Functions
Section 1.3,
Introduction,
Section 2.3,
SPNU151S Using the Compiler, Added support for C11.
Section 5.1, and
C/C++ Language
Section 5.16.2
Added the --ecc=on linker option, which enables ECC generation.
SPNU151S Using the Compiler Section 2.3.1
Note that ECC generation is now off by default.
The __TI_STRICT_ANSI_MODE__ and __TI_STRICT_FP_MODE__
SPNU151S Using the Compiler Section 2.5.1
macros are defined as 0 if their conditions are false.
Revised the section on inline function expansion and its subsections to
include new pragmas and changes to the compilers decision-making
Using the Compiler, Section 2.11 and
SPNU151S about what functions to inline. The FORCEINLINE,
C/C++ Language Section 5.11
FORCEINLINE_RECURSIVE, and NOINLINE pragmas have been
added.
C++11 features related to atomics are now supported. In addition,
SPNU151S C/C++ Language Section 5.2 removed several C++ features from the exception list because they
have been supported for several releases.
SPNU151S C/C++ Language Section 5.6 Added information about character sets and file encoding.
TI PROVIDES TECHNICAL AND RELIABILITY DATA (INCLUDING DATASHEETS), DESIGN RESOURCES (INCLUDING REFERENCE
DESIGNS), APPLICATION OR OTHER DESIGN ADVICE, WEB TOOLS, SAFETY INFORMATION, AND OTHER RESOURCES “AS IS”
AND WITH ALL FAULTS, AND DISCLAIMS ALL WARRANTIES, EXPRESS AND IMPLIED, INCLUDING WITHOUT LIMITATION ANY
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT OF THIRD
PARTY INTELLECTUAL PROPERTY RIGHTS.
These resources are intended for skilled developers designing with TI products. You are solely responsible for (1) selecting the appropriate
TI products for your application, (2) designing, validating and testing your application, and (3) ensuring your application meets applicable
standards, and any other safety, security, or other requirements. These resources are subject to change without notice. TI grants you
permission to use these resources only for development of an application that uses the TI products described in the resource. Other
reproduction and display of these resources is prohibited. No license is granted to any other TI intellectual property right or to any third
party intellectual property right. TI disclaims responsibility for, and you will fully indemnify TI and its representatives against, any claims,
damages, costs, losses, and liabilities arising out of your use of these resources.
TI’s products are provided subject to TI’s Terms of Sale (www.ti.com/legal/termsofsale.html) or other applicable terms available either on
ti.com or provided in conjunction with such TI products. TI’s provision of these resources does not expand or otherwise alter TI’s applicable
warranties or warranty disclaimers for TI products.
Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2020, Texas Instruments Incorporated