2022-10-25 02:08 AM
Hi there,
I have encouraged a strange behavior inside newlib_lock_glue.c.
On few devices the code does note execute correctly when the optimization is turned on.
To me it looks like the optimization throw away the return and just continue evaluating. the function was called (eventually) from sprintf.
I am running FreeRTOS and thread-safe strategy #4 (allow lock usage from interrupts).
The return is missing from the disassembly and I do not see any instruction that will implement it inside of the if code.
Here is the code with disassembly and callstack
lock is not null
Is the generated assembly correct?
Can you point me to the solution please? I am out of ideas.
This is not my code, newlib_lock_glue.c is generated by CubeIDE
here are mine gcc flags
-mcpu=cortex-m7
-std=gnu11
-g3
-DUSE_HAL_DRIVER
-DSTM32H7A3xx
-DSTM32_THREAD_SAFE_STRATEGY=4
-c
-Os
-ffunction-sections
-fdata-sections
-Wall
-Wextra
-Wshadow
-Wundef
-fstack-usage
--specs=nano.specs
-mfpu=fpv5-d16
-mfloat-abi=hard
-mthumb
Thank you
2022-10-25 02:58 AM
The POP instruction at the address 0x080931E6 restores the PC register to the LR register value, which was stored with a PUSH instruction on entry. Therefore the POP instruction acts as a return.
2022-10-27 03:18 AM
Hello @František Horínek
First let me thank you for posting.
When activating the optimization option, the compiler will attempt to improve the performance and/or code size at the expense of compilation time and possibly the ability to debug the program.
Therefore, when debugging the execution will not be in line with the written code.
For debugging it is recommended to use a (-O0) or (-Og) optimization level.
I recommended that you check this link: Optimize Options (Using the GNU Compiler Collection (GCC))
I hope my reply answered your question.
Feel free to reply in case if you need further info.
Kind regards,
Semer.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2022-10-27 12:16 PM
> I hope my reply answered your question.
The question basically was: "Where is the return instruction?" Your post doesn't answer the question in any way, but you are still pretending it does. What's the point of such useless posts?
> First let me thank you for posting.
Thanking is expressing a gratitude for someone doing some favor to someone. Thanking for reporting a bug is OK, but not for just asking a question. Asking a question is asking for a favor, not doing a favor - the exact opposite.
> Feel free to reply in case if you need further info.
Another nonsense from some management SJWs. People don't need your permission to reply!