Fix memory chunk corruption for opts_obstack (PR jit/68446)

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
This commit is contained in:
David Malcolm 2016-01-19 14:35:16 +00:00 committed by David Malcolm
parent 962801c550
commit d6874f5662
4 changed files with 26 additions and 10 deletions

View 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

View File

@ -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,

View 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;

View 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);
}