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]

Libiberty/alloca patch: fix giant memory leak in fixincl/gnu-regex


I noticed that fixincl recently started running much more slowly.
Spot checking it in my "top" window showed it consuming 50 to 200Mb
depending on the directory it operated on.  I only saw this behavior
when using cc for stage1, not with gcc for stage1.

Turns out, fixinc/gnu-regex.c relies on C_ALLOCA to know when to call
alloca(0) and free up the memory allocated by the C alloca routine.
C_ALLOCA is normally defined by the autoconf macro AC_FUNC_ALLOCA,
which we no longer use after the alloca reorg in libiberty.

After installing the following patch, fixincl's memory usage when
compiled by cc is comparable to when its compiled with gcc, i.e. 1 to
2Mb.

Tested by building stage1 with cc and gcc on solaris2.7 and monitoring
memory usage of fixincl.

Ok to install?

		--Kaveh


2001-03-29  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* libiberty.h (alloca): Handle setting C_ALLOCA.

diff -rup orig/egcs-CVS20010328/include/libiberty.h egcs-CVS20010328/include/libiberty.h
--- orig/egcs-CVS20010328/include/libiberty.h	Wed Mar 14 16:43:57 2001
+++ egcs-CVS20010328/include/libiberty.h	Thu Mar 29 16:24:26 2001
@@ -238,15 +238,20 @@ extern int vasprintf PARAMS ((char **, c
 /* Drastically simplified alloca configurator.  If we're using GCC,
    we use __builtin_alloca; otherwise we use the C alloca.  The C
    alloca is always available.  You can override GCC by defining
-   USE_C_ALLOCA yourself.  */
+   USE_C_ALLOCA yourself.  The canonical autoconf macro C_ALLOCA is
+   also set/unset as it is often used to indicate whether code needs
+   to call alloca(0).  */
 extern PTR C_alloca PARAMS((size_t));
 #undef alloca
 #if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA
 # define alloca(x) __builtin_alloca(x)
+# undef C_ALLOCA
 #else
 # define alloca(x) C_alloca(x)
 # undef USE_C_ALLOCA
 # define USE_C_ALLOCA 1
+# undef C_ALLOCA
+# define C_ALLOCA 1
 #endif
 
 #ifdef __cplusplus


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