]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
lto/114655 - -flto=4 at link time doesn't override -flto=auto at compile time
authorRichard Biener <rguenther@suse.de>
Tue, 9 Apr 2024 12:25:57 +0000 (14:25 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 3 May 2024 12:47:32 +0000 (14:47 +0200)
The following adjusts -flto option processing in lto-wrapper to have
link-time -flto override any compile time setting.

PR lto/114655
* lto-wrapper.cc (merge_flto_options): Add force argument.
(merge_and_complain): Do not force here.
(run_gcc): But here to make the link-time -flto option override
any compile-time one.

(cherry picked from commit 32fb04adae90a0ea68e64e8fc3cb04b613b2e9f3)

gcc/lto-wrapper.cc

index 5186d040ce0b40e4137e5ff56201c65233fb96fa..ce4b3f29a86f42824d64e0096356d62c3bdf7b1f 100644 (file)
@@ -218,15 +218,18 @@ find_option (vec<cl_decoded_option> &options, cl_decoded_option *option)
   return find_option (options, option->opt_index);
 }
 
-/* Merge -flto FOPTION into vector of DECODED_OPTIONS.  */
+/* Merge -flto FOPTION into vector of DECODED_OPTIONS.  If FORCE is true
+   then FOPTION overrides previous settings.  */
 
 static void
 merge_flto_options (vec<cl_decoded_option> &decoded_options,
-                   cl_decoded_option *foption)
+                   cl_decoded_option *foption, bool force)
 {
   int existing_opt = find_option (decoded_options, foption);
   if (existing_opt == -1)
     decoded_options.safe_push (*foption);
+  else if (force)
+    decoded_options[existing_opt].arg = foption->arg;
   else
     {
       if (strcmp (foption->arg, decoded_options[existing_opt].arg) != 0)
@@ -493,7 +496,7 @@ merge_and_complain (vec<cl_decoded_option> &decoded_options,
          break;
 
        case OPT_flto_:
-         merge_flto_options (decoded_options, foption);
+         merge_flto_options (decoded_options, foption, false);
          break;
        }
     }
@@ -1549,8 +1552,8 @@ run_gcc (unsigned argc, char *argv[])
          break;
 
        case OPT_flto_:
-         /* Merge linker -flto= option with what we have in IL files.  */
-         merge_flto_options (fdecoded_options, option);
+         /* Override IL file settings with a linker -flto= option.  */
+         merge_flto_options (fdecoded_options, option, true);
          if (strcmp (option->arg, "jobserver") == 0)
            jobserver_requested = true;
          break;