Please note that the size of the binary file can be a little misleading in the sense that uninitialized variables, .bss sections, will not necessarily occupy the physical space in binary format, since they are usually simply marked as present, in fact, the space provided to them ... this usually happens by the bootloader when you start your program.
objdump ( http://www.gnu.org/software/binutils/ ) or maybe elfdump or the elf elfdump ( http://sourceforge.net/apps/trac/elftoolchain/ ) will help you determine the size of your various segments, data and text, as well as the size of individual functions and globals, etc. All these programs βlookβ into your compiled binary file and extract large information, such as the size of the .text, .data section, list the various characters, their locations and sizes, and you can even decompose the .text section ...
An example of using elfdump in the test.elf ELF image is elfdump -z test.elf > output.txt . This resets everything, including disassembling the text section. For example, from elfdump on my system, I saw
Section #6: .text, type=NOBITS, addr=0x500, off=0x5f168 size=149404(0x2479c), link=0, info=0, align=16, entsize=1 flags=<WRITE,ALLOC,EXECINSTR> Section #7: .text, type=NOBITS, addr=0x24c9c, off=0x5f168 size=362822(0x58946), link=0, info=0, align=4, entsize=1 flags=<WRITE,ALLOC,EXECINSTR,INCLUDE> .... Section #9: .rodata, type=NOBITS, addr=0x7d5e4, off=0x5f168 size=7670(0x1df6), link=0, info=0, align=4, entsize=1 flags=<WRITE,ALLOC>
So, I see how much my code (.text sections) and my data are read-only. Later in the file I see ...
Symbol table ".symtab" Value Size Bind Type Section Name ----- ---- ---- ---- ------- ---- 218 0x7c090 130 LOC FUNC .text IRemovedThisName
So, I see that my IRemovedThisName function takes 130 bytes. A quick script will allow you to list functions sorted by size and variables sorted by size. This may indicate locations for optimization ...
For a good example of objdump try http://www.thegeekstuff.com/2012/09/objdump-examples/ , specifically section 3, which shows how to get the contents of section headers using the -h option.
As for how the program will compare on two different platforms, I think you just need to compile on both platforms and compare the results obtained with your obj/elfdump on each system - the results will depend on the set of system commands, how well each the compiler can optimize general differences in hardware architecture, etc.
If you donβt have access to the embedded system, you can try using the cross-compiler, configured for your ultimate goal, on your laptop. This will give you binary code suitable for the embedded platform, and tools for analyzing the file (i.e. the cross-platform version of objdump ). This will give you some ball details for how the program will look on embedded systems.
Hope this helps.
EDIT: This will also help. How do I get the size of a C function from a C program or inline assembly?