You copied the Doc URL to your clipboard.

Use of static data in the C libraries

Static data refers to persistent read/write data that is not stored on the stack or the heap. Callouts from the C library enable access to static data.

Static data can be external or internal in scope, and is at a fixed address relative to the program counter (pc), when compiled with -fbare-metal-pie.

The following describes how the C libraries use static data:

  • The default floating-point arithmetic libraries fz_* and fj_* do not use static data and are always reentrant. For software floating-point, the f_* and g_* libraries use static data to store the Floating-Point (FP) status word. For hardware floating-point, the f_* and g_* libraries do not use static data.

  • All statically-initialized data in the C libraries is read-only.

  • All writable static data is zero-initialized.

Note

Exactly which functions use static data in their definitions might change in future releases.

Callouts from the C library enable access to static data. C library functions that use static data can be categorized as:

  • Functions that do not use any static data of any kind, for example fprintf().

  • Functions that manage a static state, such as malloc(), rand(), and strtok().

  • Functions that do not manage a static state, but use static data in a way that is specific to the implementation in ARM® Compiler, for example isalpha().

When the C library does something that requires implicit static data, it uses a callout to a function you can replace. These functions are shown in the following table. They do not use semihosting.

Table 1-1 C library callouts

Function Description
__rt_errno_addr() Called to get the address of the variable errno
__rt_fp_status_addr() Called by the floating-point support code to get the address of the floating-point status word
locale functions The function __user_libspace() creates a block of private static data for the library

The default implementation of __user_libspace creates a 96-byte block in the ZI region. Even if your application does not have a main() function, the __user_libspace() function does not normally have to be redefined.

Note

Exactly which functions use static data in their definitions might change in future releases.

Related reference

Was this page helpful? Yes No