top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

code optimization with gcc

+1 vote
400 views

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 compiler 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

posted Aug 7, 2013 by Luv Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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

answer Aug 7, 2013 by Kumar Mitrasen
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
Similar Questions
0 votes

I am looking for detailed description of optimization flags that are provided by GCC compiler ?

+5 votes

I have a C code like this:

int foo(void)
{ 
 int phase;
 . . .
 phase = 1;
 phase = 2;
 phase = 3;
 . . .
}

In case of -O0 gcc generates machine instructions for every assignment 'phase = ...'. But in case of -O2 gcc does not generate instructions for some assignments. Of course, this is correct. However, is there any way to tell gcc that 'phase' object is inspected by another thread, so it should not remove such statements?

+2 votes

I want to use some loop optimizations. I have build GCC-4.8.1 using gmp 5.1.3, mpfr 3.1.2, mpc 1.0.1, cloog 0.18.0 and isl 0.11.1. I tried optimization flags -floop-interchange and -floop-block. I don't find any changes in the optimized code.

Are graphite loop transforms implemented in GCC-4.8.1. Should I configure and build GCC in a different way.

+5 votes

GCC is stripping the object file when nothing from the file is being used anywhere in the executable (even -o0 does nor help). We have to disable this feature of linker g++. could any one please help us to resolve this issue??

0 votes

When I was building GCC, I found out that stage1-gcc is not compiled with optimization (such as -O2). So the compilation of stage2 is very slow. Is this intended or not? If not, did I made some mistakes in configure options and caused this?

...