ARM Technical Support Knowledge Articles

How do I port my project to Microlib?

Applies to: DS-5, RealView Development Suite (RVDS)


To port an existing program to use microlib, some changes to your source code and build scripts are usually required.  This FAQ gives a step by step guide on how to achieve this task.

Microlib is not a standards-compliant ISO C library. Before porting microlib into your existing program or writing a new program using microlib, it is recommended that you  check the section “Differences from the default C library” and “ISO C features missing from microlib” of the ARM Compiler Tools libraries documentation to ensure it meets your application requirements.

Step 1: Configure Stack and Heap

Specify the initial stack pointer by defining a symbol __initial_sp to be equal to the top of the stack. The initial stack pointer must be aligned to a multiple of eight bytes. Specify the start and end of the heap by defining symbols __heap_base and __heap_limit respectively, if your program uses ARM-supplied heap functions. This can be done in an assembly file or using the embedded assembler in C, for example:

__asm void dummy_function(void)
    EXPORT __initial_sp
    EXPORT __heap_base
    EXPORT __heap_limit

__initial_sp EQU STACK_BASE
__heap_base EQU HEAP_BASE
__heap_limit EQU (HEAP_BASE + HEAP_SIZE)

The above constants STACK_BASEHEAP_BASE and HEAP_SIZE can be defined in a header file (stack.h, for example) and included in the C source file defining the stack and heap symbols.

#define HEAP_BASE  0x20100000
#define STACK_BASE 0x20200000

Step 2: Prevent main() from returning

You need to make sure your main() function does not return by putting an endless loop at the end of main() function. This is because microlib does not contain any library code to handle exit from main().

while (1) ; //endless loop to prevent main() returning

Step 3: Configure RVCT to use microlib

In the build script, add the --library_type=microlib to the linker command line. This switch will cause the linker to link in the microlib instead of the default standard C library.

Step 4: Build your code

You may see error messages and need to change your code if you are using any unsupported features, for example, using OS functions such as clock(), time(). Again check the section “ISO C features missing from microlib” from the ARM Compiler Libraries documentation to ensure you are not using any of the missing features.

Article last edited on: 2011-11-01 09:07:19

Rate this article

Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential