10.3. Invoking the Linker

The default behavior of the tiarmclang compiler is to compile specified C, C++, or assembly source files into temporary object files and then pass those object files along with any explicitly specified object files and any specified linker options to the linker.

Alternately, if you specify only object files as input to the tiarmclang compiler, the compiler passes those files to the linker along with any specified options that are applicable to the link.

10.3.3. Passing Options to the Linker

The tiarmclang command line provides the following ways to pass options to the linker:

  • The -Wl option passes a comma-separated list of options to the linker.

  • The -Xlinker option passes a single option to the linker and can be used multiple times on the same command line.

  • A linker command file can specify options to pass to the linker.

For example, the following command line passes several linker options using the -Wl option:

tiarmclang -mcpu=cortex-m0 hello.c -o a.out -Wl,-stack=0x8000,--ram_model,link_test.cmd

The following command line passes the same linker options using the -Xlinker option:

tiarmclang -mcpu=cortex-m0 hello.c -o a.out -Xlinker -stack=0x8000 -Xlinker --ram_model -Xlinker link_test.cmd

The following lines from a linker command file, pass the same linker options to the linker:

/*********************************************************************/
/* Example Linker Command File                                       */
/*********************************************************************/
-stack  0x8000                  /* SOFTWARE STACK SIZE               */
--ram_model                     /* INITIALIZE VARIABLES AT LOAD TIME */

10.3.4. Wildcards in File, Section, and Symbol Patterns

The linker allows file, section, and symbol names to be specified using the asterisk (*) and question mark (?) wildcards. Using * matches any number of characters. Using ? matches a single character. Wildcards can make it easier to handle related objects, provided they follow a suitable naming convention.

For example:

mp3*.o      /* matches anything .o that begins with mp3    */
task?.o*    /* matches task1.o, task2.c.o, taskX.o55, etc. */

SECTIONS
{
    .fast_code: { *.o(*fast*) }                > FAST_MEM
    .vectors  : { vectors.c.o(.vector:part1:*) > 0xFFFFFF00
    .str_code : { rts*.lib<str*.c.o>(.text) }  > S1ROM
}

10.3.5. Specifying C/C++ Symbols with Linker Options

The link-time symbol is the same as the high-level language name.

For more information on symbol names, see tiarmnm - Name Utility. For information specifically about C++ symbol naming, see tiarmdem - C++ Name Demangler Utility. See Using Linker Symbols in C/C++ Applications for information about referring to linker symbols in C/C++ code.