About GCC ARM 4.6 compiler code size optimization

Asked by Danilo Bessone

Premise: this is my first experience with GCC toolchains.
I downloaded the GCC ARM 4.6.2 EABI toolchain and used it to build a project (26 files, target MCU STM32F103CB) on a WinXP PC with the following results:
No optimization (-O0): program size 142216 bytes (greater than the 128K MCU internal flash)
Full code size optimization (-Os): program size 62980 bytes
These results show a poorer code optimization level if compared with a previous release (4.5.2 lite edition that I downloaded from CodeSourcery):
No optimization (-O0): program size 110524 bytes.
Full code size optimization (-Os): program size 60232 bytes.
I used the same compiler options for the two releases:
-mcpu=cortex-m3 -mthumb -Wall -D STM32F10X_MD -D STM32F103CB -ffunction-sections –O(0/s) -g –c
and the same linker options:
-O(0/s) -nostartfiles -Wl,-Map=test.map -mcpu=cortex-m3 -mthumb -Wl,--gc-sections,-Tlink.ld -g
(no library)
I used objdump to disassembly some sample functions and I found that in all the cases the code generated with the 4.5.2 compiler is more optimized in size than the 4.6 release.
Is the reduction of code size optimization observed with the 4.6 version to be considered tolerable or I did something wrong?

Thanks
Danilo

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Joey Ye
Solved:
Last query:
Last reply:
Revision history for this message
Best Joey Ye (jinyun-ye) said :
#1

Danilo,

Thanks for trying GCC toolchains and your feedback.

I have to say sorry that this release doesn't meet your expectation in term
of code size reduction in your case. We value code density and are
continuously analyzing and improving code size. However in the 4.6 release,
which is the first one of the series, the focus was more about enabling and
stability. You'd experience noticable code size reduce in the 4.7 major
release in 2012 Q4, and following-up releases.

BTW, would do please share why you measure code size with -O0? Usually when
optimizing we don't consider -O0 cases.

Thanks - Joey

On Fri, May 11, 2012 at 5:45 PM, Danilo Bessone <
<email address hidden>> wrote:

> New question #196873 on GCC ARM Embedded:
> https://answers.launchpad.net/gcc-arm-embedded/+question/196873
>
> Premise: this is my first experience with GCC toolchains.
> I downloaded the GCC ARM 4.6.2 EABI toolchain and used it to build a
> project (26 files, target MCU STM32F103CB) on a WinXP PC with the following
> results:
> No optimization (-O0): program size 142216 bytes (greater than the 128K
> MCU internal flash)
> Full code size optimization (-Os): program size 62980 bytes
> These results show a poorer code optimization level if compared with a
> previous release (4.5.2 lite edition that I downloaded from CodeSourcery):
> No optimization (-O0): program size 110524 bytes.
> Full code size optimization (-Os): program size 60232 bytes.
> I used the same compiler options for the two releases:
> -mcpu=cortex-m3 -mthumb -Wall -D STM32F10X_MD -D STM32F103CB
> -ffunction-sections –O(0/s) -g –c
> and the same linker options:
> -O(0/s) -nostartfiles -Wl,-Map=test.map -mcpu=cortex-m3 -mthumb
> -Wl,--gc-sections,-Tlink.ld -g
> (no library)
> I used objdump to disassembly some sample functions and I found that in
> all the cases the code generated with the 4.5.2 compiler is more optimized
> in size than the 4.6 release.
> Is the reduction of code size optimization observed with the 4.6 version
> to be considered tolerable or I did something wrong?
>
> Thanks
> Danilo
>
>
> --
> You received this question notification because you are an answer
> contact for GCC ARM Embedded.
>

Revision history for this message
Danilo Bessone (danilobessone) said :
#2

Thanks Joey Ye, that solved my question.

Revision history for this message
Danilo Bessone (danilobessone) said :
#3

I measured code size with the -0O option in order to query the capability of a ease debug of the program. If the total code size exceed the internal flash memory of the MCU (as in my case) I must pinpoint the area of code of concern an compile only the involved files with the -0O option or compile with the old release.
Obviously the code size with the -0s is the most significant thing but – this is a my personal opinion – also the O0/Os ratio is an important factor to take into account for the SW development of an embedded system.
I will wait for the 4.7 major release.

BR
Danilo