* elf.c (_bfd_elf_find_segment_containing_section): New function:
authorNick Clifton <nickc@redhat.com>
Mon, 31 Dec 2007 11:01:54 +0000 (11:01 +0000)
committerNick Clifton <nickc@redhat.com>
Mon, 31 Dec 2007 11:01:54 +0000 (11:01 +0000)
  Scan the segment map looking for the segment containing a
  specified function.
* elf-bfd.h: Prototype the new function.
* elf-hppa.h (elf_hppa_osec_to_segment): Delete.
  (elf_hppa_record_segment_addrs): Use new function.
* elf32-bfin.c (_bfdfdpic_osec_to_segment): Use new function.
* elf32-frv.c (_frvfdpic_osec_to_segment): Use new function.
* elf32-hppa.c (hppa_record_segment_addr): Use new function.
* elfxx-ia64.c (elfNN_ia64_relocate_section): Use new function.

bfd/ChangeLog
bfd/elf-bfd.h
bfd/elf-hppa.h
bfd/elf.c
bfd/elf32-bfin.c
bfd/elf32-frv.c
bfd/elf32-hppa.c
bfd/elfxx-ia64.c

index 546dfaf006a60f447fce17d9310a1d12b34474ef..d12d61556665cf3c709bbcbeeebcae3f70ce0176 100644 (file)
@@ -1,3 +1,16 @@
+2007-12-31  Nick Clifton  <nickc@redhat.com>
+
+       * elf.c (_bfd_elf_find_segment_containing_section): New function:
+       Scan the segment map looking for the segment containing a
+       specified function.
+       * elf-bfd.h: Prototype the new function.
+       * elf-hppa.h (elf_hppa_osec_to_segment): Delete.
+       (elf_hppa_record_segment_addrs): Use new function.
+       * elf32-bfin.c (_bfdfdpic_osec_to_segment): Use new function.
+       * elf32-frv.c (_frvfdpic_osec_to_segment): Use new function.
+       * elf32-hppa.c (hppa_record_segment_addr): Use new function.
+       * elfxx-ia64.c (elfNN_ia64_relocate_section): Use new function.
+       
 2007-12-28  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
 
        PR binutils/5146
index 918eec31ce08de359565df00d4f33558350ff6b3..dc9f1538a236347d3992a19e26ec07d4b88caf9d 100644 (file)
@@ -2076,6 +2076,9 @@ extern bfd_boolean _bfd_elf_map_sections_to_segments
 
 extern bfd_boolean _bfd_elf_is_function_type (unsigned int);
 
+extern Elf_Internal_Phdr * _bfd_elf_find_segment_containing_section
+  (bfd * abfd, asection * section);
+
 /* Exported interface for writing elf corefile notes. */
 extern char *elfcore_write_note
   (bfd *, char *, int *, const char *, int, const void *, int);
index a7850cefc5f3f5cd75605c21fbacff62421bf699..c82264b9feb390d6f572855179d487a5f0634125 100644 (file)
@@ -1088,35 +1088,6 @@ elf_hppa_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr, asection *sec)
   return TRUE;
 }
 
-/* Find the segment number in which OSEC, and output section, is
-   located.  */
-
-static unsigned
-elf_hppa_osec_to_segment (bfd *output_bfd, asection *osec)
-{
-  struct elf_segment_map *m;
-  Elf_Internal_Phdr *p;
-
-  /* Find the segment that contains the output_section.  */
-  for (m = elf_tdata (output_bfd)->segment_map,
-        p = elf_tdata (output_bfd)->phdr;
-       m != NULL;
-       m = m->next, p++)
-    {
-      int i;
-
-      for (i = m->count - 1; i >= 0; i--)
-       if (m->sections[i] == osec)
-         break;
-
-      if (i >= 0)
-       break;
-    }
-
-  BFD_ASSERT (m);
-  return p - elf_tdata (output_bfd)->phdr;
-}
-
 static void
 elf_hppa_final_write_processing (bfd *abfd,
                                 bfd_boolean linker ATTRIBUTE_UNUSED)
@@ -1337,8 +1308,12 @@ elf_hppa_record_segment_addrs (bfd *abfd,
 
   if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
     {
-      unsigned seg = elf_hppa_osec_to_segment (abfd, section->output_section);
-      bfd_vma value = elf_tdata (abfd)->phdr[seg].p_vaddr;
+      bfd_vma value;
+      Elf_Internal_Phdr *p;
+
+      p = _bfd_elf_find_segment_containing_section (abfd, section->output_section);
+      BFD_ASSERT (p != NULL);
+      value = p->p_vaddr;
 
       if (section->flags & SEC_READONLY)
        {
index ce9aa8081e60fc0ba3a266a3432c9d37253e6d20..60221046345680652e95f8f7f19a53624b1032b1 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3426,6 +3426,29 @@ get_program_header_size (bfd *abfd, struct bfd_link_info *info)
   return segs * bed->s->sizeof_phdr;
 }
 
+/* Find the segment that contains the output_section of section.  */
+
+Elf_Internal_Phdr *
+_bfd_elf_find_segment_containing_section (bfd * abfd, asection * section)
+{
+  struct elf_segment_map *m;
+  Elf_Internal_Phdr *p;
+
+  for (m = elf_tdata (abfd)->segment_map,
+        p = elf_tdata (abfd)->phdr;
+       m != NULL;
+       m = m->next, p++)
+    {
+      int i;
+
+      for (i = m->count - 1; i >= 0; i--)
+       if (m->sections[i] == section)
+         return p;
+    }
+
+  return NULL;
+}
+
 /* Create a mapping from a set of sections to a program segment.  */
 
 static struct elf_segment_map *
index cff16b1aad3695dd2e21e9f1b266fed11943e61b..091e74ed8bf5e7ca5efee346c7d23f8e7bea0d2d 100644 (file)
@@ -1497,26 +1497,9 @@ _bfinfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset,
 static unsigned
 _bfinfdpic_osec_to_segment (bfd *output_bfd, asection *osec)
 {
-  struct elf_segment_map *m;
-  Elf_Internal_Phdr *p;
-
-  /* Find the segment that contains the output_section.  */
-  for (m = elf_tdata (output_bfd)->segment_map,
-        p = elf_tdata (output_bfd)->phdr;
-       m != NULL;
-       m = m->next, p++)
-    {
-      int i;
-
-      for (i = m->count - 1; i >= 0; i--)
-       if (m->sections[i] == osec)
-         break;
-
-      if (i >= 0)
-       break;
-    }
+  Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section (output_bfd, osec);
 
-  return p - elf_tdata (output_bfd)->phdr;
+  return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1;
 }
 
 inline static bfd_boolean
index 4fc4359f952b73a10599fa2433d6ba2ca6f8b305..6ce1b9f1143df64dade724d57d892d7846d80791 100644 (file)
@@ -1341,26 +1341,9 @@ _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset,
 static unsigned
 _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec)
 {
-  struct elf_segment_map *m;
-  Elf_Internal_Phdr *p;
-
-  /* Find the segment that contains the output_section.  */
-  for (m = elf_tdata (output_bfd)->segment_map,
-        p = elf_tdata (output_bfd)->phdr;
-       m != NULL;
-       m = m->next, p++)
-    {
-      int i;
-
-      for (i = m->count - 1; i >= 0; i--)
-       if (m->sections[i] == osec)
-         break;
-
-      if (i >= 0)
-       break;
-    }
+  Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section (output_bfd, osec);
 
-  return p - elf_tdata (output_bfd)->phdr;
+  return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1;
 }
 
 inline static bfd_boolean
index 6fbcd646ecd46443b7746ad94df71e257391c42f..b707345ba4b473f693c2f85124db5bab2c8a23e3 100644 (file)
@@ -3256,9 +3256,7 @@ elf32_hppa_final_link (bfd *abfd, struct bfd_link_info *info)
 /* Record the lowest address for the data and text segments.  */
 
 static void
-hppa_record_segment_addr (bfd *abfd,
-                         asection *section,
-                         void *data)
+hppa_record_segment_addr (bfd *abfd, asection *section, void *data)
 {
   struct elf32_hppa_link_hash_table *htab;
 
@@ -3266,8 +3264,12 @@ hppa_record_segment_addr (bfd *abfd,
 
   if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
     {
-      unsigned seg = elf_hppa_osec_to_segment (abfd, section->output_section);
-      bfd_vma value = elf_tdata (abfd)->phdr[seg].p_vaddr;
+      bfd_vma value;
+      Elf_Internal_Phdr *p;
+
+      p = _bfd_elf_find_segment_containing_section (abfd, section->output_section);
+      BFD_ASSERT (p != NULL);
+      value = p->p_vaddr;
 
       if ((section->flags & SEC_READONLY) != 0)
        {
index 5aa1a0ab3910710f27eb767b78b4293844c3f7ea..535b1bc23b1ecb3ec1269ab24832328a12a6fb4f 100644 (file)
@@ -4894,24 +4894,11 @@ elfNN_ia64_relocate_section (bfd *output_bfd,
        case R_IA64_SEGREL64MSB:
        case R_IA64_SEGREL64LSB:
            {
-             struct elf_segment_map *m;
-             Elf_Internal_Phdr *p;
-
              /* Find the segment that contains the output_section.  */
-             for (m = elf_tdata (output_bfd)->segment_map,
-                    p = elf_tdata (output_bfd)->phdr;
-                  m != NULL;
-                  m = m->next, p++)
-               {
-                 int i;
-                 for (i = m->count - 1; i >= 0; i--)
-                   if (m->sections[i] == input_section->output_section)
-                     break;
-                 if (i >= 0)
-                   break;
-               }
+             Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section
+               (input_bfd, input_section->output_section);
 
-             if (m == NULL)
+             if (p == NULL)
                {
                  r = bfd_reloc_notsupported;
                }