Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it ok to compile files with different gcc optimization levels for same application?

I have an application which generally used the gcc optimization flag -O0 (no optimization). Now I have a file opt.c which I would like to compile with -O1, and leave rest of the files with -O0.

To be more specific, opt.c has a large for loop, which performs some simple arithmetic.

Finally only 1 executable is created which has all the files plus the opt.c. I am not sure if this causes any issue!

like image 286
kp11 Avatar asked Mar 23 '16 17:03

kp11


People also ask

How many optimization levels are there in GCC?

Changing this value will make the code compilation take more time and will use much more memory, especially as the level of optimization is increased. There are seven -O settings: -O0 , -O1 , -O2 , -O3 , -Os , -Og , and -Ofast .

What is default GCC optimization level?

GCC has a range of optimization levels, plus individual options to enable or disable particular optimizations. The overall compiler optimization level is controlled by the command line option -On, where n is the required optimization level, as follows: -O0 . (default).

How many levels are there in general optimization options of compiler?

In order to control compilation-time and compiler memory usage, and the trade-offs between speed and space for the resulting executable, GCC provides a range of general optimization levels, numbered from 0--3, as well as individual options for specific types of optimization.

Is GCC an optimizing compiler?

GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. As compared to -O , this option increases both compilation time and the performance of the generated code.


1 Answers

Yes, that's absolutely fine. I'm curious why you don't wan't all of your code optimized? We typically optimize everything, except a few files where optimization causes problems.

like image 144
cleblanc Avatar answered Oct 11 '22 06:10

cleblanc