Patchwork [1/2] Fix -fno-lto (PR lto/46905)

login
register
mail settings
Submitter Andi Kleen
Date Dec. 16, 2010, 12:41 p.m.
Message ID <1292503308-11258-1-git-send-email-andi@firstfloor.org>
Download mbox | patch
Permalink /patch/75751/
State New
Headers show

Comments

Andi Kleen - Dec. 16, 2010, 12:41 p.m.
From: Andi Kleen <ak@linux.intel.com>

This fixes PR lto/46905.

It's sometimes convenient in large Makefiles to globally enable LTO
in CFLAGS, but disable it again for specific files. The simplest
way to do that is appending -fno-lto, but that didn't work.
Add explicit code to handle this case.

Passes bootstrap and full test on x86_64-linux. Ok?

gcc/

2010-12-15  Andi Kleen	<ak@linux.intel.com>

	PR lto/46905
	* collect2.c (main): Handle -fno-lto.
	* common.opt (fno-lto): Add.
	* opts.c (common_handle_option): Handle OPT_fno_lto.
---
 gcc/collect2.c |    2 ++
 gcc/common.opt |    4 ++++
 gcc/opts.c     |    4 ++++
 3 files changed, 10 insertions(+), 0 deletions(-)
Richard Guenther - Dec. 16, 2010, 1:17 p.m.
On Thu, Dec 16, 2010 at 1:41 PM, Andi Kleen <andi@firstfloor.org> wrote:
> From: Andi Kleen <ak@linux.intel.com>
>
> This fixes PR lto/46905.
>
> It's sometimes convenient in large Makefiles to globally enable LTO
> in CFLAGS, but disable it again for specific files. The simplest
> way to do that is appending -fno-lto, but that didn't work.
> Add explicit code to handle this case.
>
> Passes bootstrap and full test on x86_64-linux. Ok?

Do you really need the common.opt and opts.c hunks?

> gcc/
>
> 2010-12-15  Andi Kleen  <ak@linux.intel.com>
>
>        PR lto/46905
>        * collect2.c (main): Handle -fno-lto.
>        * common.opt (fno-lto): Add.
>        * opts.c (common_handle_option): Handle OPT_fno_lto.
> ---
>  gcc/collect2.c |    2 ++
>  gcc/common.opt |    4 ++++
>  gcc/opts.c     |    4 ++++
>  3 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/gcc/collect2.c b/gcc/collect2.c
> index 89b21d5..77f794f 100644
> --- a/gcc/collect2.c
> +++ b/gcc/collect2.c
> @@ -1211,6 +1211,8 @@ main (int argc, char **argv)
>         else if ((! strncmp (argv[i], "-flto=", 6)
>                  || ! strcmp (argv[i], "-flto")) && ! use_plugin)
>          lto_mode = LTO_MODE_WHOPR;
> +       else if (!strncmp (argv[i], "-fno-lto", 8))
> +         lto_mode = LTO_MODE_NONE;
>         else if (! strcmp (argv[i], "-plugin"))
>          {
>            use_plugin = true;
> diff --git a/gcc/common.opt b/gcc/common.opt
> index 32df6fc..e6cb5e4 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -1302,6 +1302,10 @@ floop-optimize
>  Common Ignore
>  Does nothing.  Preserved for backward compatibility.
>
> +fno-lto
> +Common RejectNegative
> +Disable link-time optimization
> +
>  flto
>  Common
>  Enable link-time optimization.
> diff --git a/gcc/opts.c b/gcc/opts.c
> index 2c8e767..fc6f272 100644
> --- a/gcc/opts.c
> +++ b/gcc/opts.c
> @@ -1673,6 +1673,10 @@ common_handle_option (struct gcc_options *opts,
>       opts->x_flag_lto = "";
>       break;
>
> +    case OPT_fno_lto:
> +      opts->x_flag_lto = NULL;
> +      break;
> +
>     case OPT_w:
>       dc->dc_inhibit_warnings = true;
>       break;
> --
> 1.7.1
>
>
Andi Kleen - Dec. 16, 2010, 1:20 p.m.
Richard Guenther <richard.guenther@gmail.com> writes:

> On Thu, Dec 16, 2010 at 1:41 PM, Andi Kleen <andi@firstfloor.org> wrote:
>> From: Andi Kleen <ak@linux.intel.com>
>>
>> This fixes PR lto/46905.
>>
>> It's sometimes convenient in large Makefiles to globally enable LTO
>> in CFLAGS, but disable it again for specific files. The simplest
>> way to do that is appending -fno-lto, but that didn't work.
>> Add explicit code to handle this case.
>>
>> Passes bootstrap and full test on x86_64-linux. Ok?
>
> Do you really need the common.opt and opts.c hunks?

Yes. The previous state without them didn't work.

I also tried to do it without opts.c, but setting an 0 initialization
value for the -fno-lto entry, but that didn't work either.

-Andi
Richard Guenther - Dec. 16, 2010, 1:26 p.m.
On Thu, Dec 16, 2010 at 2:20 PM, Andi Kleen <andi@firstfloor.org> wrote:
> Richard Guenther <richard.guenther@gmail.com> writes:
>
>> On Thu, Dec 16, 2010 at 1:41 PM, Andi Kleen <andi@firstfloor.org> wrote:
>>> From: Andi Kleen <ak@linux.intel.com>
>>>
>>> This fixes PR lto/46905.
>>>
>>> It's sometimes convenient in large Makefiles to globally enable LTO
>>> in CFLAGS, but disable it again for specific files. The simplest
>>> way to do that is appending -fno-lto, but that didn't work.
>>> Add explicit code to handle this case.
>>>
>>> Passes bootstrap and full test on x86_64-linux. Ok?
>>
>> Do you really need the common.opt and opts.c hunks?
>
> Yes. The previous state without them didn't work.
>
> I also tried to do it without opts.c, but setting an 0 initialization
> value for the -fno-lto entry, but that didn't work either.

Huh, that's strange.  Joseph, do you have any idea why?  Is it because
of how flags get passed to collect2?

Richard.

> -Andi
>
> --
> ak@linux.intel.com -- Speaking for myself only.
>
Jan Hubicka - Dec. 16, 2010, 2:29 p.m.
> On Thu, Dec 16, 2010 at 2:20 PM, Andi Kleen <andi@firstfloor.org> wrote:
> > Richard Guenther <richard.guenther@gmail.com> writes:
> >
> >> On Thu, Dec 16, 2010 at 1:41 PM, Andi Kleen <andi@firstfloor.org> wrote:
> >>> From: Andi Kleen <ak@linux.intel.com>
> >>>
> >>> This fixes PR lto/46905.
> >>>
> >>> It's sometimes convenient in large Makefiles to globally enable LTO
> >>> in CFLAGS, but disable it again for specific files. The simplest
> >>> way to do that is appending -fno-lto, but that didn't work.
> >>> Add explicit code to handle this case.
> >>>
> >>> Passes bootstrap and full test on x86_64-linux. Ok?
> >>
> >> Do you really need the common.opt and opts.c hunks?
> >
> > Yes. The previous state without them didn't work.
> >
> > I also tried to do it without opts.c, but setting an 0 initialization
> > value for the -fno-lto entry, but that didn't work either.
> 
> Huh, that's strange.  Joseph, do you have any idea why?  Is it because
> of how flags get passed to collect2?
I think it is because -flto is not switch but accept string argument?

Honza
> 
> Richard.
> 
> > -Andi
> >
> > --
> > ak@linux.intel.com -- Speaking for myself only.
> >
Joseph S. Myers - Dec. 16, 2010, 3:39 p.m.
On Thu, 16 Dec 2010, Richard Guenther wrote:

> > I also tried to do it without opts.c, but setting an 0 initialization
> > value for the -fno-lto entry, but that didn't work either.
> 
> Huh, that's strange.  Joseph, do you have any idea why?  Is it because
> of how flags get passed to collect2?

Having both flto and fno-lto in common.opt seems dodgy.  Try making the 
code in opts.c that handles OPT_flto check "value" (value == 0 meaning 
-fno-lto) instead.

Patch

diff --git a/gcc/collect2.c b/gcc/collect2.c
index 89b21d5..77f794f 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -1211,6 +1211,8 @@  main (int argc, char **argv)
         else if ((! strncmp (argv[i], "-flto=", 6)
 		  || ! strcmp (argv[i], "-flto")) && ! use_plugin)
 	  lto_mode = LTO_MODE_WHOPR;
+	else if (!strncmp (argv[i], "-fno-lto", 8))
+	  lto_mode = LTO_MODE_NONE;
         else if (! strcmp (argv[i], "-plugin"))
 	  {
 	    use_plugin = true;
diff --git a/gcc/common.opt b/gcc/common.opt
index 32df6fc..e6cb5e4 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1302,6 +1302,10 @@  floop-optimize
 Common Ignore
 Does nothing.  Preserved for backward compatibility.
 
+fno-lto
+Common RejectNegative
+Disable link-time optimization
+
 flto
 Common
 Enable link-time optimization.
diff --git a/gcc/opts.c b/gcc/opts.c
index 2c8e767..fc6f272 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -1673,6 +1673,10 @@  common_handle_option (struct gcc_options *opts,
       opts->x_flag_lto = "";
       break;
 
+    case OPT_fno_lto:
+      opts->x_flag_lto = NULL;
+      break;
+
     case OPT_w:
       dc->dc_inhibit_warnings = true;
       break;