aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf64-ppc.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2014-06-13 19:11:39 +0930
committerAlan Modra <amodra@gmail.com>2014-06-13 19:11:39 +0930
commitd495ab0d843def702a6641fa4fc31708d7fc97b1 (patch)
treea16dc7d65d085eb532bcf044a358d737e252061e /bfd/elf64-ppc.c
parentcaa4096e844a000ff63c4fa9180d70ca2093fd2a (diff)
downloadgdb-d495ab0d843def702a6641fa4fc31708d7fc97b1.zip
gdb-d495ab0d843def702a6641fa4fc31708d7fc97b1.tar.gz
gdb-d495ab0d843def702a6641fa4fc31708d7fc97b1.tar.bz2
Free linker hash table from bfd_close.
Also tidies numerous error exit paths in various link_hash_table_create functions that failed to free memory. include/ * bfdlink.h (struct bfd_link_hash_table): Add hash_table_free field. bfd/ * archive.c: Include bfdlink.h. (_bfd_archive_close_and_cleanup): Call linker hash_table_free. * bfd.c (struct bfd): Add is_linker_output field. * elf-bfd.h (_bfd_elf_link_hash_table_free): Update prototype. * linker.c (_bfd_link_hash_table_init): Set up hash_table_free, link.hash and is_linker_output. (_bfd_generic_link_hash_table_free): Replace bfd_link_hash_table* param with bfd*. Assert is_linker_output and link.hash, and clear them before exit. * elf-m10300.c (elf32_mn10300_link_hash_table_free): Replace bfd_link_hash_table* param with bfd*. Hack is_linker_output and link.hash so we can free two linker hash tables. (elf32_mn10300_link_hash_table_create): Create static_hash_table first. Clean up on errors. Set hash_table_free pointer. * elf32-arm.c (elf32_arm_link_hash_table_free): Replace bfd_link_hash_table* param with bfd*. (elf32_arm_link_hash_table_create): Clean up on errors. Set hash_table_free pointer. * elf32-avr.c, * elf32-hppa.c, * elf32-i386.c, * elf32-m68hc1x.c, * elf32-m68k.c, * elf32-metag.c, * elf32-nios2.c, * elf32-xgate.c, * elf64-ia64-vms.c, * elf64-ppc.c, * elf64-x86-64.c, * elflink.c, * elfnn-aarch64.c, * elfnn-ia64.c, * elfxx-sparc.c, * xcofflink.c: Similarly. * simple.c (bfd_simple_get_relocated_section_contents): Save and clear link.next before creating linker hash table. Clean up on errors, and restore link.next on exit. * elf32-m68hc1x.h (m68hc11_elf_bfd_link_hash_table_free): Delete. * elf32-xgate.h (xgate_elf_bfd_link_hash_table_free): Delete. * elfxx-sparc.h (_bfd_sparc_elf_link_hash_table_free): Delete. * libcoff-in.h (_bfd_xcoff_bfd_link_hash_table_free): Delete. * hash.c (bfd_hash_table_init_n): Free table on error. * libbfd-in.h (_bfd_generic_link_hash_table_free): Update proto. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. * libcoff.h: Regenerate.
Diffstat (limited to 'bfd/elf64-ppc.c')
-rw-r--r--bfd/elf64-ppc.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index 581ce55..46cba68 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -4144,15 +4144,16 @@ tocsave_htab_eq (const void *p1, const void *p2)
/* Destroy a ppc64 ELF linker hash table. */
static void
-ppc64_elf_link_hash_table_free (struct bfd_link_hash_table *hash)
+ppc64_elf_link_hash_table_free (bfd *obfd)
{
- struct ppc_link_hash_table *htab = (struct ppc_link_hash_table *) hash;
+ struct ppc_link_hash_table *htab;
- bfd_hash_table_free (&htab->stub_hash_table);
- bfd_hash_table_free (&htab->branch_hash_table);
+ htab = (struct ppc_link_hash_table *) obfd->link.hash;
if (htab->tocsave_htab)
htab_delete (htab->tocsave_htab);
- _bfd_elf_link_hash_table_free (hash);
+ bfd_hash_table_free (&htab->branch_hash_table);
+ bfd_hash_table_free (&htab->stub_hash_table);
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Create a ppc64 ELF linker hash table. */
@@ -4179,7 +4180,7 @@ ppc64_elf_link_hash_table_create (bfd *abfd)
if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc,
sizeof (struct ppc_stub_hash_entry)))
{
- _bfd_elf_link_hash_table_free ((struct bfd_link_hash_table *) htab);
+ _bfd_elf_link_hash_table_free (abfd);
return NULL;
}
@@ -4188,7 +4189,7 @@ ppc64_elf_link_hash_table_create (bfd *abfd)
sizeof (struct ppc_branch_hash_entry)))
{
bfd_hash_table_free (&htab->stub_hash_table);
- _bfd_elf_link_hash_table_free ((struct bfd_link_hash_table *) htab);
+ _bfd_elf_link_hash_table_free (abfd);
return NULL;
}
@@ -4198,12 +4199,10 @@ ppc64_elf_link_hash_table_create (bfd *abfd)
NULL);
if (htab->tocsave_htab == NULL)
{
- bfd_hash_table_free (&htab->branch_hash_table);
- bfd_hash_table_free (&htab->stub_hash_table);
- _bfd_elf_link_hash_table_free ((struct bfd_link_hash_table *) htab);
+ ppc64_elf_link_hash_table_free (abfd);
return NULL;
}
- (void) ppc64_elf_link_hash_table_free;
+ htab->elf.root.hash_table_free = ppc64_elf_link_hash_table_free;
/* Initializing two fields of the union is just cosmetic. We really
only care about glist, but when compiled on a 32-bit host the