This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils 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: Bug in dwfl_module_relocations


On Wed, 2011-10-19 at 16:35 -0700, Roland McGrath wrote:
> That looks correct.  But I see that all callers of cache_sections
> conditionalize its call the same way.  So might as well just move the
> short-circuit logic into the top of that function and remove the
> duplications of it, and here it will be a tail call.

You mean like the following?

2011-10-20  Mark Wielaard  <mjw@redhat.com>

        * derelocate.c (cache_sections): Intern mod->reloc_info check.
        (dwfl_module_relocations): Don't check mod->reloc_info.
        (dwfl_module_relocation_info): Likewise.
        (find_section): Likewise.

Thanks,

Mark
diff --git a/libdwfl/derelocate.c b/libdwfl/derelocate.c
index ba6d9db..d4b6b26 100644
--- a/libdwfl/derelocate.c
+++ b/libdwfl/derelocate.c
@@ -93,6 +93,9 @@ cache_sections (Dwfl_Module *mod)
   struct secref *refs = NULL;
   size_t nrefs = 0;
 
+  if (likely (mod->reloc_info != NULL))
+    return mod->reloc_info->count;
+
   size_t shstrndx;
   if (unlikely (elf_getshdrstrndx (mod->main.elf, &shstrndx) < 0))
     {
@@ -227,9 +230,6 @@ dwfl_module_relocations (Dwfl_Module *mod)
   if (mod == NULL)
     return -1;
 
-  if (mod->reloc_info != NULL)
-    return mod->reloc_info->count;
-
   switch (mod->e_type)
     {
     case ET_REL:
@@ -269,7 +269,7 @@ dwfl_module_relocation_info (Dwfl_Module *mod, unsigned int idx,
       return NULL;
     }
 
-  if (unlikely (mod->reloc_info == NULL) && cache_sections (mod) < 0)
+  if (cache_sections (mod) < 0)
     return NULL;
 
   struct dwfl_relocation *sections = mod->reloc_info;
@@ -318,7 +318,7 @@ check_module (Dwfl_Module *mod)
 static int
 find_section (Dwfl_Module *mod, Dwarf_Addr *addr)
 {
-  if (unlikely (mod->reloc_info == NULL) && cache_sections (mod) < 0)
+  if (cache_sections (mod) < 0)
     return -1;
 
   struct dwfl_relocation *sections = mod->reloc_info;

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