From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27909 invoked by alias); 23 Sep 2014 13:47:42 -0000 Mailing-List: contact jit-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: Sender: jit-owner@gcc.gnu.org Received: (qmail 27890 invoked by uid 89); 23 Sep 2014 13:47:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.98.4 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com From: David Malcolm To: jit@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [jit] Fix segfault in ipa-pure-const.c during LTO Date: Wed, 01 Jan 2014 00:00:00 -0000 Message-Id: <1411479838-1750-1-git-send-email-dmalcolm@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-SW-Source: 2014-q3/txt/msg00027.txt.bz2 Committed to branch dmalcolm/jit: In the initial commit on the JIT branch I moved gcc/ipa-pure-const.c: register_hooks to be a method of class pass_ipa_pure_const and the static local "init_p" within it to be member data of the class, to ensure that the pass can be rerun by separate invocations within one process. Since the IPA hooks aren't virtual functions they don't have a "this" so I faked it somewhat by setting "current_pass" before calling the hooks. Except that I only set "current_pass" when calling "generate_summary": I forgot to set it when calling the other IPA hooks. This led to a segfault when running LTO, due to a NULL dereference of "pass" in ipa-pure-const.c here, due to current_pass being NULL: Program received signal SIGSEGV, Segmentation fault. pure_const_read_summary () at ../../../src/gcc/ipa-pure-const.c:1026 1026 pass->register_hooks (); (gdb) list 1021 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data (); 1022 struct lto_file_decl_data *file_data; 1023 unsigned int j = 0; 1024 1025 pass_ipa_pure_const *pass = static_cast (current_pass); 1026 pass->register_hooks (); 1027 1028 while ((file_data = file_data_vec[j++])) 1029 { 1030 const char *data; (gdb) p current_pass $2 = (opt_pass *) 0x0 (gdb) bt #0 pure_const_read_summary () at ../../../src/gcc/ipa-pure-const.c:1026 #1 0x00000000008feb20 in ipa_read_summaries_1 (pass=0x18b3900) at ../../../src/gcc/passes.c:2457 #2 0x00000000008ffefb in ipa_read_summaries () at ../../../src/gcc/passes.c:2480 #3 0x00000000005b27bd in read_cgraph_and_symbols (fnames=, nfiles=) at ../../../src/gcc/lto/lto.c:3068 #4 lto_main () at ../../../src/gcc/lto/lto.c:3415 #5 0x00000000009bf90e in compile_file () at ../../../src/gcc/toplev.c:553 #6 0x0000000000588c94 in do_compile () at ../../../src/gcc/toplev.c:1943 #7 toplev::main (this=this@entry=0x7fffffffdb5f, argc=argc@entry=26, argv=argv@entry=0x7fffffffdc58) at ../../../src/gcc/toplev.c:2040 #8 0x000000000058987c in main (argc=26, argv=0x7fffffffdc58) at ../../../src/gcc/main.c:38 This patch fixes the crash by setting current_pass before calling an IPA hook. Bootstrapped®rtested on x86_64-unknown-linux-gnu (Fedora 20) gcc/ChangeLog: * passes.c (execute_ipa_summary_passes): Fix whitespace when assigning to current_pass. (ipa_write_summaries_2): Assign "pass" to "current_pass" global before calling write_summary hook. (ipa_write_optimization_summaries_1): Likewise when calling write_optimization_summary hook. (ipa_read_summaries_1): Likewise for read_summary hook. (ipa_read_optimization_summaries_1): Likewise for read_optimization_summary hook. (execute_ipa_stmt_fixups): Likewise for stmt_fixup hook. --- gcc/passes.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gcc/passes.c b/gcc/passes.c index 8e3b85a..772993d 100644 --- a/gcc/passes.c +++ b/gcc/passes.c @@ -1944,7 +1944,7 @@ execute_ipa_summary_passes (ipa_opt_pass_d *ipa_pass) if (pass->tv_id) timevar_push (pass->tv_id); - current_pass = pass; + current_pass = pass; ipa_pass->generate_summary (); /* Stop timevar. */ @@ -2256,6 +2256,7 @@ ipa_write_summaries_2 (opt_pass *pass, struct lto_out_decl_state *state) pass_init_dump_file (pass); + current_pass = pass; ipa_pass->write_summary (); pass_fini_dump_file (pass); @@ -2374,6 +2375,7 @@ ipa_write_optimization_summaries_1 (opt_pass *pass, pass_init_dump_file (pass); + current_pass = pass; ipa_pass->write_optimization_summary (); pass_fini_dump_file (pass); @@ -2454,6 +2456,7 @@ ipa_read_summaries_1 (opt_pass *pass) pass_init_dump_file (pass); + current_pass = pass; ipa_pass->read_summary (); pass_fini_dump_file (pass); @@ -2504,6 +2507,7 @@ ipa_read_optimization_summaries_1 (opt_pass *pass) pass_init_dump_file (pass); + current_pass = pass; ipa_pass->read_optimization_summary (); pass_fini_dump_file (pass); @@ -2583,6 +2587,7 @@ execute_ipa_stmt_fixups (opt_pass *pass, if (pass->tv_id) timevar_push (pass->tv_id); + current_pass = pass; ipa_pass->stmt_fixup (node, stmts); /* Stop timevar. */ -- 1.7.11.7