[patch][rfc] Enabling more optimizations with -ON

Cary Coutant ccoutant@google.com
Thu Nov 20 00:25:00 GMT 2014

Sorry, Rafael, I'm not ignoring your proposal -- I'm just pondering
it. I'm not wild about the -O option in the first place, since it
implies that we can nicely arrange the various optimizations into some
order. Right now, we use it in exactly two places: -O1 with
--compress-debug-sections uses ZIP compression level 9 instead of 1,
and -O2 does tail optimization of the string tables. Both of those
probably would have been cleaner with distinct options, but it was
convenient and both simply trade a little link time for a smaller
executable without any risk. It's not clear to me that --gc-sections
or --icf are universally applicable, which is what bundling them with
some optimization level would imply.


On Wed, Nov 19, 2014 at 3:13 PM, Rafael Espíndola
<rafael.espindola@gmail.com> wrote:
> On 19 November 2014 18:07, Mike Frysinger <vapier@gentoo.org> wrote:
>> On 03 Nov 2014 11:39, Rafael Espíndola wrote:
>>> In compilers the -ON options enable various optimizations. Different
>>> compilers (and compiler versions) have different ones, but the option
>>> itself is commonly available and selects a somewhat corresponding
>>> level.
>>> In both bfd ld and gold very few optimizations are enabled with the
>>> -ON options. This means that users have to know which optimizations
>>> are available:
>>> ld ...-O3 --gc-sections --icf=safe....
>>> If an optimization is added to one of them, a configure check has to
>>> be used to find if the program is being linked with gold or bfd (and
>>> which version).
>>> As a starting point, the attached patch changes gold to gc sections by
>>> default if given -O3 or higher. It can still be disabled with an
>>> explicit --no-gc-sections.
>> i don't think this is really useful.  gc-sections requires code to be compiled
>> with -f{data,function}-sections in order to be effective.  so at that point, the
>> user is opting in to the desired behavior ...
> This particular example is bit of a chicken and egg issue with the
> compiler. There was some discussion at least on the clang side to
> enable ffunction-sections and fdata-sections by default.
> The more general question is "should the liker do more optimizations
> at -Ox"? It is very convenient since then the user doesn't need to
> know the set of optimizations available for a given linker.
> For example, right now a project needs a configure/cmake check to find
> out if it is being linked with gold before using -icf=safe, but if it
> was enabled with some -O level, it could just pass that -O option to
> both gold and bfd.
>> -mike
> Cheers,
> Rafael

More information about the Binutils mailing list