How do I place a group of functions or variables in a specific section?

Technical Note 27498



3/6/2015 3:28 PM


This Technical Note covers how to do placement of a group of functions and variables, and how to take advantage of some features.

IAR Embedded Workbench for ARM 6.70 (and newer)


Two pragma directives was added in version 6.70 ...

#pragma default_variable_attributes

... and ...

#pragma default_function_attributes

... to set default placement and attributes for variable/function declarations and definitions.

This means that you can override multiple declarations and definitions by using a single #pragma.


Below is an example of how to use these pragmas:

Modify in your .icf file...

/* Modify your .icf file to use a place in directive for your section MY_FUNC. This places the following functions at an absolute address in RAM2 mem region */

define region RAM2 = mem:[from 0x20000000 to 0x20001FFF]

place in RAM2 { readonly section MY_FUNC};

In your source...

/* In your source place following functions in section MY_FUNC */
#pragma default_function_attributes = @ "MY_FUNC"

int fun1(int x)
return x + 1;
int fun2(int x)
return x - 1;

/* Stop placing functions in section MY_FUNC */
#pragma default_function_attributes =

int fun3(int x)
return x + x;

/* Place following data in section MY_DATA */
#pragma default_variable_attributes = @ "MY_DATA"

int data1;
int data2;

/* Stop placing data in section MY_DATA */
#pragma default_variable_attributes =

int data3;

int main()
data1 = fun1(5);
data2 = fun2(5);
data3 = fun3(5);

return data1 + data2 + data3;

Alternative Example

Alternatively you can place all of the functions into one or more source files and have the linker link the object files to an absolute address.

Modify in your .icf file...

/* All of the functions are located in source file func.c. 
In your linker file define RAM2 region or any named region */

define region RAM2 = mem:[from 0x20000000 to 0x20001FFF];

/* Initialize by copy the .text and .rodata portion of obj file into RAM2 */

initialize by copy { readwrite, section .text object func.o, section .rodata object func.o};

place in RAM2 { readwrite object func.o};


IAR Embedded Workbench for ARM 5.xx (and newer)


The placement of a few functions in a specific section is done with...

#pragma location="FUNCTIONS"
void h(void);

... but this becomes impractical when there are many functions to place. IAR ILINK Linker in IAR Embedded Workbench for ARM 5.xx can place all functions from a file into a specific section.

Placing many functions 

  • Collect these functions in one (or more) source files.
  • Remove any #pragma location you have earlier added.
  • Edit the .icf file with a line the holds the keyword "object" as exemplified below. For more information, please see the chapter Section-selectors in the Development Guide.


The example Edited Tutor holds an edited variant of "Tutor 1", where IAR ILINK Linker will place all code from the file Utilities.c at address 0x7000000 and higher.

The change made to the "Tutor 1", is the addition of these files to the .icf file:

define symbol __EXAMPLE_start__ = 0x7000000;
define symbol __EXAMPLE_end__ = 0x700FFFF;
define region EXAMPLE_region = mem:[from __EXAMPLE_start__ to __EXAMPLE_end__];
place in EXAMPLE_region { readonly object Utilities.o};


All product names are trademarks or registered trademarks of their respective owners.

Realated Tech Notes

© IAR Systems 1995-2016 - All rights reserved.