This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler: How do you determine the effect of warm vs. cold start on global variable initialization?

Tool/software: TI C/C++ Compiler

As part of my work with MathWorks Embedded Coder and Polyspace software verification tools, I often have questions related to the effects of warm-start vs. cold-start on global variable initialization. Here is an example:

int globA = 2;
int globB; % default to zero by ANSI C standard
int globC; % default to zero by ANSI C standard

int main() {
    globC = 5;
    return 0;
}

It is clear to me that globC will be properly initialized in all cases since it is explicitly initialized in the main. However, for the other two it is less clear. Based on the TMS320C2x Compiler User's Guide, I understand that the _c_int0() function copies all of the explicitly initialized data from .cinit to .bss during the boot process assuming that the linker has option -c to auto-initialize at run-time. This means that a warm start which relaunches from _c_int0() will initialize globA with the -c link option. 

In section 5.7 of the Guide, we are told how you can use the linker command file to explicitly initialize the .bss section to zero. With the linker zeroing .bss and with option -c, I assume this will result in initialization at both warm and cold start for globB. Without the linker zeroing, there is only initialization for globB if provided by the loader and it would only be for a cold start.

Finally, with the linker using the -cr option, there would only ever be cold start initialization for globB and globC. This situation removes the mechanism for warm start initialization.

Is this understanding correct? Where can I find more resources on this behavior?

  • The distinction between warm start and cold start is not recognized by the compiler.  In this post, I presume execution begins with the function _c_int00 that is in the compiler RTS library supplied with the compiler.

    I further presume you build with COFF ABI, and not the newer EABI. COFF ABI is the compiler default, and remains more widely used than EABI, though that is changing.

    All that being the case, please see the article Uninitialized Static Objects Not Set to Zero in COFF.  You will learn that, for the specific example you show in your post, the variables globB and globC are not initialized to 0 by the startup code.

    For further details, please search the C28x compiler manual for the sub-chapter titled System Initialization.

    Thanks and regards,

    -George