4.4.1. How C and C++ programs use the library functions

This section describes specific library functions that are used to initialize the execution environment and application, library exit functions, and target-dependent library functions that the application itself might call during its execution.

Initializing the execution environment and executing the application

The entry point of a program is at __main in the C library where library code does the following:

  1. Copies nonroot (RO and RW) execution regions from their load addresses to their execution addresses.

  2. Zeroes ZI regions.

  3. Branches to __rt_entry.

If you do not want the library to do this, you can define your own __main that branches to __rt_entry as in Example 4.1.

Example 4.1. __main and __rt_entry

    IMPORT __rt_entry	
    EXPORT __main	
    ENTRY	
__main
    B     __rt_entry	
    END

The library function __rt_entry() runs the program as follows:

  1. Calls __rt_stackheap_init() to set up the stack and heap.

  2. Calls __rt_lib_init() to initialize referenced library functions, initialize the locale and, if necessary, set up argc and argv for main(). For C++, calls the constructors for any top-level objects.

  3. Calls main(), the user-level root of the application.

    From main(), your program might call, among other things, library functions. See Library functions called from main() for more information.

  4. Calls exit() with the value returned by main().

Library functions called from main()

The function main() is the user-level root of the application. It requires the execution environment to be initialized, and that input/output functions can be called. While in main() the program might perform one of the following actions that calls user-customizable functions in the C library:

Copyright © 1999-2001 ARM Limited. All rights reserved.ARM DUI 0067D
Non-Confidential