Codesize arm gcc4.9 to arm gcc7 increased drastic

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User8720
Level 1
Level 1
First like given 5 replies posted Welcome!
Hi.

I've downloaded the latest toolchain from arm (gcc7) and compiled a project with the same settings as with older gcc4.9 (standard from DAVE distribution).

The code size increased about 10%.

I had a closer look to the listing and espacially to XMC_GPIO_Init().
With gcc4.9 it tooks 180Bytes, with gcc7 it tooks 524Bytes.

Does anyone know the root cause of this?

Greetings
0 Likes
4 Replies
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

I just tried using the GPIO example for XMC47 in the XMCLib.

GCC 49
text data bss dec hex filename
1896 0 2072 3968 f80 XMCLIB_GPIO.elf

GCC7
text data bss dec hex filename
1900 0 2072 3972 f84 XMCLIB_GPIO.elf


Regards,
Jesus
0 Likes
lock attach
Attachments are accessible only for community members.
User8720
Level 1
Level 1
First like given 5 replies posted Welcome!
Thanks for testing.

I extracted the section from the listing from my compilation.




Can you please post your listing and if possible your compiler / linker log?

In addition here are my compiler options for gcc7:
-DXMC1302_T038x0200 -DAKTIV=1 -DINAKTIV=0 -DTRUE=1 -DFALSE=0 -DNC=0xFF -DGND=0 -I"D:\Software Infineon\Demo" -I"D:\Software Infineon\Demo\DevDrivers\XMCLib\inc" -I"D:\Software Infineon\Demo\DevDrivers\CMSIS\Include" -I"D:\Software Infineon\Demo\DevDrivers\CMSIS\Infineon\XMC1300_series\Include" -I"D:\Software Infineon\Demo\RTOS\include" -I"D:\Software Infineon\Demo\RTOS\portable\GCC\ARM_CM0" -Os -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -Wall -std=gnu99 -Wa,-adhlns="$@.lst" -pipe -c -fmessage-length=0 -mcpu=cortex-m0 -mthumb -g3 -gdwarf-2

They are the same as for gcc4.9.
0 Likes
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

I have tested using your settings. The difference in size you see is due to the usage of fpack-struct.
In my case
GCC49(-Os)   
text data bss dec hex filename
1016 0 1048 2064 810 XMCLIB_GPIO_XMC13.elf

GCC49(-Os -fpack-struct -fshort-enums)
text data bss dec hex filename
1068 0 1048 2116 844 XMCLIB_GPIO_XMC13.elf

GCC7(-Os)
text data bss dec hex filename
1000 0 1040 2040 7f8 XMCLIB_GPIO_XMC13.elf

GCC7(-Os -fpack-struct -fshort-enums)
text data bss dec hex filename
1384 0 1040 2424 978 XMCLIB_GPIO_XMC13.elf



Bear in mind the warning in the description of the -fpack-struct switch in the manual of GCC
-fpack-struct[=n]
Without a value specified, pack all structure members together without holes.
When a value is specified (which must be a small power of two), pack structure
members according to this value, representing the maximum alignment (that
is, objects with default alignment requirements larger than this are output
potentially unaligned at the next fitting location.
Warning: the ‘-fpack-struct’ switch causes GCC to generate code that is
not binary compatible with code generated without that switch. Additionally,
it makes the code suboptimal
. Use it to conform to a non-default application
binary interface.


You can find also other reports about using -fpack-struct, http://digitalvampire.org/blog/index.php/2006/07/31/why-you-shouldnt-use-__attribute__packed/

Regards,
Jesus
0 Likes
User8720
Level 1
Level 1
First like given 5 replies posted Welcome!
Thank a lot.
This solved my problem.
0 Likes