]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - bfd/elf.c
* elf-bfd.h (elf_backend_data <elf_backend_section_from_bfd_section>):
[thirdparty/binutils-gdb.git] / bfd / elf.c
index 080d517bb6942063dd7b5a74633fd5892dfc9514..2c14de8a60fdbcda5e579804aa2475972e70031a 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4050,50 +4050,47 @@ _bfd_elf_section_from_bfd_section (abfd, asect)
      bfd *abfd;
      struct sec *asect;
 {
-  struct elf_backend_data *bed = get_elf_backend_data (abfd);
-  Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd);
+  struct elf_backend_data *bed;
   int index;
-  Elf_Internal_Shdr *hdr;
-  int maxindex = elf_numsections (abfd);
 
   if (elf_section_data (asect) != NULL
       && elf_section_data (asect)->this_idx != 0)
     return elf_section_data (asect)->this_idx;
 
   if (bfd_is_abs_section (asect))
-    return SHN_ABS;
-  if (bfd_is_com_section (asect))
-    return SHN_COMMON;
-  if (bfd_is_und_section (asect))
-    return SHN_UNDEF;
-
-  for (index = 1; index < maxindex; index++)
+    index = SHN_ABS;
+  else if (bfd_is_com_section (asect))
+    index = SHN_COMMON;
+  else if (bfd_is_und_section (asect))
+    index = SHN_UNDEF;
+  else
     {
-      hdr = i_shdrp[index];
-      if (hdr != NULL && hdr->bfd_section == asect)
-       return index;
+      Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd);
+      int maxindex = elf_numsections (abfd);
+
+      for (index = 1; index < maxindex; index++)
+       {
+         Elf_Internal_Shdr *hdr = i_shdrp[index];
+
+         if (hdr != NULL && hdr->bfd_section == asect)
+           return index;
+       }
+      index = -1;
     }
 
+  bed = get_elf_backend_data (abfd);
   if (bed->elf_backend_section_from_bfd_section)
     {
-      for (index = 0; index < maxindex; index++)
-       {
-         int retval;
+      int retval = index;
 
-         hdr = i_shdrp[index];
-         if (hdr == NULL)
-           continue;
-
-         retval = index;
-         if ((*bed->elf_backend_section_from_bfd_section)
-             (abfd, hdr, asect, &retval))
-           return retval;
-       }
+      if ((*bed->elf_backend_section_from_bfd_section) (abfd, asect, &retval))
+       return retval;
     }
 
-  bfd_set_error (bfd_error_nonrepresentable_section);
+  if (index == -1)
+    bfd_set_error (bfd_error_nonrepresentable_section);
 
-  return SHN_BAD;
+  return index;
 }
 
 /* Given a BFD symbol, return the index in the ELF symbol table, or -1