top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

How to disable GCC optimization

+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??

posted Sep 11, 2013 by Anderson

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

+1 vote

Use "-O0" with gcc command to disable optimization. But Optimization can be also disabled selectively.
Here using "-O1" enable all optimizations. And some of those optimizations can be disabled using a -f switch.

To view the -f flags enabled by -O1 use this handy tip:gcc -fverbose-asm -H -x c <(echo '') -O1 -S -o O1.s

answer Sep 11, 2013 by Satyabrata Mahapatra
Please go through this following Link:
Similar Questions
+2 votes

I am getting following error when compiling my program with gcc version 4.9.0

gcc --version
gcc (GCC) 4.9.0 20131023 (experimental)


./A.out: /usr/lib/x86_64-linux-gnu/ version `CXXABI_1.3.8' not found (required by ./A.out)

But I gcc 4.7.3 is fine. Any guess why this may be happening.

+1 vote

If I compile c++ code, I am supposed to use g++. This automatically does some magic that calling just Gcc would not do. The same with Fortran code and gfortran. So my question is which frontend should I use to link if I have object files from both c++ as well as Fortran, c, and maybe another language still?

+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?

0 votes

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

+1 vote

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

Useful Links with Similar Problem
Contact Us
+91 9880187415
#470/147, 3rd Floor, 5th Main,
HSR Layout Sector 7,
Bangalore - 560102,
Karnataka INDIA.