pragma GCC optimize("O0") issue

Asked by Nazım YILDIZ

Hello,

I use arm-cortexm4 microcontroller which is stm32f303.
The arm gcc compiler version is 5.4 2016q2.
Code development envirment is Eclipse/STM32 AC6.

I have tryed to use optimize level3(-O3) in whole project expect 1 file. Then used optimize pragma code to change optimizing level for aaaa.c file like below.

#pragma GCC push_options
#pragma GCC optimize("O0")

#includes ....
Source codes...
//End of the code
#pragma GCC pop_options

After compiling the related make file output is:

# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../Menu/LcdDriver/hd44780.c

OBJS += \
./Menu/LcdDriver/hd44780.o

C_DEPS += \
./Menu/LcdDriver/hd44780.d

# Each subdirectory must supply rules for building sources it contributes
Menu/LcdDriver/%.o: ../Menu/LcdDriver/%.c
 @echo 'Building file: $<'
 @echo 'Invoking: MCU GCC Compiler'
 @echo %cd%
 arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DSTM32F30 -DSTM32F3 -DSTM32F303VBTx -DSTM32 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F303xC -I"E:/workspace_ac6/CCS3010/inc" -I"E:/workspace_ac6/CCS3010/CMSIS/core" -I"E:/workspace_ac6/CCS3010/CMSIS/device" -I"E:/workspace_ac6/CCS3010/HAL_Driver/Inc/Legacy" -I"E:/workspace_ac6/CCS3010/HAL_Driver/Inc" -I"E:/workspace_ac6/CCS3010/ACAnalyzer" -I"E:/workspace_ac6/CCS3010/AuxInput" -I"E:/workspace_ac6/CCS3010/AuxOutput" -I"E:/workspace_ac6/CCS3010/Compressor" -I"E:/workspace_ac6/CCS3010/External_Storage" -I"E:/workspace_ac6/CCS3010/Fault" -I"E:/workspace_ac6/CCS3010/HardwareInit" -I"E:/workspace_ac6/CCS3010/Language" -I"E:/workspace_ac6/CCS3010/Parameters" -I"E:/workspace_ac6/CCS3010/FreeRTOSv9.0.0" -I"E:/workspace_ac6/CCS3010/FreeRTOSv9.0.0/FreeRTOS/Source/include" -I"E:/workspace_ac6/CCS3010/TestModules" -I"E:/workspace_ac6/CCS3010/SimpleAlgorithms" -I"E:/workspace_ac6/CCS3010/Compressor/CompressorFixed" -I"E:/workspace_ac6/CCS3010/Menu" -I"E:/workspace_ac6/CCS3010/ServiceTimes" -I"E:/workspace_ac6/CCS3010/Log" -I"E:/workspace_ac6/CCS3010/Menu/LcdDriver" -I"E:/workspace_ac6/CCS3010/Keypad" -I"E:/workspace_ac6/CCS3010/SystemAlarms" -O3 -g3 -fmessage-length=0 -ffunction-sections -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
 @echo 'Finished building: $<'
 @echo ' '

As you can see here optimizing leve still -O3.
How can I change it to -O0?

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Tejas Belagod
Solved:
Last query:
Last reply:
Revision history for this message
Best Tejas Belagod (belagod-tejas) said :
#1

THough you have -O3 on the cmdline, the source will have been optimised at -O0. You can verify this by doing an objdump on the object and looking at assembly for the scope of the pragma applied.

Revision history for this message
Nazım YILDIZ (nazimyildiz90) said :
#2

I have added -Wa,-adhln -g hd44780.c > hd44780.s this option into cmdline to get assembly output( gcc -Wa,-adhln -g hd44780.c > hd44780.s).

After compiling "No such file or directory" message is printed. (I can examine the assembly while in debuging but it isn't comfortable.)

Revision history for this message
Nazım YILDIZ (nazimyildiz90) said :
#3

Exact compiler message is "arm-none-eabi-gcc: error: hd44780.c: No such file or directory".

Revision history for this message
Nazım YILDIZ (nazimyildiz90) said :
#4

Thanks Tejas Belagod, that solved my question.

Revision history for this message
Nazım YILDIZ (nazimyildiz90) said :
#5

Additional information for others:
To get assembler output in case of using eclipse as IDE, developers should add

arm-none-eabi-objdump -D "${BuildArtifactFileBaseName}.elf" > "${BuildArtifactFileBaseName}.lst"

lines into C/C++ Build -> Settings -> Build Steps -> Post-build steps.

For example:
 arm-none-eabi-objdump -D "${BuildArtifactFileBaseName}.elf" > "${BuildArtifactFileBaseName}.lst && arm-none-eabi-objcopy -O ihex "${BuildArtifactFileBaseName}.elf" "${BuildArtifactFileBaseName}.hex"; arm-none-eabi-size "${BuildArtifactFileName}"