public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
* [jit] Fix segfault in ipa-pure-const.c during LTO
@ 2014-01-01  0:00 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2014-01-01  0:00 UTC (permalink / raw)
  To: jit, gcc-patches; +Cc: David Malcolm

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 <pass_ipa_pure_const *> (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=<optimized out>, nfiles=<optimized out>)
    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&regrtested 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-09-23 13:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-01  0:00 [jit] Fix segfault in ipa-pure-const.c during LTO David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).