Compiling under different OS with the same compiler version

Asked by Martin Lang

Hello their,

I was wondering why I get a different .bin file size when I compiling the same project with the same
arm gcc compiler version (both with: 4.8q2) under different Operating Systems?
In my example win and linux.

under win, the resulting .bin file size is 274kb and under linux it is only 254kb. I'm using exactly the same
compiling and linking commands.

I used readelf to get a view more infos, and the .txt section differs quite a bit:

windows: 251kb
linux: 234kb

but I'm note sure about the reasons, so does the .text section size is so much different?

Is it just because of different shared librarys (os)?

thanks for any hints.

cya

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Martin Lang
Solved:
Last query:
Last reply:
Revision history for this message
Terry Guo (terry.guo) said :
#1

I simply tried with a plain hello world app and found the code size is same between Win and Linux. Here are my screen paste:

build@build-desktop:~/temp$ ./gcc-arm-none-eabi-4_8-2014q2/bin/arm-none-eabi-gcc -mthumb -specs=rdimon.specs h.c
build@build-desktop:~/temp$ ./gcc-arm-none-eabi-4_8-2014q2/bin/arm-none-eabi-size a.out
   text data bss dec hex filename
  10124 2404 260 12788 31f4 a.out
build@build-desktop:~/temp$ cat h.c
#include<stdio.h>
int main() { puts("Hello"); return 0;}

e:\Terry>.\gcc-arm-none-eabi-4_8-2014q2-20140609-win32\bin\arm-none-eabi-gcc.exe
 -mthumb -specs=rdimon.specs h.c

e:\Terry>.\gcc-arm-none-eabi-4_8-2014q2-20140609-win32\bin\arm-none-eabi-size.ex
e a.out
   text data bss dec hex filename
  10124 2404 260 12788 31f4 a.out

Would you please provide more details like options for us to reproduce this issue?

Revision history for this message
Martin Lang (mart-lang-in) said :
#2

Hey Terry,

Revision history for this message
Martin Lang (mart-lang-in) said :
#3

Hey Terry,

I wrote a simple program for testing like you did:

main.cpp:
===========================
int main(void)
{
        int a = 5;

        float f_var = 32.0f;

        float erg = 0;

        for(int i=0;i<=100;i++){
                erg = i*a/f_var;
        }
        if(erg==500) {
                return 4;
        }

        return 0;

}
===========================

I used the following compiling an linking option (which are the same like in my project):

compile:
arm-none-eabi-gcc -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wall -ffunction-sections -g -O1 -c -DSTM32F405RG -DSTM32F4XX -DUSE_STDPERIPH_DRIVER -D__ASSEMBLY__ -D__FPU_USED -D__FPU_PRESENT -DSYSTEM_LIB main.cpp

linking:
arm-none-eabi-gcc -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wall -O1 -Wl,--gc-sections -lstdc++ -Wl,-Tarm-gcc-link-new.ld -g -o main.elf main.o -lstdc++ -lsupc++ -lm -lgcc -lc -lnosys

result:

Windows:
---------------
C:\tmp\mit linker>arm-none-eabi-size main.o
   text data bss dec hex filename
     28 0 0 28 1c main.o

Linux:
---------------
server:~/tmp/new$ arm-none-eabi-size main.o
   text data bss dec hex filename
     20 0 0 20 14 main.o

same result like in my project, the linux one is smaller than the windows one.

Revision history for this message
Terry Guo (terry.guo) said :
#4

Thanks for providing more information. Unfortunately I still can't reproduce. The results from my Windows and Linux are same with the result from your Linux.

I suspect that your are calling wrong compiler on your Windows platform. This can happen when user installed more than one our tool chain. The path to the newest one will be appended to PATH rather than being pre-prended. Please try with absolute path to your compiler like "c:\abc\bin\arm-none-eabi-gcc.exe ...".

Revision history for this message
Martin Lang (mart-lang-in) said :
#5

Sorry Terry, you'r right. The PATH Variable on Windows wasn't correct set. my small test programm
has now the same size.
however, my project has a slightly different size:

Linux:
--------------
arm-none-eabi-size project.elf
   text data bss dec hex filename
 260340 2212 61744 324296 4f2c8 project.elf

Windows:
--------------
   text data bss dec hex filename
 260324 2212 61744 324280 4f2b8 project.elf

I compiled using the same command lines under linux and windows.

Revision history for this message
Terry Guo (terry.guo) said :
#6

Then please use "arm-none-eabi-nm -S project.elf" to find out which function caused difference. The second column represents the size.

Revision history for this message
Martin Lang (mart-lang-in) said :
#7

Hello Terry,

i spent the last days to figure out whats going on and why I became the different sizes.
Somehow I got confused with the different parameters and versions.
I figured out that my IDE (CooCox) parsed another libary path to the linker,
which caused the linker to use a different set of libstdc++ which caused
the size differents (under the linux machine the linker couldn't find
the other library and used the standard stc from arm gcc).

Sorry for the inconvenience I caused you.

regards Martin

Revision history for this message
Terry Guo (terry.guo) said :
#8

Hi Martin,

Glad to hear you figured things out. What you shared will help other people some day. So feel free to discuss any thing.

BR,
Terry