Code Execution bug encountered after setting optimization for size -O0d

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Code Execution bug encountered after setting optimization for size -O0d

跳至解决方案
1,636 次查看
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

标签 (1)
1 解答
1,530 次查看
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!
-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

4 回复数
1,531 次查看
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!
-----------------------------------------------------------------------------------------------------------------------

1,530 次查看
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 项奖励
回复
1,530 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

Good to know your problem got solved. My pleasure!

Have a great day,

Jennie Zhang

0 项奖励
回复
1,530 次查看
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 项奖励
回复