public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] lto: fix error handling for -Wl,-plugin-opt=debug
@ 2022-02-02 14:30 Martin Liška
  2022-02-02 14:38 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Liška @ 2022-02-02 14:30 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

When one uses something like: -Wl,-plugin-opt=debug,
we end up with lto1 WPA invocation that has 'debug'
on command line. We interpret that as input filename.

The patch moves resolution checking later so that we end up with
a reasonable error message:

lto1: error: open debug failed: No such file or directory
lto1: fatal error: errors during merging of translation units

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

	PR lto/104333

gcc/lto/ChangeLog:

	* lto-common.cc (read_cgraph_and_symbols): Move resolution
	checking for number of files later and report a reasonable
	error message.
---
  gcc/lto/lto-common.cc | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc
index 4d6686b0b99..fbcd4742ee4 100644
--- a/gcc/lto/lto-common.cc
+++ b/gcc/lto/lto-common.cc
@@ -2704,6 +2704,7 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
  {
    unsigned int i, last_file_ix;
    FILE *resolution;
+  unsigned resolution_objects = 0;
    int count = 0;
    struct lto_file_decl_data **decl_data;
    symtab_node *snode;
@@ -2726,18 +2727,14 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
    if (resolution_file_name)
      {
        int t;
-      unsigned num_objects;
  
        resolution = fopen (resolution_file_name, "r");
        if (resolution == NULL)
  	fatal_error (input_location,
  		     "could not open symbol resolution file: %m");
  
-      t = fscanf (resolution, "%u", &num_objects);
+      t = fscanf (resolution, "%u", &resolution_objects);
        gcc_assert (t == 1);
-
-      /* True, since the plugin splits the archives.  */
-      gcc_assert (num_objects == nfiles);
      }
    symtab->state = LTO_STREAMING;
  
@@ -2806,7 +2803,12 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
    lto_register_canonical_types_for_odr_types ();
  
    if (resolution_file_name)
-    fclose (resolution);
+    {
+      /* True, since the plugin splits the archives.  */
+      if (!seen_error ())
+	gcc_assert (resolution_objects == nfiles);
+      fclose (resolution);
+    }
  
    /* Show the LTO report before launching LTRANS.  */
    if (flag_lto_report || (flag_wpa && flag_lto_report_wpa))
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lto: fix error handling for -Wl,-plugin-opt=debug
  2022-02-02 14:30 [PATCH] lto: fix error handling for -Wl,-plugin-opt=debug Martin Liška
@ 2022-02-02 14:38 ` Richard Biener
  2022-02-02 14:48   ` Martin Liška
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2022-02-02 14:38 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches, Jakub Jelinek

On Wed, Feb 2, 2022 at 3:31 PM Martin Liška <mliska@suse.cz> wrote:
>
> When one uses something like: -Wl,-plugin-opt=debug,
> we end up with lto1 WPA invocation that has 'debug'
> on command line. We interpret that as input filename.
>
> The patch moves resolution checking later so that we end up with
> a reasonable error message:
>
> lto1: error: open debug failed: No such file or directory

I think almost all of these errors should be fatal_error, not error ()
since we cannot really recover.  That would make ..

> lto1: fatal error: errors during merging of translation units
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin
>
>         PR lto/104333
>
> gcc/lto/ChangeLog:
>
>         * lto-common.cc (read_cgraph_and_symbols): Move resolution
>         checking for number of files later and report a reasonable
>         error message.
> ---
>   gcc/lto/lto-common.cc | 14 ++++++++------
>   1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc
> index 4d6686b0b99..fbcd4742ee4 100644
> --- a/gcc/lto/lto-common.cc
> +++ b/gcc/lto/lto-common.cc
> @@ -2704,6 +2704,7 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
>   {
>     unsigned int i, last_file_ix;
>     FILE *resolution;
> +  unsigned resolution_objects = 0;
>     int count = 0;
>     struct lto_file_decl_data **decl_data;
>     symtab_node *snode;
> @@ -2726,18 +2727,14 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
>     if (resolution_file_name)
>       {
>         int t;
> -      unsigned num_objects;
>
>         resolution = fopen (resolution_file_name, "r");
>         if (resolution == NULL)
>         fatal_error (input_location,
>                      "could not open symbol resolution file: %m");
>
> -      t = fscanf (resolution, "%u", &num_objects);
> +      t = fscanf (resolution, "%u", &resolution_objects);
>         gcc_assert (t == 1);
> -
> -      /* True, since the plugin splits the archives.  */
> -      gcc_assert (num_objects == nfiles);
>       }
>     symtab->state = LTO_STREAMING;
>
> @@ -2806,7 +2803,12 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
>     lto_register_canonical_types_for_odr_types ();
>
>     if (resolution_file_name)
> -    fclose (resolution);
> +    {
> +      /* True, since the plugin splits the archives.  */
> +      if (!seen_error ())

... checking for seen_error () unnecessary.

> +       gcc_assert (resolution_objects == nfiles);
> +      fclose (resolution);
> +    }
>
>     /* Show the LTO report before launching LTRANS.  */
>     if (flag_lto_report || (flag_wpa && flag_lto_report_wpa))
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lto: fix error handling for -Wl,-plugin-opt=debug
  2022-02-02 14:38 ` Richard Biener
@ 2022-02-02 14:48   ` Martin Liška
  2022-02-02 14:50     ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Liška @ 2022-02-02 14:48 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches, Jakub Jelinek

[-- Attachment #1: Type: text/plain, Size: 154 bytes --]

On 2/2/22 15:38, Richard Biener wrote:
> ... checking for seen_error () unnecessary.

Sure, so something like this?

Ready to be installed?
Thanks,
Martin

[-- Attachment #2: 0001-lto-fix-error-handling-for-Wl-plugin-opt-debug.patch --]
[-- Type: text/x-patch, Size: 3275 bytes --]

From fd7385e495acfced416b37320b4bb7475bf2f9ff Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Wed, 2 Feb 2022 14:21:51 +0100
Subject: [PATCH] lto: fix error handling for -Wl,-plugin-opt=debug

When one uses something like: -Wl,-plugin-opt=debug,
we end up with lto1 WPA invocation that has 'debug'
on command line. We interpret that as input filename.

The patch moves resolution checking later so that we end up with
a reasonable error message:

lto1: fatal error: open debug failed: No such file or directory
compilation terminated.

	PR lto/104333

gcc/lto/ChangeLog:

	* lto-common.cc (read_cgraph_and_symbols): Move resolution
	checking for number of files later and report a reasonable
	error message.
	* lto-object.cc (lto_obj_file_open): Make error fatal.
---
 gcc/lto/lto-common.cc | 13 +++++++------
 gcc/lto/lto-object.cc |  8 ++------
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc
index 4d6686b0b99..11fde671162 100644
--- a/gcc/lto/lto-common.cc
+++ b/gcc/lto/lto-common.cc
@@ -2704,6 +2704,7 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
 {
   unsigned int i, last_file_ix;
   FILE *resolution;
+  unsigned resolution_objects = 0;
   int count = 0;
   struct lto_file_decl_data **decl_data;
   symtab_node *snode;
@@ -2726,18 +2727,14 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
   if (resolution_file_name)
     {
       int t;
-      unsigned num_objects;
 
       resolution = fopen (resolution_file_name, "r");
       if (resolution == NULL)
 	fatal_error (input_location,
 		     "could not open symbol resolution file: %m");
 
-      t = fscanf (resolution, "%u", &num_objects);
+      t = fscanf (resolution, "%u", &resolution_objects);
       gcc_assert (t == 1);
-
-      /* True, since the plugin splits the archives.  */
-      gcc_assert (num_objects == nfiles);
     }
   symtab->state = LTO_STREAMING;
 
@@ -2806,7 +2803,11 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
   lto_register_canonical_types_for_odr_types ();
 
   if (resolution_file_name)
-    fclose (resolution);
+    {
+      /* True, since the plugin splits the archives.  */
+      gcc_assert (resolution_objects == nfiles);
+      fclose (resolution);
+    }
 
   /* Show the LTO report before launching LTRANS.  */
   if (flag_lto_report || (flag_wpa && flag_lto_report_wpa))
diff --git a/gcc/lto/lto-object.cc b/gcc/lto/lto-object.cc
index 6f7f96f14d9..329bbc71fd6 100644
--- a/gcc/lto/lto-object.cc
+++ b/gcc/lto/lto-object.cc
@@ -103,10 +103,7 @@ lto_obj_file_open (const char *filename, bool writable)
 		  : O_RDONLY | O_BINARY),
 		 0666);
   if (lo->fd == -1)
-    {
-      error ("open %s failed: %s", fname, xstrerror (errno));
-      goto fail;
-    }
+    fatal_error (input_location, "open %s failed: %s", fname, xstrerror (errno));
 
   if (!writable)
     {
@@ -146,13 +143,12 @@ lto_obj_file_open (const char *filename, bool writable)
 
   return &lo->base;
 
- fail_errmsg:
+fail_errmsg:
   if (err == 0)
     error ("%s: %s", fname, errmsg);
   else
     error ("%s: %s: %s", fname, errmsg, xstrerror (err));
 					 
- fail:
   if (lo->fd != -1)
     lto_obj_file_close ((lto_file *) lo);
   free (lo);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lto: fix error handling for -Wl,-plugin-opt=debug
  2022-02-02 14:48   ` Martin Liška
@ 2022-02-02 14:50     ` Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2022-02-02 14:50 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches, Jakub Jelinek

On Wed, Feb 2, 2022 at 3:48 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 2/2/22 15:38, Richard Biener wrote:
> > ... checking for seen_error () unnecessary.
>
> Sure, so something like this?

yes, I think so.

> Ready to be installed?

OK.

> Thanks,
> Martin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-02 14:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-02 14:30 [PATCH] lto: fix error handling for -Wl,-plugin-opt=debug Martin Liška
2022-02-02 14:38 ` Richard Biener
2022-02-02 14:48   ` Martin Liška
2022-02-02 14:50     ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).