This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Compiles & links differently only the 1st time...?!

I have a C16x project that exhibits a behaviour that I don't understand. Basically, if I un-archive a project into an empty subdirectory and do a "build all" I get a certain HEX file. However, all subsequent times I do a "build all" (without changing anything) I get a different HEX file. In other words, 2 HEX files from the same project. The process is very repeatable. Anyone have a clue as to why that might be? I'm not using anything that I know of that might cause a difference (such as using __TIME__ or __DATE__), and it's just different after the first build (it's always the same for the 2nd and subsequent builds).

Confused...
Dave.

Parents Reply Children
  • What I've noticed so far is that the 1st time I do the "build all" there are several more passes of the compiler than for the subsequent "build all's", and that there are differences in the resulting list files. To minimize the chance of possible optimization problems I set the optimization level to the lowest possible level (constant folding). I've also tried this out on different PC's that we use with the KEIL tools, and I get the same behaviour on all of them, even though they have different versions of the tools.

  • With C51, on the compiler options tab in the "Code Optimization" area, there is a check box for "Global Register Coloring" (also known as the "REGFILE" option) that is separate from the optimization "Level" drop-down" list. Enabling this causes more than one pass through the compile/link process. Could it be that C16x has a similar option that you could uncheck?

  • "What I've noticed so far is that the 1st time I do the 'Build All' there are several more passes of the compiler than for the subsequent 'Build All'"

    Yes, that's what C51 does with the aforementioned Global Register Optimisation

    "With C51, on the compiler options tab in the 'Code Optimization' area, there is a check box for 'Global Register Coloring'"

    Yes, that's the one I was thinking of!

    With C51, it causes a project.ORC file to be generated; its contents look something like this:

    .
    .
    .
    F37F  _STRCMP_XDATA_XDATA
    F30F  _STRCPY_XDATA_CODE
    F30F  _STRCPY_XDATA_XDATA
    F301  _STRLEN_XDATA
    F301  _TO_INT
    F3FF  _TRACE_HEX_PTR
    F39F  _TRANSMIT_CHARACTER
    .
    .
    .
    The names are names of the functions in your code, and the Hex numbers are a bitmap representation of each function's register usage.

    When you do your first 'Build All' straight from the archive, you don't have the project.ORC file, and it has to work from scratch; subsequent 'Build Alls' don't delete the project.ORC file, and this "seeds" the process - which is why you see the different result.
    If you deleted the project.ORC file before each 'Build All', you'd get the same result each time.

  • Thanks everyone! Unchecking the "Global Register Colorization" checkbox on the compiler tab of the project options has given us the ability to create the same HEX file after every build (of the same code). I'm a little puzzled as to why the tools would think that one build was okay but another was better. Isn't functional (i.e., fits in memory and runs) okay? Are the extra runs of parts of the tools to get even faster & smaller executable code? Makes me wonder if it might be useful for the user to have the ability to enter options similar to board layout tools where the tools would run until a user defined point of diminishing returns was met (such as a min percentage of reduction in either size or speed, etc.). Just a comment... the prospect of not being able to [easily] recreate a HEX file from the source code is unsettling to me. I'm quite relieved now that we can repeatedly, reliably recreate the same HEX file from the same project. Thanks again!

  • I'm quite relieved now that we can repeatedly, reliably recreate the same HEX file from the same project.

    Note, however, that different versions of Keil tools will most likely generate different code. So if you need to be able to rebuild the same HEX file after a while, you will have to use the same version of the Keil toolchain.

    Regards,
    Mike.

  • "Are the extra runs of parts of the tools to get even faster & smaller executable code?"

    Yes. It's an iterative process; and it can actually make quite a big difference.

    See my earlier explanation for how it comes to be different on the 1st build only.