+2014-06-13 Alan Modra <amodra@gmail.com>
+
+ * 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.
+
2014-06-13 Alan Modra <amodra@gmail.com>
PR 17047
#include "safe-ctype.h"
#include "hashtab.h"
#include "filenames.h"
+#include "bfdlink.h"
#ifndef errno
extern int errno;
}
}
}
+ if (abfd->is_linker_output)
+ (*abfd->link.hash->hash_table_free) (abfd);
+
return TRUE;
}
/* Set if only required symbols should be added in the link hash table for
this object. Used by VMS linkers. */
unsigned int selective_search : 1;
+
+ /* Set if this is the linker output BFD. */
+ unsigned int is_linker_output : 1;
};
/* See note beside bfd_set_section_userdata. */
. {* Set if only required symbols should be added in the link hash table for
. this object. Used by VMS linkers. *}
. unsigned int selective_search : 1;
+.
+. {* Set if this is the linker output BFD. *}
+. unsigned int is_linker_output : 1;
.};
.
.{* See note beside bfd_set_section_userdata. *}
extern struct bfd_link_hash_table *_bfd_elf_link_hash_table_create
(bfd *);
extern void _bfd_elf_link_hash_table_free
- (struct bfd_link_hash_table *);
+ (bfd *);
extern void _bfd_elf_link_hash_copy_indirect
(struct bfd_link_info *, struct elf_link_hash_entry *,
struct elf_link_hash_entry *);
/* Destroy an mn10300 ELF linker hash table. */
static void
-elf32_mn10300_link_hash_table_free (struct bfd_link_hash_table *hash)
+elf32_mn10300_link_hash_table_free (bfd *obfd)
{
struct elf32_mn10300_link_hash_table *ret
- = (struct elf32_mn10300_link_hash_table *) hash;
+ = (struct elf32_mn10300_link_hash_table *) obfd->link.hash;
- _bfd_elf_link_hash_table_free
- ((struct bfd_link_hash_table *) ret->static_hash_table);
- _bfd_elf_link_hash_table_free
- ((struct bfd_link_hash_table *) ret);
+ obfd->link.hash = &ret->static_hash_table->root.root;
+ _bfd_elf_link_hash_table_free (obfd);
+ obfd->is_linker_output = TRUE;
+ obfd->link.hash = &ret->root.root;
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Create an mn10300 ELF linker hash table. */
if (ret == NULL)
return NULL;
- if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
- elf32_mn10300_link_hash_newfunc,
- sizeof (struct elf32_mn10300_link_hash_entry),
- MN10300_ELF_DATA))
- {
- free (ret);
- return NULL;
- }
-
- ret->tls_ldm_got.offset = -1;
-
amt = sizeof (struct elf_link_hash_table);
ret->static_hash_table = bfd_zmalloc (amt);
if (ret->static_hash_table == NULL)
free (ret);
return NULL;
}
- (void) elf32_mn10300_link_hash_table_free;
+
+ abfd->is_linker_output = FALSE;
+ abfd->link.hash = NULL;
+ if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
+ elf32_mn10300_link_hash_newfunc,
+ sizeof (struct elf32_mn10300_link_hash_entry),
+ MN10300_ELF_DATA))
+ {
+ abfd->is_linker_output = TRUE;
+ abfd->link.hash = &ret->static_hash_table->root.root;
+ _bfd_elf_link_hash_table_free (abfd);
+ free (ret);
+ return NULL;
+ }
+ ret->root.root.hash_table_free = elf32_mn10300_link_hash_table_free;
+
+ ret->tls_ldm_got.offset = -1;
+
return & ret->root.root;
}
/* Destroy an ARM elf linker hash table. */
static void
-elf32_arm_link_hash_table_free (struct bfd_link_hash_table *hash)
+elf32_arm_link_hash_table_free (bfd *obfd)
{
struct elf32_arm_link_hash_table *ret
- = (struct elf32_arm_link_hash_table *) hash;
+ = (struct elf32_arm_link_hash_table *) obfd->link.hash;
bfd_hash_table_free (&ret->stub_hash_table);
- _bfd_elf_link_hash_table_free (hash);
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Create an ARM elf linker hash table. */
if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
sizeof (struct elf32_arm_stub_hash_entry)))
{
- free (ret);
+ _bfd_elf_link_hash_table_free (abfd);
return NULL;
}
- (void) elf32_arm_link_hash_table_free;
+ ret->root.root.hash_table_free = elf32_arm_link_hash_table_free;
return &ret->root.root;
}
/* Free the derived linker hash table. */
static void
-elf32_avr_link_hash_table_free (struct bfd_link_hash_table *btab)
+elf32_avr_link_hash_table_free (bfd *obfd)
{
struct elf32_avr_link_hash_table *htab
- = (struct elf32_avr_link_hash_table *) btab;
+ = (struct elf32_avr_link_hash_table *) obfd->link.hash;
/* Free the address mapping table. */
if (htab->amt_stub_offsets != NULL)
free (htab->amt_destination_addr);
bfd_hash_table_free (&htab->bstab);
- _bfd_elf_link_hash_table_free (btab);
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Create the derived linker hash table. The AVR ELF port uses the derived
/* Init the stub hash table too. */
if (!bfd_hash_table_init (&htab->bstab, stub_hash_newfunc,
sizeof (struct elf32_avr_stub_hash_entry)))
- return NULL;
- (void) elf32_avr_link_hash_table_free;
+ {
+ _bfd_elf_link_hash_table_free (abfd);
+ return NULL;
+ }
+ htab->etab.root.hash_table_free = elf32_avr_link_hash_table_free;
return &htab->etab.root;
}
/* Free the derived linker hash table. */
static void
-elf32_hppa_link_hash_table_free (struct bfd_link_hash_table *btab)
+elf32_hppa_link_hash_table_free (bfd *obfd)
{
struct elf32_hppa_link_hash_table *htab
- = (struct elf32_hppa_link_hash_table *) btab;
+ = (struct elf32_hppa_link_hash_table *) obfd->link.hash;
bfd_hash_table_free (&htab->bstab);
- _bfd_elf_link_hash_table_free (btab);
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Create the derived linker hash table. The PA ELF port uses the derived
/* Init the stub hash table too. */
if (!bfd_hash_table_init (&htab->bstab, stub_hash_newfunc,
sizeof (struct elf32_hppa_stub_hash_entry)))
- return NULL;
- (void) elf32_hppa_link_hash_table_free;
+ {
+ _bfd_elf_link_hash_table_free (abfd);
+ return NULL;
+ }
+ htab->etab.root.hash_table_free = elf32_hppa_link_hash_table_free;
htab->text_segment_base = (bfd_vma) -1;
htab->data_segment_base = (bfd_vma) -1;
/* Destroy an i386 ELF linker hash table. */
static void
-elf_i386_link_hash_table_free (struct bfd_link_hash_table *hash)
+elf_i386_link_hash_table_free (bfd *obfd)
{
struct elf_i386_link_hash_table *htab
- = (struct elf_i386_link_hash_table *) hash;
+ = (struct elf_i386_link_hash_table *) obfd->link.hash;
if (htab->loc_hash_table)
htab_delete (htab->loc_hash_table);
if (htab->loc_hash_memory)
objalloc_free ((struct objalloc *) htab->loc_hash_memory);
- _bfd_elf_link_hash_table_free (hash);
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Create an i386 ELF linker hash table. */
ret->loc_hash_memory = objalloc_create ();
if (!ret->loc_hash_table || !ret->loc_hash_memory)
{
- free (ret);
+ elf_i386_link_hash_table_free (abfd);
return NULL;
}
- (void) elf_i386_link_hash_table_free;
+ ret->elf.root.hash_table_free = elf_i386_link_hash_table_free;
return &ret->elf.root;
}
/* Destroy a 68HC11/68HC12 ELF linker hash table. */
-void
-m68hc11_elf_bfd_link_hash_table_free (struct bfd_link_hash_table *hash)
+static void
+m68hc11_elf_bfd_link_hash_table_free (bfd *obfd)
{
struct m68hc11_elf_link_hash_table *ret
- = (struct m68hc11_elf_link_hash_table *) hash;
+ = (struct m68hc11_elf_link_hash_table *) obfd->link.hash;
bfd_hash_table_free (ret->stub_hash_table);
free (ret->stub_hash_table);
- _bfd_elf_link_hash_table_free (hash);
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Create a 68HC11/68HC12 ELF linker hash table. */
ret->stub_hash_table = (struct bfd_hash_table*) bfd_malloc (amt);
if (ret->stub_hash_table == NULL)
{
- free (ret);
+ _bfd_elf_link_hash_table_free (abfd);
return NULL;
}
if (!bfd_hash_table_init (ret->stub_hash_table, stub_hash_newfunc,
sizeof (struct elf32_m68hc11_stub_hash_entry)))
- return NULL;
+ {
+ free (ret->stub_hash_table);
+ _bfd_elf_link_hash_table_free (abfd);
+ return NULL;
+ }
+ ret->root.root.hash_table_free = m68hc11_elf_bfd_link_hash_table_free;
return ret;
}
extern struct m68hc11_elf_link_hash_table* m68hc11_elf_hash_table_create
(bfd*);
-extern void m68hc11_elf_bfd_link_hash_table_free (struct bfd_link_hash_table*);
extern void m68hc11_elf_get_bank_parameters (struct bfd_link_info*);
/* Destroy an m68k ELF linker hash table. */
static void
-elf_m68k_link_hash_table_free (struct bfd_link_hash_table *_htab)
+elf_m68k_link_hash_table_free (bfd *obfd)
{
struct elf_m68k_link_hash_table *htab;
- htab = (struct elf_m68k_link_hash_table *) _htab;
+ htab = (struct elf_m68k_link_hash_table *) obfd->link.hash;
if (htab->multi_got_.bfd2got != NULL)
{
htab_delete (htab->multi_got_.bfd2got);
htab->multi_got_.bfd2got = NULL;
}
- _bfd_elf_link_hash_table_free (_htab);
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Create an m68k ELF linker hash table. */
free (ret);
return NULL;
}
- (void) elf_m68k_link_hash_table_free;
+ ret->root.root.hash_table_free = elf_m68k_link_hash_table_free;
ret->multi_got_.global_symndx = 1;
/* Free the derived linker hash table. */
static void
-elf_metag_link_hash_table_free (struct bfd_link_hash_table *btab)
+elf_metag_link_hash_table_free (bfd *obfd)
{
struct elf_metag_link_hash_table *htab
- = (struct elf_metag_link_hash_table *) btab;
+ = (struct elf_metag_link_hash_table *) obfd->link.hash;
bfd_hash_table_free (&htab->bstab);
- _bfd_elf_link_hash_table_free (btab);
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Create the derived linker hash table. The Meta ELF port uses the derived
/* Init the stub hash table too. */
if (!bfd_hash_table_init (&htab->bstab, stub_hash_newfunc,
sizeof (struct elf_metag_stub_hash_entry)))
- return NULL;
- (void) elf_metag_link_hash_table_free;
+ {
+ _bfd_elf_link_hash_table_free (abfd);
+ return NULL;
+ }
+ htab->etab.root.hash_table_free = elf_metag_link_hash_table_free;
return &htab->etab.root;
}
/* Free the derived linker hash table. */
static void
-nios2_elf32_link_hash_table_free (struct bfd_link_hash_table *btab)
+nios2_elf32_link_hash_table_free (bfd *obfd)
{
struct elf32_nios2_link_hash_table *htab
- = (struct elf32_nios2_link_hash_table *) btab;
+ = (struct elf32_nios2_link_hash_table *) obfd->link.hash;
bfd_hash_table_free (&htab->bstab);
- _bfd_elf_link_hash_table_free (btab);
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Implement bfd_elf32_bfd_link_hash_table_create. */
/* Init the stub hash table too. */
if (!bfd_hash_table_init (&ret->bstab, stub_hash_newfunc,
sizeof (struct elf32_nios2_stub_hash_entry)))
- return NULL;
- (void) nios2_elf32_link_hash_table_free;
+ {
+ _bfd_elf_link_hash_table_free (abfd);
+ return NULL;
+ }
+ ret->root.root.hash_table_free = nios2_elf32_link_hash_table_free;
return &ret->root.root;
}
cache_ptr->howto = &elf_xgate_howto_table[r_type];
}
-/* Free the derived linker hash table. */
+/* Destroy an XGATE ELF linker hash table. */
-void
-xgate_elf_bfd_link_hash_table_free (struct bfd_link_hash_table *hash)
+static void
+xgate_elf_bfd_link_hash_table_free (bfd *obfd)
{
struct xgate_elf_link_hash_table *ret =
- (struct xgate_elf_link_hash_table *) hash;
+ (struct xgate_elf_link_hash_table *) obfd->link.hash;
bfd_hash_table_free (ret->stub_hash_table);
free (ret->stub_hash_table);
- _bfd_elf_link_hash_table_free (hash);
+ _bfd_elf_link_hash_table_free (obfd);
}
-/* Create a XGATE ELF linker hash table. */
+/* Create an XGATE ELF linker hash table. */
static struct bfd_link_hash_table*
xgate_elf_bfd_link_hash_table_create (bfd *abfd)
ret->stub_hash_table = (struct bfd_hash_table*) bfd_zmalloc (amt);
if (ret->stub_hash_table == NULL)
{
- free (ret);
+ _bfd_elf_link_hash_table_free (abfd);
return NULL;
}
sizeof(struct elf32_xgate_stub_hash_entry)))
{
free (ret->stub_hash_table);
- free (ret);
+ _bfd_elf_link_hash_table_free (abfd);
return NULL;
}
+ ret->root.root.hash_table_free = xgate_elf_bfd_link_hash_table_free;
return &ret->root.root;
}
extern struct xgate_elf_link_hash_table* xgate_elf_hash_table_create
(bfd *);
-extern void xgate_elf_bfd_link_hash_table_free (struct bfd_link_hash_table *);
extern void xgate_elf_get_bank_parameters (struct bfd_link_info *);
/* Destroy IA-64 linker hash table. */
static void
-elf64_ia64_link_hash_table_free (struct bfd_link_hash_table *hash)
+elf64_ia64_link_hash_table_free (bfd *obfd)
{
struct elf64_ia64_link_hash_table *ia64_info
- = (struct elf64_ia64_link_hash_table *) hash;
+ = (struct elf64_ia64_link_hash_table *) obfd->link.hash;
if (ia64_info->loc_hash_table)
{
htab_traverse (ia64_info->loc_hash_table,
objalloc_free ((struct objalloc *) ia64_info->loc_hash_memory);
elf_link_hash_traverse (&ia64_info->root,
elf64_ia64_global_dyn_info_free, NULL);
- _bfd_elf_link_hash_table_free (hash);
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Create the derived linker hash table. The IA-64 ELF port uses this
ret->loc_hash_memory = objalloc_create ();
if (!ret->loc_hash_table || !ret->loc_hash_memory)
{
- free (ret);
+ elf64_ia64_link_hash_table_free (abfd);
return NULL;
}
- (void) elf64_ia64_link_hash_table_free;
+ ret->root.root.hash_table_free = elf64_ia64_link_hash_table_free;
return &ret->root.root;
}
/* 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. */
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;
}
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;
}
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
/* Destroy an X86-64 ELF linker hash table. */
static void
-elf_x86_64_link_hash_table_free (struct bfd_link_hash_table *hash)
+elf_x86_64_link_hash_table_free (bfd *obfd)
{
struct elf_x86_64_link_hash_table *htab
- = (struct elf_x86_64_link_hash_table *) hash;
+ = (struct elf_x86_64_link_hash_table *) obfd->link.hash;
if (htab->loc_hash_table)
htab_delete (htab->loc_hash_table);
if (htab->loc_hash_memory)
objalloc_free ((struct objalloc *) htab->loc_hash_memory);
- _bfd_elf_link_hash_table_free (hash);
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Create an X86-64 ELF linker hash table. */
ret->loc_hash_memory = objalloc_create ();
if (!ret->loc_hash_table || !ret->loc_hash_memory)
{
- free (ret);
+ elf_x86_64_link_hash_table_free (abfd);
return NULL;
}
- (void) elf_x86_64_link_hash_table_free;
+ ret->elf.root.hash_table_free = elf_x86_64_link_hash_table_free;
return &ret->elf.root;
}
free (ret);
return NULL;
}
+ ret->root.hash_table_free = _bfd_elf_link_hash_table_free;
return &ret->root;
}
/* Destroy an ELF linker hash table. */
void
-_bfd_elf_link_hash_table_free (struct bfd_link_hash_table *hash)
+_bfd_elf_link_hash_table_free (bfd *obfd)
{
- struct elf_link_hash_table *htab = (struct elf_link_hash_table *) hash;
+ struct elf_link_hash_table *htab;
+
+ htab = (struct elf_link_hash_table *) obfd->link.hash;
if (htab->dynstr != NULL)
_bfd_elf_strtab_free (htab->dynstr);
_bfd_merge_sections_free (htab->merge_info);
- _bfd_generic_link_hash_table_free (hash);
+ _bfd_generic_link_hash_table_free (obfd);
}
/* This is a hook for the ELF emulation code in the generic linker to
/* Destroy an AArch64 elf linker hash table. */
static void
-elfNN_aarch64_link_hash_table_free (struct bfd_link_hash_table *hash)
+elfNN_aarch64_link_hash_table_free (bfd *obfd)
{
struct elf_aarch64_link_hash_table *ret
- = (struct elf_aarch64_link_hash_table *) hash;
+ = (struct elf_aarch64_link_hash_table *) obfd->link.hash;
if (ret->loc_hash_table)
htab_delete (ret->loc_hash_table);
objalloc_free ((struct objalloc *) ret->loc_hash_memory);
bfd_hash_table_free (&ret->stub_hash_table);
- _bfd_elf_link_hash_table_free (hash);
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Create an AArch64 elf linker hash table. */
if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
sizeof (struct elf_aarch64_stub_hash_entry)))
{
- free (ret);
+ _bfd_elf_link_hash_table_free (abfd);
return NULL;
}
ret->loc_hash_memory = objalloc_create ();
if (!ret->loc_hash_table || !ret->loc_hash_memory)
{
- free (ret);
+ elfNN_aarch64_link_hash_table_free (abfd);
return NULL;
}
- (void) elfNN_aarch64_link_hash_table_free;
+ ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free;
return &ret->root.root;
}
/* Destroy IA-64 linker hash table. */
static void
-elfNN_ia64_link_hash_table_free (struct bfd_link_hash_table *hash)
+elfNN_ia64_link_hash_table_free (bfd *obfd)
{
struct elfNN_ia64_link_hash_table *ia64_info
- = (struct elfNN_ia64_link_hash_table *) hash;
+ = (struct elfNN_ia64_link_hash_table *) obfd->link.hash;
if (ia64_info->loc_hash_table)
{
htab_traverse (ia64_info->loc_hash_table,
objalloc_free ((struct objalloc *) ia64_info->loc_hash_memory);
elf_link_hash_traverse (&ia64_info->root,
elfNN_ia64_global_dyn_info_free, NULL);
- _bfd_elf_link_hash_table_free (hash);
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Create the derived linker hash table. The IA-64 ELF port uses this
ret->loc_hash_memory = objalloc_create ();
if (!ret->loc_hash_table || !ret->loc_hash_memory)
{
- free (ret);
+ elfNN_ia64_link_hash_table_free (abfd);
return NULL;
}
- (void) elfNN_ia64_link_hash_table_free;
+ ret->root.root.hash_table_free = elfNN_ia64_link_hash_table_free;
return &ret->root.root;
}
/* Destroy a SPARC ELF linker hash table. */
-void
-_bfd_sparc_elf_link_hash_table_free (struct bfd_link_hash_table *hash)
+static void
+_bfd_sparc_elf_link_hash_table_free (bfd *obfd)
{
struct _bfd_sparc_elf_link_hash_table *htab
- = (struct _bfd_sparc_elf_link_hash_table *) hash;
+ = (struct _bfd_sparc_elf_link_hash_table *) obfd->link.hash;
if (htab->loc_hash_table)
htab_delete (htab->loc_hash_table);
if (htab->loc_hash_memory)
objalloc_free ((struct objalloc *) htab->loc_hash_memory);
- _bfd_generic_link_hash_table_free (hash);
+ _bfd_elf_link_hash_table_free (obfd);
}
/* Create a SPARC ELF linker hash table. */
ret->loc_hash_memory = objalloc_create ();
if (!ret->loc_hash_table || !ret->loc_hash_memory)
{
- free (ret);
+ _bfd_sparc_elf_link_hash_table_free (abfd);
return NULL;
}
+ ret->elf.root.hash_table_free = _bfd_sparc_elf_link_hash_table_free;
return &ret->elf.root;
}
(bfd *);
extern struct bfd_link_hash_table *_bfd_sparc_elf_link_hash_table_create
(bfd *);
-extern void _bfd_sparc_elf_link_hash_table_free
- (struct bfd_link_hash_table *);
extern bfd_boolean _bfd_sparc_elf_create_dynamic_sections
(bfd *, struct bfd_link_info *);
extern void _bfd_sparc_elf_copy_indirect_symbol
objalloc_alloc ((struct objalloc *) table->memory, alloc);
if (table->table == NULL)
{
+ bfd_hash_table_free (table);
bfd_set_error (bfd_error_no_memory);
return FALSE;
}
/* Generic link hash table destruction routine. */
extern void _bfd_generic_link_hash_table_free
- (struct bfd_link_hash_table *);
+ (bfd *);
/* Generic add symbol routine. */
extern bfd_boolean _bfd_generic_link_add_symbols
/* Generic link hash table destruction routine. */
extern void _bfd_generic_link_hash_table_free
- (struct bfd_link_hash_table *);
+ (bfd *);
/* Generic add symbol routine. */
extern bfd_boolean _bfd_generic_link_add_symbols
(bfd *, arelent **, asymbol **);
extern struct bfd_link_hash_table *_bfd_xcoff_bfd_link_hash_table_create
(bfd *);
-extern void _bfd_xcoff_bfd_link_hash_table_free
- (struct bfd_link_hash_table *);
extern bfd_boolean _bfd_xcoff_bfd_link_add_symbols
(bfd *, struct bfd_link_info *);
extern bfd_boolean _bfd_xcoff_bfd_final_link
(bfd *, arelent **, asymbol **);
extern struct bfd_link_hash_table *_bfd_xcoff_bfd_link_hash_table_create
(bfd *);
-extern void _bfd_xcoff_bfd_link_hash_table_free
- (struct bfd_link_hash_table *);
extern bfd_boolean _bfd_xcoff_bfd_link_add_symbols
(bfd *, struct bfd_link_info *);
extern bfd_boolean _bfd_xcoff_bfd_final_link
const char *),
unsigned int entsize)
{
+ bfd_boolean ret;
+
+ BFD_ASSERT (!abfd->is_linker_output && !abfd->link.hash);
table->undefs = NULL;
table->undefs_tail = NULL;
table->type = bfd_link_generic_hash_table;
- return bfd_hash_table_init (&table->table, newfunc, entsize);
+ ret = bfd_hash_table_init (&table->table, newfunc, entsize);
+ if (ret)
+ {
+ /* Arrange for destruction of this hash table on closing ABFD. */
+ table->hash_table_free = _bfd_generic_link_hash_table_free;
+ abfd->link.hash = table;
+ abfd->is_linker_output = TRUE;
+ }
+ return ret;
}
/* Look up a symbol in a link hash table. If follow is TRUE, we
}
void
-_bfd_generic_link_hash_table_free (struct bfd_link_hash_table *hash)
+_bfd_generic_link_hash_table_free (bfd *obfd)
{
- struct generic_link_hash_table *ret
- = (struct generic_link_hash_table *) hash;
+ struct generic_link_hash_table *ret;
+ BFD_ASSERT (obfd->is_linker_output && obfd->link.hash);
+ ret = (struct generic_link_hash_table *) obfd->link.hash;
bfd_hash_table_free (&ret->root.table);
free (ret);
+ obfd->link.hash = NULL;
+ obfd->is_linker_output = FALSE;
}
/* Grab the symbols for an object file when doing a generic link. We
bfd_byte *contents, *data;
int storage_needed;
struct saved_offsets saved_offsets;
+ bfd *link_next;
/* Don't apply relocation on executable and shared library. See
PR 4756. */
link_info.input_bfds = abfd;
link_info.input_bfds_tail = &abfd->link.next;
+ link_next = abfd->link.next;
+ abfd->link.next = NULL;
link_info.hash = _bfd_generic_link_hash_table_create (abfd);
link_info.callbacks = &callbacks;
callbacks.warning = simple_dummy_warning;
bfd_size_type amt = sec->rawsize > sec->size ? sec->rawsize : sec->size;
data = (bfd_byte *) bfd_malloc (amt);
if (data == NULL)
- return NULL;
+ {
+ _bfd_generic_link_hash_table_free (abfd);
+ abfd->link.next = link_next;
+ return NULL;
+ }
outbuf = data;
}
{
if (data)
free (data);
+ _bfd_generic_link_hash_table_free (abfd);
+ abfd->link.next = link_next;
return NULL;
}
bfd_map_over_sections (abfd, simple_save_output_info, &saved_offsets);
bfd_map_over_sections (abfd, simple_restore_output_info, &saved_offsets);
free (saved_offsets.sections);
- _bfd_generic_link_hash_table_free (link_info.hash);
+ _bfd_generic_link_hash_table_free (abfd);
+ abfd->link.next = link_next;
return contents;
}
/* Destroy an XCOFF link hash table. */
-void
-_bfd_xcoff_bfd_link_hash_table_free (struct bfd_link_hash_table *hash)
+static void
+_bfd_xcoff_bfd_link_hash_table_free (bfd *obfd)
{
- struct xcoff_link_hash_table *ret = (struct xcoff_link_hash_table *) hash;
+ struct xcoff_link_hash_table *ret;
- _bfd_stringtab_free (ret->debug_strtab);
- bfd_hash_table_free (&ret->root.table);
- free (ret);
+ ret = (struct xcoff_link_hash_table *) obfd->link.hash;
+ if (ret->archive_info)
+ htab_delete (ret->archive_info);
+ if (ret->debug_strtab)
+ _bfd_stringtab_free (ret->debug_strtab);
+ _bfd_generic_link_hash_table_free (obfd);
}
/* Create an XCOFF link hash table. */
ret->debug_strtab = _bfd_xcoff_stringtab_init ();
ret->archive_info = htab_create (37, xcoff_archive_info_hash,
xcoff_archive_info_eq, NULL);
+ if (!ret->debug_strtab || !ret->archive_info)
+ {
+ _bfd_xcoff_bfd_link_hash_table_free (abfd);
+ return NULL;
+ }
+ ret->root.hash_table_free = _bfd_xcoff_bfd_link_hash_table_free;
/* The linker will always generate a full a.out header. We need to
record that fact now, before the sizeof_headers routine could be
+2014-06-13 Alan Modra <amodra@gmail.com>
+
+ * bfdlink.h (struct bfd_link_hash_table): Add hash_table_free field.
+
2014-06-13 Alan Modra <amodra@gmail.com>
* bfdlink.h: Update for bfd.link_next change.
struct bfd_link_hash_entry *undefs;
/* Entries are added to the tail of the undefs list. */
struct bfd_link_hash_entry *undefs_tail;
+ /* Function to free the hash table on closing BFD. */
+ void (*hash_table_free) (bfd *);
/* The type of the link hash table. */
enum bfd_link_hash_table_type type;
};