Code Execution bug encountered after setting optimization for size -O0d

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Code Execution bug encountered after setting optimization for size -O0d

Jump to solution
1,016 Views
joseplluismoral
Contributor II

Hi everyone!

 

Im using the following setup:

KDS 3.0.0

toolchain: GNU Tools for ARM Embedded Processors (arm-none-eabi-gcc)

toolchain architecture: ARM (AArch32)

 

Im working in a custom from scratch bootloader for target KW01Z128 cortex m0+, after setting up the optimization for size in the project options (Project propierties -> C/C++ Build -> Settings -> Tool Settings -> Optimization) selecting the size optimization -O0s) I found a problem in the debugging.

 

In the debugging process I detect that a C line is not executed, if I remove the optimization and change it for "none O0"

The line is "magically" executed.

 

Here is the problematic optimized code:

153850_153850.pngpastedImage_1.png

I don't know that this is a error produced by the toolchain or KDS.

 

1-. How can I solve that problem keeping the optimization of size activated?

2-. Do you know if there exists

 

PS:

After looking for KDS optimization problem posts and reading it:

Problem with code geting optimized out | NXP Community

 

I have tried the asm("nop"); option but it not solves the problem and the code line optimized is not being executed anyway.

Original Attachment has been moved to: kw01_bootloader_test_bindatafromuart_source.rar

Labels (1)
1 Solution
910 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

I wonder these two variable lastFwLenght and lastFwInitPage have been optimized.

please cast them to "volatile" to avoid optimization.

pastedImage_2.png

then I check disassembly code with -Os option. I can see the related code you mention not being optimized:

pastedImage_3.png


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

4 Replies
911 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

I wonder these two variable lastFwLenght and lastFwInitPage have been optimized.

please cast them to "volatile" to avoid optimization.

pastedImage_2.png

then I check disassembly code with -Os option. I can see the related code you mention not being optimized:

pastedImage_3.png


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

910 Views
joseplluismoral
Contributor II

ZhangJennie

Many many many many many (infinite...) many thanks, your help has been very valuable to me

It worked like a charm!

0 Kudos
Reply
910 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Good to know your problem got solved. My pleasure!

Have a great day,

Jennie Zhang

0 Kudos
Reply
910 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

BTW, My test with your code is under KDS 3.2. for the moment, I don't have KDS3.0 installed.

0 Kudos
Reply