Placing a library in RAM

Technical Note 200401


Arm, RH850, RISC-V, RL78, RX, STM8, SuperH




2020/6/25 13:32


This Technical Note describes a method of placing a library in RAM.


Download and open the example project from (projects built with IAR Embedded Workbench for Arm 8.42.2).

The example ( contains two projects:

  • Simplelib – builds a library file (simplelib.a) containing a global array and a function returning a value from the array.
  • Place Lib in RAM – a demo project that places the library in RAM and executes the library function.

To place the library (simplelib.a) in RAM, follow these steps:

  1. Define an address range in RAM for the library code.

    define symbol region_RAM_CODE_start = 0x08010000;
    define symbol region_RAM_CODE_end = 0x0801FFFF;​

  2. Define a region for the library code.

    define region RAM_CODE_region = mem:[from region_RAM_CODE_start to region_RAM_CODE_end];​

  3. Define a block (placed in RAM) for the library code. The section selector directive collects code content from the library and the section attribute readwrite instructs the linker to link it as code executing from RAM.

    define block LIB {readwrite code object simplelib.a};​

  4. Define a block (placed in ROM) for the initializer bytes from the library. The section selection directive collects all the _init sections (the code content) from the library.

    define block LIB_INIT {readonly code section *_init object simplelib.a};​

  5. The initialize by copy directive instructs the linker to create *_init sections (containing the code content from the library) to enable copying from ROM to RAM and arrange for the startup code to copy code content from block LIB_INIT to block LIB.

    initialize by copy { readonly object simplelib.a };​

  6. The place in directive instructs the linker to place the block for the library code in RAM.

    place in RAM_CODE_region { block LIB };​

  7. The place in directive instructs the linker to place the initializer bytes (code content) from the library in ROM.

    place in ROM_region { block LIB_INIT };​


To place a library in RAM, define a region in RAM for the library, define and place a block LIB in RAM, define and place a block LIB_INIT in ROM, and finally arrange for the code contents of the library to be copied at startup from ROM to RAM.



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



We do no longer support Internet Explorer. To get the best experience of, we recommend upgrading to a modern browser such as Chrome or Edge.