On Fri, Jul 12, 2013 at 11:21 AM, Marc Glisse <marc.gli...@inria.fr> wrote: > On Fri, 12 Jul 2013, Ian Lance Taylor wrote: > >> On Fri, Jul 12, 2013 at 7:54 AM, Marc Glisse <marc.gli...@inria.fr> wrote: >>> >>> >>> this patch makes the driver pass -O2 to GNU ld if gcc was called with -O3 >>> (or more), -Ofast or -Os. >> >> >> I don't understand why that is a good idea. > > > Well, you thought it was 3 years ago ;-) > http://gcc.gnu.org/ml/gcc/2010-05/msg00193.html
Ah well, coming to it fresh I'm not sure it is. >> The linker -O option is only distantly related to the compiler -O option. >> It was probably a mistake to have a linker -O option at all. > > > Doesn't the linker produce something that is faster to link and/or smaller, > with this flag? For gold I think it has two effects. If you use compressed debug sections, it will compress them with zlib level 9 rather than 1. If you use -O2 or greater it will optimize string tables (e.g., the table holding the names of symbols) such that if the table stores two strings S1 and S2, and S2 is a suffix of S1, it will store only S1, and change pointers to S2 to point to the suffix of S1. So you are correct that the result will be smaller, but not faster to link. People routinely compile with -O or -O2. It's not clear to me that they should routinely link with -O or -O2. These decisions are not the default in the linker because they aren't good tradeoffs for most people. Ian