On Tue, Jan 3, 2012 at 2:25 PM, Jakub Jelinek <ja...@redhat.com> wrote:
> Hi!
>
> Referring to malloced strings from GC hashtable macinfo_table entries
> and then freeing them at the end of compilation process is problematic
> with PCH, because without PCH the strings are malloced, but with PCH
> ggc allocated after restore and thus free on them is invalid.
>
> Fixed by making the strings GC allocated all the time.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok.

Thanks,
Richard.

> 2012-01-03  Jakub Jelinek  <ja...@redhat.com>
>
>        PR pch/51722
>        * dwarf2out.c (dwarf2out_start_source_file, dwarf2out_define,
>        dwarf2out_undef): Allocate e.info using ggc_strdup instead
>        of xstrdup.
>        (output_macinfo_op): Don't ggc_strdup fd->filename.
>        (optimize_macinfo_range): Allocate grp_name using XALLOCAVEC,
>        then ggc_strdup it.  Don't free inc->info or cur->info.
>        (output_macinfo): Don't free ref->info or file->info.
>
> --- gcc/dwarf2out.c.jj  2012-01-01 19:54:46.000000000 +0100
> +++ gcc/dwarf2out.c     2012-01-03 10:42:01.608744373 +0100
> @@ -20549,7 +20549,7 @@ dwarf2out_start_source_file (unsigned in
>       macinfo_entry e;
>       e.code = DW_MACINFO_start_file;
>       e.lineno = lineno;
> -      e.info = xstrdup (filename);
> +      e.info = ggc_strdup (filename);
>       VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
>     }
>  }
> @@ -20595,7 +20595,7 @@ dwarf2out_define (unsigned int lineno AT
>        }
>       e.code = DW_MACINFO_define;
>       e.lineno = lineno;
> -      e.info = xstrdup (buffer);;
> +      e.info = ggc_strdup (buffer);
>       VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
>     }
>  }
> @@ -20622,7 +20622,7 @@ dwarf2out_undef (unsigned int lineno ATT
>        }
>       e.code = DW_MACINFO_undef;
>       e.lineno = lineno;
> -      e.info = xstrdup (buffer);
> +      e.info = ggc_strdup (buffer);
>       VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
>     }
>  }
> @@ -20662,8 +20662,6 @@ output_macinfo_op (macinfo_entry *ref)
>     {
>     case DW_MACINFO_start_file:
>       fd = lookup_filename (ref->info);
> -      if (fd->filename == ref->info)
> -       fd->filename = ggc_strdup (fd->filename);
>       file_num = maybe_emit_file (fd);
>       dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
>       dw2_asm_output_data_uleb128 (ref->lineno,
> @@ -20802,8 +20800,8 @@ optimize_macinfo_range (unsigned int idx
>   linebuf_len = strlen (linebuf);
>
>   /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum>  */
> -  grp_name = XNEWVEC (char, 4 + encoded_filename_len + linebuf_len + 1
> -                     + 16 * 2 + 1);
> +  grp_name = XALLOCAVEC (char, 4 + encoded_filename_len + linebuf_len + 1
> +                        + 16 * 2 + 1);
>   memcpy (grp_name, DWARF_OFFSET_SIZE == 4 ? "wm4." : "wm8.", 4);
>   tail = grp_name + 4;
>   if (encoded_filename_len)
> @@ -20824,14 +20822,13 @@ optimize_macinfo_range (unsigned int idx
>   inc = VEC_index (macinfo_entry, macinfo_table, idx - 1);
>   inc->code = DW_MACRO_GNU_transparent_include;
>   inc->lineno = 0;
> -  inc->info = grp_name;
> +  inc->info = ggc_strdup (grp_name);
>   if (*macinfo_htab == NULL)
>     *macinfo_htab = htab_create (10, htab_macinfo_hash, htab_macinfo_eq, 
> NULL);
>   /* Avoid emitting duplicates.  */
>   slot = htab_find_slot (*macinfo_htab, inc, INSERT);
>   if (*slot != NULL)
>     {
> -      free (CONST_CAST (char *, inc->info));
>       inc->code = 0;
>       inc->info = NULL;
>       /* If such an entry has been used before, just emit
> @@ -20846,7 +20843,6 @@ optimize_macinfo_range (unsigned int idx
>           i++)
>        {
>          cur->code = 0;
> -         free (CONST_CAST (char *, cur->info));
>          cur->info = NULL;
>        }
>     }
> @@ -20909,7 +20905,6 @@ output_macinfo (void)
>          if (!VEC_empty (macinfo_entry, files))
>            {
>              macinfo_entry *file = VEC_last (macinfo_entry, files);
> -             free (CONST_CAST (char *, file->info));
>              VEC_pop (macinfo_entry, files);
>            }
>          break;
> @@ -20939,10 +20934,6 @@ output_macinfo (void)
>          break;
>        }
>       output_macinfo_op (ref);
> -      /* For DW_MACINFO_start_file ref->info has been copied into files
> -        vector.  */
> -      if (ref->code != DW_MACINFO_start_file)
> -       free (CONST_CAST (char *, ref->info));
>       ref->info = NULL;
>       ref->code = 0;
>     }
> @@ -20976,7 +20967,6 @@ output_macinfo (void)
>                                       ref->lineno);
>          ASM_OUTPUT_LABEL (asm_out_file, label);
>          ref->code = 0;
> -         free (CONST_CAST (char *, ref->info));
>          ref->info = NULL;
>          dw2_asm_output_data (2, 4, "DWARF macro version number");
>          if (DWARF_OFFSET_SIZE == 8)
> @@ -20989,7 +20979,6 @@ output_macinfo (void)
>       case DW_MACINFO_undef:
>        output_macinfo_op (ref);
>        ref->code = 0;
> -       free (CONST_CAST (char *, ref->info));
>        ref->info = NULL;
>        break;
>       default:
>
>        Jakub

Reply via email to