From patchwork Mon Mar 10 20:55:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 328818 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2D42C2C1F5C for ; Tue, 11 Mar 2014 07:57:00 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=Epsox8jJiEAi rNsm64JMHd/5pt9bSdHD6rGFVIQNUjgWrhO5zvpaF4NSEcJL6TjCHGiVj6RPKvts 4JNC+0XgaIPaqNb6sbuXGjkBDvaoo5xaULEaC9fmb08kNXLyfCqw+132JmjCDln2 9DqAsF8JPPty1sPeMxBskg8bPu2Wuug= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=UVDp5k4BiKbQUjo701 vH4TcVCvA=; b=S/r2Vj4+VU5z57JMcAmdxhDjmT/C2o/pNkKSgs2RsaKx0C2xjO mWrNdOOTp53vwpO6wvSyaPpT5iHltizGTwKJp5j+GW16fyDQHjvg+HcSAj10Qdob 1I4ULiu74vMqhPbaD81wGuqMXLxcvRbbp2VmP3nZV+i58NYRXTFXcfryY= Received: (qmail 3582 invoked by alias); 10 Mar 2014 20:56:53 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 3559 invoked by uid 89); 10 Mar 2014 20:56:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 10 Mar 2014 20:56:51 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2AKunca025760 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 10 Mar 2014 16:56:50 -0400 Received: from surprise.redhat.com (vpn-239-141.phx2.redhat.com [10.3.239.141]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s2AKunSi014122; Mon, 10 Mar 2014 16:56:49 -0400 From: David Malcolm To: jit@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [jit] Fix global state init_p within ipa_init Date: Mon, 10 Mar 2014 16:55:12 -0400 Message-Id: <1394484912-27797-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes Committed to branch dmalcolm/jit: Attempting to repeatedly compile with optimizations on within one process would, under some circumstances, lead to a segfault the second time in, here: #0 splay_tree_delete (sp=0x0) at ../../src/libiberty/splay-tree.c:353 #1 0x00007ffff77f104f in propagate () at ../../src/gcc/ipa-reference.c:878 #2 0x00007ffff77f1d23 in (anonymous namespace)::pass_ipa_reference::execute (this=0x72f5d0) at ../../src/gcc/ipa-reference.c:1191 #3 0x00007ffff6fc5237 in execute_one_pass (pass=0x72f5d0) at ../../src/gcc/passes.c:2216 #4 0x00007ffff6fc6044 in execute_ipa_pass_list (pass=0x72f5d0) at ../../src/gcc/passes.c:2580 #5 0x00007ffff6c93d5f in ipa_passes () at ../../src/gcc/cgraphunit.c:2027 The crash occurred here: #1 0x00007ffff77f104f in propagate () at ../../src/gcc/ipa-reference.c:878 878 splay_tree_delete (reference_vars_to_consider); (gdb) p reference_vars_to_consider $10 = (splay_tree) 0x0 This tended to occur when working with functions intended to be inlined. Debuggging indicated that the root-cause was the "init_p" flag within ipa_init: it is static, presumably to allow idempotent initialization. However, there is also cleanup, so that the 2nd time in, ipa-reference.c is working with post-clean up state, failing to rebuild its data structures (e.g. a NULL for "reference_vars_to_consider"). Hence this patches changes ipa initialization from being idempotent within the lifetime of the process to being idempotent within one invocation of toplev_main, by moving it from static in function scope to *file* scope, adding a reset of the flag to toplev_finalize. [That said, I *think* ipa_init is only called at most once per invocation of toplev_main.] Doing so allows the optimizer to inline functions in repeated invocations of the compiler within one process. [...provided debuginfo generation is disabled. In this latter case, with GCC_JIT_BOOL_OPTION_DEBUGINFO, the equivalent of -g, I'm currently running into what I take to be a separate segfault in dwarf2out.c the second time in. I haven't tracked this other one down yet.] gcc/ * ipa-reference.c (ipa_init): Move static bool init_p from here to... (ipa_init_p): New file-scope variable, so that it can be reset when repeatedly invoking the compiler within one process by... (ipa_reference_c_finalize): New function. * ipa-reference.h (ipa_reference_c_finalize): New. * toplev.c (toplev_finalize): Invoke new function ipa_reference_c_finalize. --- gcc/ChangeLog.jit | 11 +++++++++++ gcc/ipa-reference.c | 13 +++++++++---- gcc/ipa-reference.h | 1 + gcc/toplev.c | 2 ++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/gcc/ChangeLog.jit b/gcc/ChangeLog.jit index 555fc76..0e35180 100644 --- a/gcc/ChangeLog.jit +++ b/gcc/ChangeLog.jit @@ -1,3 +1,14 @@ +2014-03-10 David Malcolm + + * ipa-reference.c (ipa_init): Move static bool init_p from here + to... + (ipa_init_p): New file-scope variable, so that it can be reset + when repeatedly invoking the compiler within one process by... + (ipa_reference_c_finalize): New function. + * ipa-reference.h (ipa_reference_c_finalize): New. + * toplev.c (toplev_finalize): Invoke new function + ipa_reference_c_finalize. + 2014-01-24 David Malcolm * timevar.def: Replace TV_CLIENT_CALLBACK with TV_JIT_REPLAY. diff --git a/gcc/ipa-reference.c b/gcc/ipa-reference.c index b3e137e..2a6671f 100644 --- a/gcc/ipa-reference.c +++ b/gcc/ipa-reference.c @@ -403,17 +403,17 @@ propagate_bits (ipa_reference_global_vars_info_t x_global, struct cgraph_node *x } } +static bool ipa_init_p = false; + /* The init routine for analyzing global static variable usage. See comments at top for description. */ static void ipa_init (void) { - static bool init_p = false; - - if (init_p) + if (ipa_init_p) return; - init_p = true; + ipa_init_p = true; if (dump_file) reference_vars_to_consider = splay_tree_new (splay_tree_compare_ints, 0, 0); @@ -1199,3 +1199,8 @@ make_pass_ipa_reference (gcc::context *ctxt) { return new pass_ipa_reference (ctxt); } + +void ipa_reference_c_finalize (void) +{ + ipa_init_p = false; +} diff --git a/gcc/ipa-reference.h b/gcc/ipa-reference.h index 317ebb0..fbcf6fa 100644 --- a/gcc/ipa-reference.h +++ b/gcc/ipa-reference.h @@ -26,6 +26,7 @@ along with GCC; see the file COPYING3. If not see /* In ipa-reference.c */ bitmap ipa_reference_get_not_read_global (struct cgraph_node *fn); bitmap ipa_reference_get_not_written_global (struct cgraph_node *fn); +void ipa_reference_c_finalize (void); #endif /* GCC_IPA_REFERENCE_H */ diff --git a/gcc/toplev.c b/gcc/toplev.c index 2418f7b..9de1c2d 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -78,6 +78,7 @@ along with GCC; see the file COPYING3. If not see #include "context.h" #include "pass_manager.h" #include "dwarf2out.h" +#include "ipa-reference.h" #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) #include "dbxout.h" @@ -2000,6 +2001,7 @@ void toplev_finalize (void) cgraphunit_c_finalize (); dwarf2out_c_finalize (); ipa_c_finalize (); + ipa_reference_c_finalize (); predict_c_finalize (); symtab_c_finalize (); varpool_c_finalize ();