Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good idea to change the optimization flags while building GCC from source?

Tags:

gcc

Considering that I'm building GCC from source + mpfr, gmp, mpc, libelf and binutils, is it a good idea to change the optimization flags like so

CFLAGS="-O3" CXXFLAGS="-O3" ./configure

while configuring GCC or any of the other software?

I have a c2duo.

EDIT: I'm worried about the fact that these flags could change the behaviour of those programs/libs.

like image 480
user2485710 Avatar asked Nov 25 '25 01:11

user2485710


1 Answers

There are two things which you can do:

  1. If you're natively bootstrapping, you can do a full, and complete profile guided bootstrap. This will build the compiler and dependencies with a bootstrapped compiler providing the third round with the profile information it can use to optimize itself. After configure, do make profiledbootstrap. Note you can place the dependencies and stuff likke binutils and gdb inside the gcc source tree, and they should be built as well in the process.

  2. If you don't want to go through a long profiled bootstrap process, set CFLAGS, CXXFLAGS, CFLAGS_FOR_TARGET, CXXFLAGS_FOR_TARGET, etc. at GCC configure time to:

    -O2 -flto -march=core2
    

    And set LDFLAGS and LDFLAGS_FOR_TARGET to

    -flto
    

This will optimize the most and safest stuff.

Note that all this trouble will probably only result in a tiny speedup in the final executable.

like image 132
rubenvb Avatar answered Nov 26 '25 14:11

rubenvb