[patch] Reduce ridiculous stack use in _dl_map_object_deps

Paul Pluzhnikov ppluzhnikov@google.com
Mon Oct 31 22:11:00 GMT 2011


On Mon, Oct 31, 2011 at 2:23 PM, Roland McGrath <roland@hack.frob.com> wrote:

> Use an initialized defn.

Done.

>> +       if (new_size > needed_space_bytes)
>> +         needed_space
>> +           = extend_alloca (needed_space, needed_space_bytes, new_size);
>> +
>> +       needed = needed_space;
>
> Something has to update needed_space_bytes.

extend_alloca does.

Thanks,
-- 
Paul Pluzhnikov

2011-10-31  Paul Pluzhnikov  <ppluzhnikov@google.com>

       * elf/dl-deps.c (_dl_map_object_deps): Reuse alloca space to reduce
       stack usage.
-------------- next part --------------
diff --git a/elf/dl-deps.c b/elf/dl-deps.c
index 95b1088..899de2f 100644
--- a/elf/dl-deps.c
+++ b/elf/dl-deps.c
@@ -156,6 +156,8 @@ _dl_map_object_deps (struct link_map *map,
   int errno_reason;
   const char *errstring;
   const char *objname;
+  struct link_map **needed_space;
+  size_t needed_space_bytes;
 
   auto inline void preload (struct link_map *map);
 
@@ -175,6 +177,10 @@ _dl_map_object_deps (struct link_map *map,
   /* No loaded object so far.  */
   nlist = 0;
 
+  /* No alloca'd space yet.  */
+  needed_space = NULL;
+  needed_space_bytes = 0;
+
   /* First load MAP itself.  */
   preload (map);
 
@@ -216,8 +222,19 @@ _dl_map_object_deps (struct link_map *map,
 	 dependencies of this object.  */
       if (l->l_searchlist.r_list == NULL && l->l_initfini == NULL
 	  && l != map && l->l_ldnum > 0)
-	needed = (struct link_map **) alloca (l->l_ldnum
-					      * sizeof (struct link_map *));
+	{
+	  /* 16-align so extend_alloca has a chance to re-use the space.
+	     Note that extend_alloca is broken for recent versions of GCC
+	     on x86: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50938  */
+	  size_t new_size
+	    = (l->l_ldnum * sizeof (struct link_map *) + 15) & ~15;
+
+	  if (new_size > needed_space_bytes)
+	    needed_space
+	      = extend_alloca (needed_space, needed_space_bytes, new_size);
+
+	  needed = needed_space;
+	}
 
       if (l->l_info[DT_NEEDED] || l->l_info[AUXTAG] || l->l_info[FILTERTAG])
 	{


More information about the Libc-alpha mailing list