Skip to main content

IAR Embedded Workbench for Arm 9.70.x

Interaction between the tools and your application

In this section:

The linking process and the application can interact symbolically in four ways:

  • Creating a symbol by using the linker command line option ‑‑define_symbol. The linker will create a public absolute constant symbol that the application can use as a label, as a size, as setup for a debugger, etc.

  • Creating an exported configuration symbol by using the command line option ‑‑config_def or the configuration directive define symbol, and exporting the symbol using the export symbol directive. ILINK will create a public absolute constant symbol that the application can use as a label, as a size, as setup for a debugger, etc.

    One advantage of this symbol definition is that this symbol can also be used in expressions in the configuration file, for example, to control the placement of sections into memory ranges.

  • Using the compiler operators __section_begin, __section_end, or __section_size, or the assembler operators SFB, SFE, or SIZEOF on a named section or block. These operators provide access to the start address, end address, and size of a contiguous sequence of sections with the same name, or of a linker block specified in the linker configuration file.

  • The command line option ‑‑entry informs the linker about the start label of the application. It is used by the linker as a root symbol and to inform the debugger where to start execution.

The following lines illustrate how to use -D to create a symbol. If you need to use this mechanism, add these options to your command line like this:

‑‑define_symbol NrOfElements=10
‑‑config_def MY_HEAP_SIZE=1024

The linker configuration file can look like this:

define memory Mem with size = 4G;
define region ROM = Mem:[from 0x00000 size 0x10000];
define region RAM = Mem:[from 0x20000 size 0x10000];

/* Export of symbol */
export symbol MY_HEAP_SIZE;

/* Setup a heap area with a size defined by an ILINK option */
define block MyHEAP with size = MY_HEAP_SIZE, alignment
= 8 {};

place in RAM { block MyHEAP };

Add these lines to your application source code:

#include <stdlib.h>

/* Use symbol defined by ILINK option to dynamically allocate an array of elements
with specified size. The value takes the form of a label. */
extern int NrOfElements;

typedef char Elements;
Elements *GetElementArray()
{
  return malloc(sizeof(Elements) * (long) &NrOfElements);
}
/* Use a symbol defined by ILINK option, a symbol that in the
 * configuration file was made available to the application.
 */
extern char MY_HEAP_SIZE;
/* Declare the section that contains the heap. */
#pragma section = "MYHEAP"

char *MyHeap()
{
  /* First get start of statically allocated section, */
  char *p = __section_begin("MYHEAP");

  /* ...then we zero it, using the imported size. */
  for (int i = 0; i < (int) &MY_HEAP_SIZE; ++i)
  {
    p[i] = 0;
  }
  return p;
}