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

Arm Compiler V6.15 LTO Optimizations and -Oz

Hi,

We are trying to port our code from Arm compiler v5 to Arm compiler v6.15 or 6.16 and we are facing an issue when selecting -Oz optimizations and LTO. It seems that the compiler will truncate a variable from uint32_t bit to a 1 byte length variable.

The variable that gets truncated is assigned to a specific un-initialized section (created just for this variable) via a custom scatter file. The variable is selected to be a 32bit type since a magic number is assigned to it when the variable doesn't already hold this magic number. What we are trying to do is to check if there is a memory corruption during start up, so if the variable != magic number we enter an if condition else we skip the code in the if condition. The compiler will replace this 32bit variable with a 1 byte length variable in order to perform the check. Apparently this doesn't work for us since we would like to decrease the probability of this variable being accidentally initialized to a proper value.

The specific variable is only read once during start up and if it doesn't hold the specific number it will assigned with that number. Apparently the compiler doesn't see any other dependencies on that variable so it truncates it to 1 byte since it assumes that this will do the job 

We are able to bypass this optimization via adding a volatile attribute at that specific variable so that the compiler wont optimize it. But our main concern is if the compiler does the same thing in other places as well that we haven't noticed. So my questions are:

  • Is the volatile the correct attribute to add in such case (perhaps there is some other attribute that we can add instead of volatile) ?
  • Are you aware when the compiler will do similar optimizations (in order for us to be able to locate any additional issues) that may come up ?
  • Is there a kill switch for that specific optimization (truncate variable lengths) ?

Some additional information, the tool is Keil 5.33 the target is CortexM0+ 

Please let me know if this is clear enough.

Thanks Marios

Parents Reply Children
No data