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.

CCS/UCD3138: What optimization levels in the CCS ARM 7 compiler move RAM variables around?

Part Number: UCD3138

Tool/software: Code Composer Studio

The UCD3138064 provides a capability to download a new code and switch to it while still running a power supply.  To facilitate fast switching, we need to have the RAM variables remain in the same locations in the new version of the code.  So far as I can tell, CCS only starts optimizing RAM locations when you use optimization level 4 - Whole Program Optimizations.  Is this the case, or do lower levels of optimization sometimes move the RAM variable around depending on code changes (other than adding variables).   

  • The compiler makes no attempt to locate variables in the same place on successive builds.  When little changes between builds, that tends to happen.  But it is not a requirement which is designed or tested for.  Thus, it is not possible to identify all the conditions which may cause variables to change memory locations.

    Here is one factor you probably didn't consider. Changing the order in which the linker sees the object files and libraries can cause a difference.

    Removing one variable, or adding one variable, causes all other variables at higher memory addresses to change location.

    I was not aware that using --opt_level=4 can cause variables to change location.  But I don't find that surprising.  All the object modules built with --opt_level=4 are combined into one compilation unit, and built again.  The order of the variables in that one unit could well be different than when they are compiled separately.  A similar effect will not be seen at lower levels of optimization.  

    I'm afraid my post is not very useful.  But that is the nature of this situation.

    Thanks and regards,

    -George

  • I am aware that adding variables and changing the order the linker sees the files will change the order of variables in the memory map. To avoid this issue, I normally declare all the variables in one file. And if I add variables for new versions of the code, I add them at the end of the that file. This has worked so far.

    Based on my experience with the compiler, I suspected that what you described is what happens with the opt_level = 4, because I can take the same code, and get a different memory map by changing to that level. So that's a confirmation of what I expected.

    But my question really is, assuming that I put all my variables in a single file, in the same order, and only add new variables at the end of that file, and avoid optimization level 4, will my old variables still be in the same place?

    And, to add other exceptions that I have already thought of, use the same versions of compiler and linker, and the same libraries, and the same linker command files.
  • Ian Bower said:
    assuming that I put all my variables in a single file, in the same order, and only add new variables at the end of that file, and avoid optimization level 4, will my old variables still be in the same place?

    Probably.  But there is no guarantee.  If you need a guarantee, then I recommend you implement that file in assembly.

    Thanks and regards,

    -George

  • I like the idea of having the option of implementing the file in assembly as a backstop in case we can't duplicate the memory map in any other way.  I think I'll experiment with that.