[v2,1/2] count number of loaded objects in each namespace only once

Message ID 1470232359-18696-2-git-send-email-gleb@scylladb.com
State New, archived
Headers

Commit Message

Gleb Natapov Aug. 3, 2016, 1:52 p.m. UTC
  _ns_nloaded already has count of all objects in a namespace, no need to
add it while iterating over all objects.
---
 elf/dl-iteratephdr.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
  

Comments

Mike Frysinger Aug. 5, 2016, 3:31 a.m. UTC | #1
On 03 Aug 2016 16:52, Gleb Natapov wrote:
> --- a/elf/dl-iteratephdr.c
> +++ b/elf/dl-iteratephdr.c
> @@ -48,17 +48,18 @@ __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
>  #ifdef SHARED
>    const void *caller = RETURN_ADDRESS (0);
>    for (Lmid_t cnt = GL(dl_nns) - 1; cnt > 0; --cnt)
> +    {
> +    /* We have to count the total number of loaded objects.  */
> +    nloaded += GL(dl_ns)[cnt]._ns_nloaded;
>      for (struct link_map *l = GL(dl_ns)[cnt]._ns_loaded; l; l = l->l_next)

since you've added a scope here, all the code in it needs to be indented
by one more level
-mike
  

Patch

diff --git a/elf/dl-iteratephdr.c b/elf/dl-iteratephdr.c
index 1cb6e26..2be4d2d 100644
--- a/elf/dl-iteratephdr.c
+++ b/elf/dl-iteratephdr.c
@@ -48,17 +48,18 @@  __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
 #ifdef SHARED
   const void *caller = RETURN_ADDRESS (0);
   for (Lmid_t cnt = GL(dl_nns) - 1; cnt > 0; --cnt)
+    {
+    /* We have to count the total number of loaded objects.  */
+    nloaded += GL(dl_ns)[cnt]._ns_nloaded;
     for (struct link_map *l = GL(dl_ns)[cnt]._ns_loaded; l; l = l->l_next)
       {
-	/* We have to count the total number of loaded objects.  */
-	nloaded += GL(dl_ns)[cnt]._ns_nloaded;
-
 	if (caller >= (const void *) l->l_map_start
 	    && caller < (const void *) l->l_map_end
 	    && (l->l_contiguous
 		|| _dl_addr_inside_object (l, (ElfW(Addr)) caller)))
 	  ns = cnt;
       }
+    }
 #endif
 
   for (l = GL(dl_ns)[ns]._ns_loaded; l != NULL; l = l->l_next)