From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 97F9F385C411; Wed, 2 Feb 2022 15:10:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97F9F385C411 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9533] lto: fix error handling for -Wl,-plugin-opt=debug X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: f9b49f9da2258b2e17564d4fa253cc9db3a28a82 X-Git-Newrev: fb812e0417adc20cac72986df3bf422ed007743c Message-Id: <20220202151021.97F9F385C411@sourceware.org> Date: Wed, 2 Feb 2022 15:10:21 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Feb 2022 15:10:21 -0000 https://gcc.gnu.org/g:fb812e0417adc20cac72986df3bf422ed007743c commit r11-9533-gfb812e0417adc20cac72986df3bf422ed007743c Author: Martin Liska Date: Wed Feb 2 14:21:51 2022 +0100 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.c (read_cgraph_and_symbols): Move resolution checking for number of files later and report a reasonable error message. * lto-object.c (lto_obj_file_open): Make error fatal. (cherry picked from commit 9a92e46c0e9a75cd14125493b8826d3e33dd0f67) Diff: --- gcc/lto/lto-common.c | 13 +++++++------ gcc/lto/lto-object.c | 8 ++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/gcc/lto/lto-common.c b/gcc/lto/lto-common.c index 02d16f49c11..f36edc463b3 100644 --- a/gcc/lto/lto-common.c +++ b/gcc/lto/lto-common.c @@ -2703,6 +2703,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; @@ -2725,18 +2726,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; @@ -2805,7 +2802,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.c b/gcc/lto/lto-object.c index bf6f08e5129..a898d46152d 100644 --- a/gcc/lto/lto-object.c +++ b/gcc/lto/lto-object.c @@ -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);