AW: code optimization.

Christoph Kobe Christoph.Kobe@ek-team.de
Wed Aug 7 08:22:00 GMT 2013


(answer below)

-----Ursprüngliche Nachricht-----
Von: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] Im Auftrag von hemant undale
Gesendet: Mittwoch, 7. August 2013 08:04
An: gcc-help@gcc.gnu.org
Betreff: code optimization.

Hi to All,
My current compiler settings are
arm-none-eabi-gcc -Wall -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
-fshort-double-mcpu=cortex-m4 -mthumb -Qn -Os -finstrument-functions -mlong-calls -c temp.c -o temp.o so on for temp1, temp2... Etc I am compiling multiple C files.
and linker settings are
ld -r temp.o -o one.o
so on for temp1, temp2... Etc
I am linking multiple .O files.
Also I am using linker script i.e link.txt (invoked externally as below) ld -cref -Map map.txt -S -T link.txt -temp.o -lm -lc -lgcc arm-none-eabi-gcc -Wall sample.o -O Firmware.abs Now, At output I get .abs file of 140KB.
My Questions are
1.	How to optimize (reduce size of .abs) by using complier or linker
specific options??????
2.	There are Number of NOT used global variables and Blank Function
Calls in my C files (NO Dead Code!!!!). Is it possible to perform some link time optimization??????????
3.	Please Elaborate as I am new to this, I have referred sites, gcc
help and tried some "lto" options but NO reduction is size!!!!!!!!!!!!!
4.	I also tried using 
	-fdata-sections
	-ffunction-sections
But It has INCREASED my firmware.abs file size from KB to MB (yes it is
MB!!!!) I also wondered WHY??????????
I am using codesourcery arm toolchain evaluation.
It has gcc version 4.5.2 

Thanks for patiently reading my question.

----

Hi hemantu,

when using -fdata-sections and -ffunction-sections you also need to use --gc-sections during linking.

Also, people might find it easier to read your email carefully (and you will get more quality responses) if you invest some more time into formatting your text (paragrahs, less exclamation marks & question marks, no capitals). As a good starting point, a google search for "mailing list etiquette" points here:
http://www.freebsd.org/doc/en/articles/mailing-list-faq/etiquette.html

Regards
Christoph

----

Thanks for prompt reply Christoph,
I will take care for your valuable suggestions. 
I tried already using --gc-sections during linking but no improvements.
I really have same questions
1. How to optimize (reduce size of .abs) by using complier or linker specific options?
2. There is number of not used global variables and blank function calls in my C files (but no dead Code!).Is it possible to perform some link time optimization?
3. Please elaborate as I am new to this, I have referred sites, gcc help and tried some "lto" options but no reduction is size.
4.	I also tried using -fdata-sections -ffunction-sections but it has
increased my firmware.abs file size from KB to MB (yes it is MB!)I wondered WHY? 
I am using codesourcery arm toolchain evaluation.
It has gcc version 4.5.2

Cheers
Hemant

----

Hi Hemant,

I don't have simple answers to your other questions, but I'll try:

1. I was just facing the same problem and using -ffunction-sections & -fdatasections in combination with --gc-sections significantly reduced my executeable size from around 500 kiB to about 70 kiB. I think this is the best (initial) approach to reduce executable size.
2. I don't know.
3. Is this a question? I don't understand it.
4. Short: I don't know why. But I found using binutils helpful to examine the executables. Try "objdump -h executable.abs" to see the sections in the file, including their sizes. Do this with and without the -ffunction-sections -fdata-sections. 

My approach was to really understand what's going on during compiling, linking, etc. Searching on the net, reading documentation and playing with binutils helped me a lot.

Back to mail-formatting: On mailing lists it's usually better to post at the bottom (that's why I moved your answer down) because other people can read the correspondance as a whole without having to scroll around the email.

Regards
Christoph



More information about the Gcc-help mailing list