]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix memory chunk corruption for opts_obstack (PR jit/68446)
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 19 Jan 2016 14:35:16 +0000 (14:35 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Tue, 19 Jan 2016 14:35:16 +0000 (14:35 +0000)
gcc/ChangeLog:
PR jit/68446
* gcc.c (driver::decode_argv): Add call to
init_opts_obstack before init_options_struct.
* opts.c (init_opts_obstack): Remove idempotency.
(init_options_struct): Replace call to init_opts_obstack
with a gcc_assert to verify that it has already been called.
* toplev.c (toplev::main): Add call to init_opts_obstack before
calls to init_options_struct.
(toplev::finalize): Move cleanup of opts_obstack next to
cleanup of save_decoded_options, clearing the latter, and
save_decoded_options_count.

From-SVN: r232567

gcc/ChangeLog
gcc/gcc.c
gcc/opts.c
gcc/toplev.c

index bffbedf2591151ab04ed6d7a3a9ea02a44ff10f1..56890c1b97615c37c51636433383f0c95cc61f50 100644 (file)
@@ -1,3 +1,17 @@
+2016-01-19  David Malcolm  <dmalcolm@redhat.com>
+
+       PR jit/68446
+       * gcc.c (driver::decode_argv): Add call to
+       init_opts_obstack before init_options_struct.
+       * opts.c (init_opts_obstack): Remove idempotency.
+       (init_options_struct): Replace call to init_opts_obstack
+       with a gcc_assert to verify that it has already been called.
+       * toplev.c (toplev::main): Add call to init_opts_obstack before
+       calls to init_options_struct.
+       (toplev::finalize): Move cleanup of opts_obstack next to
+       cleanup of save_decoded_options, clearing the latter, and
+       save_decoded_options_count.
+
 2016-01-19  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        PR target/69135
index f04fdc440d2a79f3415a145bb14b3a1439c44dab..683b30fcbab1e291c85d06221e54cc6fa1f81ab7 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -7216,6 +7216,7 @@ driver::decode_argv (int argc, const char **argv)
   global_init_params ();
   finish_params ();
 
+  init_opts_obstack ();
   init_options_struct (&global_options, &global_options_set);
 
   decode_cmdline_options_to_array (argc, argv,
index 8e8410cd370025e969be179cdddbb418791056c0..b4e8144489cde2a86087c9c0fe99ff60a7c23c63 100644 (file)
@@ -266,18 +266,12 @@ add_comma_separated_to_vector (void **pvec, const char *arg)
   *pvec = v;
 }
 
-/* Initialize opts_obstack if not initialized.  */
+/* Initialize opts_obstack.  */
 
 void
 init_opts_obstack (void)
 {
-  static bool opts_obstack_initialized = false;
-
-  if (!opts_obstack_initialized)
-    {
-      opts_obstack_initialized = true;
-      gcc_obstack_init (&opts_obstack);
-    }
+  gcc_obstack_init (&opts_obstack);
 }
 
 /* Initialize OPTS and OPTS_SET before using them in parsing options.  */
@@ -287,7 +281,9 @@ init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set)
 {
   size_t num_params = get_num_compiler_params ();
 
-  init_opts_obstack ();
+  /* Ensure that opts_obstack has already been initialized by the time
+     that we initialize any gcc_options instances (PR jit/68446).  */
+  gcc_assert (opts_obstack.chunk_size > 0);
 
   *opts = global_options_init;
 
index b754e5b24085cf9adadd9e91092878e62f21f355..28c115d71c4faa764609a9508f105f97820c825a 100644 (file)
@@ -2053,6 +2053,7 @@ toplev::main (int argc, char **argv)
   /* One-off initialization of options that does not need to be
      repeated when options are added for particular functions.  */
   init_options_once ();
+  init_opts_obstack ();
 
   /* Initialize global options structures; this must be repeated for
      each structure used for parsing options.  */
@@ -2134,11 +2135,15 @@ toplev::finalize (void)
   finalize_options_struct (&global_options);
   finalize_options_struct (&global_options_set);
 
+  /* save_decoded_options uses opts_obstack, so these must
+     be cleaned up together.  */
+  obstack_free (&opts_obstack, NULL);
   XDELETEVEC (save_decoded_options);
+  save_decoded_options = NULL;
+  save_decoded_options_count = 0;
 
   /* Clean up the context (and pass_manager etc). */
   delete g;
   g = NULL;
 
-  obstack_free (&opts_obstack, NULL);
 }