X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f From: Andris Pavenis To: gcc-patches AT gcc DOT gnu DOT org Subject: Re: Fix for [Bug preprocessor/16366] Preprocessor option -remap causes memory corruption Date: Thu, 15 Jul 2004 09:52:47 +0300 User-Agent: KMail/1.6.82 Cc: Zack Weinberg , djgpp-workers AT delorie DOT com References: <200407061101 DOT 19534 DOT pavenis AT latnet DOT lv> <200407091852 DOT 44247 DOT pavenis AT latnet DOT lv> <87658x2m5i DOT fsf AT codesourcery DOT com> In-Reply-To: <87658x2m5i.fsf@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200407150952.48641.pavenis@latnet.lv> Reply-To: djgpp-workers AT delorie DOT com 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;