AnsweredAssumed Answered

Cosmic or the worse compilator/linker ever programmed?

Question asked by lopez.pedro.001 on May 29, 2012
Latest reply on Jun 5, 2012 by Andrew Neil
Hi. I'm coding my 3rd testing project on stm8, to be exact in 2 different mcus, 103 and 105. I'm using cosmic compiler, and i didnt have any problem with the previous 2 projects (because i didnt verify the size).

The problem is that binary files generated by cosmic linker are oversized,... I expain it.

Until now ( I have more than 25 years programming and 13 years in MCU's world) when you included functions and you didnt use them, the linker was able to remove them from final binary since they are not being used..., I say until now because cosmic compiler is not doing that.

In my 3rd testing project i wanted to create the bigger array in flash (with const char noname[xxx];, where xxx is the size). What was my surprise when with a small code (about 10 lines my code, basically initializing ports and timers)  the bigger table size that I was able to create in a 8kb flash stm8s103 was just 3300... I though then that i did something wrong so i started to do different tests...., I called my provider and he started to do his own tests, after a while we talked again and our conclusion was that COSMIC compiler doesn't remove unused functions.

To verify it, just create a cosmic project with stvd, then include for example in the project stm8_gpio.c, generate a map file (linker tab then output in category combobox). You will see a .map file generated and a line, something like:

start 0000909d end 0000a444 length  5031 segment .text

After that I edit the stm8s_gpio.c file and remove with a #if defined(XXXX) the function GPIO_ExternalPullUpConfig that i'm not using in my code, and i get:

start 0000909d end 0000a42c length  5007 segment .text

So basically it is including the function, even when I dont use it in the code

If you continue reading the file in the first case you will see

_GPIO_ExternalPullUpConfig         >    6   (6)
  25 > _GPIO_ExternalPullUpConfig: (6)
_GPIO_ExternalPullUpConfig          00009f27   defined in Debug\stm8s_gpio.o section .text

Maybe the problem is that i'm using the 32kb limited version of the compiler but at least they can notice you this "hidden feature" when you get it.