bfd_get_section_by_name_if hash chain traversal
authorAlan Modra <amodra@gmail.com>
Fri, 24 Jul 2015 05:06:38 +0000 (14:36 +0930)
committerAlan Modra <amodra@gmail.com>
Fri, 24 Jul 2015 05:18:35 +0000 (14:48 +0930)
This function stops too soon, as I found when the hash chain happened
to contain two .debug_macro sections and a .bss section:
.debug_macro -> .bss -> .debug_macro

* section.c (bfd_get_section_by_name_if): Iterate over entire hash
chain.

bfd/ChangeLog
bfd/section.c

index 9db32edea3b944dc3b687ddf6a170515b7177126..6a29b7a439f3fc0975756af6f56f7915cb1b893c 100644 (file)
@@ -1,3 +1,8 @@
+2015-07-24  Alan Modra  <amodra@gmail.com>
+
+       * section.c (bfd_get_section_by_name_if): Iterate over entire hash
+       chain.
+
 2015-07-23  Joseph Myers  <joseph@codesourcery.com>
 
        * elfxx-mips.c (_bfd_mips_elf_finish_dynamic_sections)
index 6af174afa8bbf2e3de485145081e9f3d459b361f..aa652a41d79ac3b08f699d40644e69a880bdd407 100644 (file)
@@ -994,14 +994,11 @@ bfd_get_section_by_name_if (bfd *abfd, const char *name,
     return NULL;
 
   hash = sh->root.hash;
-  do
-    {
-      if ((*operation) (abfd, &sh->section, user_storage))
-       return &sh->section;
-      sh = (struct section_hash_entry *) sh->root.next;
-    }
-  while (sh != NULL && sh->root.hash == hash
-        && strcmp (sh->root.string, name) == 0);
+  for (; sh != NULL; sh = (struct section_hash_entry *) sh->root.next)
+    if (sh->root.hash == hash
+       && strcmp (sh->root.string, name) == 0
+       && (*operation) (abfd, &sh->section, user_storage))
+      return &sh->section;
 
   return NULL;
 }