From b50ff8bbb379d7be46b3e516e02e4c9ed08d3c14 Mon Sep 17 00:00:00 2001 From: Olivier Hainque Date: Fri, 4 May 2012 08:03:54 +0000 Subject: gcc.c (eval_spec_function): Finalize/restore the current string obstack state as part of the context... * gcc.c (eval_spec_function): Finalize/restore the current string obstack state as part of the context push/pop operations. From-SVN: r187146 --- gcc/gcc.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'gcc/gcc.c') diff --git a/gcc/gcc.c b/gcc/gcc.c index 09f9b1548b8..e152b705393 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -5313,6 +5313,8 @@ eval_spec_function (const char *func, const char *args) int save_this_is_linker_script; const char *save_suffix_subst; + int save_growing_size; + void *save_growing_value; sf = lookup_spec_function (func); if (sf == NULL) @@ -5329,6 +5331,18 @@ eval_spec_function (const char *func, const char *args) save_input_from_pipe = input_from_pipe; save_suffix_subst = suffix_subst; + /* If we have some object growing now, finalize it so the args and function + eval proceed from a cleared context. This is needed to prevent the first + constructed arg from mistakenly including the growing value. We'll push + this value back on the obstack once the function evaluation is done, to + restore a consistent processing context for our caller. This is fine as + the address of growing objects isn't guaranteed to remain stable until + they are finalized, and we expect this situation to be rare enough for + the extra copy not to be an issue. */ + save_growing_size = obstack_object_size (&obstack); + if (save_growing_size > 0) + save_growing_value = obstack_finish (&obstack); + /* Create a new spec processing context, and build the function arguments. */ @@ -5354,6 +5368,9 @@ eval_spec_function (const char *func, const char *args) input_from_pipe = save_input_from_pipe; suffix_subst = save_suffix_subst; + if (save_growing_size > 0) + obstack_grow (&obstack, save_growing_value, save_growing_size); + return funcval; } -- cgit v1.2.1