From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 100601 invoked by alias); 18 Sep 2019 07:40:30 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 100020 invoked by uid 89); 18 Sep 2019 07:40:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.2 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,SPF_PASS autolearn=ham version=3.3.1 spammy=H*i:fP48HmHepQ, H*i:cW_qMN2roPxfm, H*i:CAOyqgcX1Zu94, H*f:7h_3-6Yvk X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Sep 2019 07:40:28 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B903BB6B7; Wed, 18 Sep 2019 07:40:26 +0000 (UTC) Date: Wed, 18 Sep 2019 07:40:00 -0000 From: Richard Biener To: Ian Lance Taylor cc: gcc-patches Subject: Re: Patch RFA: Emit .cfi_sections after some input code has been seen In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SW-Source: 2019-09/txt/msg01052.txt.bz2 On Tue, 17 Sep 2019, Ian Lance Taylor wrote: > This seemingly innocuous change > > 2019-09-11 Richard Biener > > * lto-opts.c (lto_write_options): Stream -g when debug is enabled. > * lto-wrapper.c (merge_and_complain): Pick up -g. > (append_compiler_options): Likewise. > (run_gcc): Re-instantiate handling -g0 at link-time. > * doc/invoke.texi (flto): Document debug info generation. > > caused PR 91763, a test failure building Go code with -flto. The > problem only arose when using the GNU assembler on Solaris. > > The bug is that when emitting debug info but not exception info, and > when using gas, the DWARF code will emit > .cfi_sections .debug_frame > This will direct gas to emit unwind info into .debug_frame but not .eh_frame. > > Go code requires unwind info, and the Go library expects it to be in > .eh_frame. The Go frontend always turns on exceptions, so this > .cfi_sections directive is not used. > > However, when using -flto, the lto1 program decides whether it is > using exceptions based on what it reads from the input files. Before > lto1 sees any input files, flag_exceptions will have its default value > of 0. And lto1 initializes the debug info before seeing any input > files, so the debug initialization thinks that exceptions are not in > use, and emits the .cfi_sections directive. > > This problem was uncovered by the above patch because Go code also > turns on debugging by default, and so lto1 now sees a -g option that > it did not see before. > > This patch fixes the problem by moving the emission of .cfi_sections > from debug init to the first time that the debug info needs to know > whether CFI is supported. This is only done when actually emitting > debug info, and therefore after some input files have been read. > > Bootstrapped and ran full testsuite on x86_64-pc-linux-gnu. Tested > that formerly failing case now passes on sparc-sun-solaris2.11. > > OK for trunk? Hmm. To me it looks like there's nothing guaranteeing that flag_exceptions is initialized appropriately since it's set on function body read-in which is now on-demand. So I'm not sure that we cannot have functions output into assembly before flag_exceptions is initialized. Also dwarf2out_do_cfi_asm is a predicate which makes it an awkward point. Maybe at the time we emit the first .cfi assembly instruction would be the correct (and latest) point in time to emit this directive? Anyways, I am testing the patch below which initializes flag_exceptions before dwarf2out_assembly_start by moving the initialization to a central place. The lto_input_ts_function_decl_tree_pointers made this work for most languages but not for those not having a language-specific personality routine, so I have to check flag_exceptions as well (the decls struct function are not input yet, but we do save the CUs -fexception setting accordingly). Note this doesn't solve PR91794 where the same issue for -funwind-tables setting applies, but the fix could look similar. LTO bootstrap and regtest running on x86_64-unknown-linux-gnu. Richard. 2019-09-18 Richard Biener PR lto/91763 * lto-streamer-in.c (input_eh_regions): Move EH init to lto_materialize_function. * tree-streamer-in.c (lto_input_ts_function_decl_tree_pointers): Likewise. lto/ * lto.c (lto_materialize_function): Initialize EH by looking at the function personality and flag_exceptions setting. Index: gcc/lto-streamer-in.c =================================================================== --- gcc/lto-streamer-in.c (revision 275800) +++ gcc/lto-streamer-in.c (working copy) @@ -615,11 +615,6 @@ input_eh_regions (struct lto_input_block lto_tag_check_range (tag, LTO_eh_table, LTO_eh_table); - /* If the file contains EH regions, then it was compiled with - -fexceptions. In that case, initialize the backend EH - machinery. */ - lto_init_eh (); - gcc_assert (fn->eh); root_region = streamer_read_hwi (ib); Index: gcc/tree-streamer-in.c =================================================================== --- gcc/tree-streamer-in.c (revision 275800) +++ gcc/tree-streamer-in.c (working copy) @@ -800,12 +800,6 @@ lto_input_ts_function_decl_tree_pointers } } #endif - - /* If the file contains a function with an EH personality set, - then it was compiled with -fexceptions. In that case, initialize - the backend EH machinery. */ - if (DECL_FUNCTION_PERSONALITY (expr)) - lto_init_eh (); } Index: gcc/lto/lto.c =================================================================== --- gcc/lto/lto.c (revision 275800) +++ gcc/lto/lto.c (working copy) @@ -218,6 +218,12 @@ lto_materialize_function (struct cgraph_ return; if (DECL_FUNCTION_PERSONALITY (decl) && !first_personality_decl) first_personality_decl = DECL_FUNCTION_PERSONALITY (decl); + /* If the file contains a function with a language specific EH + personality set or with EH enabled initialize the backend EH + machinery. */ + if (DECL_FUNCTION_PERSONALITY (decl) + || opt_for_fn (decl, flag_exceptions)) + lto_init_eh (); } /* Let the middle end know about the function. */