From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 33C1A3858025; Wed, 2 Feb 2022 13:24:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 33C1A3858025 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/PR104333-lto-error-handling)] lto: fix error handling for -Wl, -plugin-opt=debug X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/users/marxin/heads/PR104333-lto-error-handling X-Git-Oldrev: cac2f69cdad434ad5cb60f5fe931d45cd82ef476 X-Git-Newrev: 818e357c9a0fd984bfe48e1fedb36e6e9577cd85 Message-Id: <20220202132435.33C1A3858025@sourceware.org> Date: Wed, 2 Feb 2022 13:24:35 +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 13:24:35 -0000 https://gcc.gnu.org/g:818e357c9a0fd984bfe48e1fedb36e6e9577cd85 commit 818e357c9a0fd984bfe48e1fedb36e6e9577cd85 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: error: open debug failed: No such file or directory lto1: fatal error: errors during merging of translation units 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. Diff: --- 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))