This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [patch][rfc] Enabling more optimizations with -ON
- From: Rafael EspÃndola <rafael dot espindola at gmail dot com>
- To: Rafael EspÃndola <rafael dot espindola at gmail dot com>, Binutils <binutils at sourceware dot org>, Cary Coutant <ccoutant at google dot com>
- Date: Wed, 19 Nov 2014 18:13:21 -0500
- Subject: Re: [patch][rfc] Enabling more optimizations with -ON
- Authentication-results: sourceware.org; auth=none
- References: <CAG3jRe+UXKKwUq==KLx9TQx2cSr2F-=fgz6cN41TndGoTwgaoQ at mail dot gmail dot com> <20141119230722 dot GA3225 at vapier dot wh0rd dot info>
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