From 0d3887ba8f5ac936b40c98099814398bf78b4147 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 27 Apr 1998 15:51:27 +0000 Subject: [PATCH] Based on patch from H.J. Lu : * 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 | 7 +++++ bfd/elf.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 7aba8da29a5..5935da6bea4 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +Mon Apr 27 11:49:55 1998 Ian Lance Taylor + + Based on patch from H.J. Lu : + * 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 * elf64-alpha.c (struct alpha_relax_info): Replace elfsym with other. diff --git a/bfd/elf.c b/bfd/elf.c index 166769a0ba8..bb62b2ba052 100644 --- 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; +} /* Allocate an ELF string table--force the first byte to be zero. */ -- 2.30.2