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

Rafael Espíndola rafael.espindola@gmail.com
Wed Nov 19 23:13:00 GMT 2014

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


More information about the Binutils mailing list