This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix for [Bug preprocessor/16366] Preprocessor option -remap causes memory corruption


On Friday 09 July 2004 19:14, Zack Weinberg wrote:
>
> The fact that there is a huge pile of code in files.c which is only
> ever used under DJGPP (no one except DJGPP ever uses -remap) by itself
> causes trouble for others.
>
> > I think, the best could be to reimplement remap_filename() to avoid use
> > of pfile->file_hash in it.
>
> Yes, that would also be an acceptable solution.

It seems that fix is very simple: using a different hash table for 
directories.

Bootstrapped gcc-3.5.0 20040713 (experimantal) for i686-pc-linux-gnu with and 
without fix. No regressions in testsuite found. Also similar patch for 
gcc-3.4.1 don't cause testsuite regressions (in that case bootstrapped for C 
and C++ only). It also verified (3.5.0), that included patch fixes problem 
with -remap (I specified -Wp,-remap under Linux).

Andris

Index: libcpp/files.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/files.c,v
retrieving revision 1.4
diff -p -r1.4 files.c
*** libcpp/files.c	26 Jun 2004 17:39:40 -0000	1.4
--- libcpp/files.c	15 Jul 2004 06:40:27 -0000
*************** make_cpp_dir (cpp_reader *pfile, const c
*** 884,890 ****
    cpp_dir *dir;
  
    hash_slot = (struct file_hash_entry **)
!     htab_find_slot_with_hash (pfile->file_hash, dir_name,
  			      htab_hash_string (dir_name),
  			      INSERT);
  
--- 884,890 ----
    cpp_dir *dir;
  
    hash_slot = (struct file_hash_entry **)
!     htab_find_slot_with_hash (pfile->dir_hash, dir_name,
  			      htab_hash_string (dir_name),
  			      INSERT);
  
*************** _cpp_init_files (cpp_reader *pfile)
*** 984,989 ****
--- 984,991 ----
  {
    pfile->file_hash = htab_create_alloc (127, file_hash_hash, file_hash_eq,
  					NULL, xcalloc, free);
+   pfile->dir_hash = htab_create_alloc (127, file_hash_hash, file_hash_eq,
+ 					NULL, xcalloc, free);
    allocate_file_hash_entries (pfile);
  }
  
*************** void
*** 992,997 ****
--- 994,1000 ----
  _cpp_cleanup_files (cpp_reader *pfile)
  {
    htab_delete (pfile->file_hash);
+   htab_delete (pfile->dir_hash);
  }
  
  /* Enter a file name in the hash for the sake of cpp_included.  */
Index: libcpp/internal.h
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/internal.h,v
retrieving revision 1.4
diff -p -r1.4 internal.h
*** libcpp/internal.h	30 Jun 2004 18:35:17 -0000	1.4
--- libcpp/internal.h	15 Jul 2004 06:40:27 -0000
*************** struct cpp_reader
*** 334,339 ****
--- 334,340 ----
  
    /* File and directory hash table.  */
    struct htab *file_hash;
+   struct htab *dir_hash;
    struct file_hash_entry *file_hash_entries;
    unsigned int file_hash_entries_allocated, file_hash_entries_used;
  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]