Based on patch from H.J. Lu <hjl@gnu.org>:
authorIan Lance Taylor <ian@airs.com>
Mon, 27 Apr 1998 15:51:27 +0000 (15:51 +0000)
committerIan Lance Taylor <ian@airs.com>
Mon, 27 Apr 1998 15:51:27 +0000 (15:51 +0000)
* elf.c (bfd_elf_get_bfd_needed_list): New function.
* bfd-in.h (bfd_elf_get_bfd_needed_list): Declare.
* bfd-in2.h: Rebuild.

bfd/ChangeLog
bfd/elf.c

index 7aba8da29a5cce9496a80f90368d9bb2d17ace47..5935da6bea44503548bfdfd0abe151f0485222a1 100644 (file)
@@ -1,3 +1,10 @@
+Mon Apr 27 11:49:55 1998  Ian Lance Taylor  <ian@cygnus.com>
+
+       Based on patch from H.J. Lu <hjl@gnu.org>:
+       * elf.c (bfd_elf_get_bfd_needed_list): New function.
+       * bfd-in.h (bfd_elf_get_bfd_needed_list): Declare.
+       * bfd-in2.h: Rebuild.
+
 Sat Apr 25 20:07:53 1998  Richard Henderson  <rth@cygnus.com>
 
        * elf64-alpha.c (struct alpha_relax_info): Replace elfsym with other.
index 166769a0ba87b51f1682ff2e04fc006123117dcf..bb62b2ba052613de997135220a597d453e319245 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -916,7 +916,7 @@ bfd_elf_set_dt_needed_name (abfd, name)
 }
 
 /* Get the list of DT_NEEDED entries for a link.  This is a hook for
-   the ELF emulation code.  */
+   the linker ELF emulation code.  */
 
 struct bfd_link_needed_list *
 bfd_elf_get_needed_list (abfd, info)
@@ -941,6 +941,91 @@ bfd_elf_get_dt_soname (abfd)
     return elf_dt_name (abfd);
   return NULL;
 }
+
+/* Get the list of DT_NEEDED entries from a BFD.  This is a hook for
+   the ELF linker emulation code.  */
+
+boolean
+bfd_elf_get_bfd_needed_list (abfd, pneeded)
+     bfd *abfd;
+     struct bfd_link_needed_list **pneeded;
+{
+  asection *s;
+  bfd_byte *dynbuf = NULL;
+  int elfsec;
+  unsigned long link;
+  bfd_byte *extdyn, *extdynend;
+  size_t extdynsize;
+  void (*swap_dyn_in) PARAMS ((bfd *, const PTR, Elf_Internal_Dyn *));
+
+  *pneeded = NULL;
+
+  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour
+      || bfd_get_format (abfd) != bfd_object)
+    return true;
+
+  s = bfd_get_section_by_name (abfd, ".dynamic");
+  if (s == NULL || s->_raw_size == 0)
+    return true;
+
+  dynbuf = (bfd_byte *) bfd_malloc (s->_raw_size);
+  if (dynbuf == NULL)
+    goto error_return;
+
+  if (! bfd_get_section_contents (abfd, s, (PTR) dynbuf, (file_ptr) 0,
+                                 s->_raw_size))
+    goto error_return;
+
+  elfsec = _bfd_elf_section_from_bfd_section (abfd, s);
+  if (elfsec == -1)
+    goto error_return;
+
+  link = elf_elfsections (abfd)[elfsec]->sh_link;
+
+  extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
+  swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in;
+
+  extdyn = dynbuf;
+  extdynend = extdyn + s->_raw_size;
+  for (; extdyn < extdynend; extdyn += extdynsize)
+    {
+      Elf_Internal_Dyn dyn;
+
+      (*swap_dyn_in) (abfd, (PTR) extdyn, &dyn);
+
+      if (dyn.d_tag == DT_NULL)
+       break;
+
+      if (dyn.d_tag == DT_NEEDED)
+       {
+         const char *string;
+         struct bfd_link_needed_list *l;
+
+         string = bfd_elf_string_from_elf_section (abfd, link,
+                                                   dyn.d_un.d_val);
+         if (string == NULL)
+           goto error_return;
+
+         l = (struct bfd_link_needed_list *) bfd_alloc (abfd, sizeof *l);
+         if (l == NULL)
+           goto error_return;
+
+         l->by = abfd;
+         l->name = string;
+         l->next = *pneeded;
+         *pneeded = l;
+       }
+    }
+
+  free (dynbuf);
+
+  return true;
+
+ error_return:
+  if (dynbuf != NULL)
+    free (dynbuf);
+  return false;
+}
 \f
 /* Allocate an ELF string table--force the first byte to be zero.  */