summaryrefslogtreecommitdiff
path: root/bfd/elflink.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@bigpond.net.au>2013-02-11 05:30:52 +0000
committerAlan Modra <amodra@bigpond.net.au>2013-02-11 05:30:52 +0000
commitc756b971bc0938e4270912f3d87fb1da13fd1567 (patch)
tree11efb7bbfab7a5593bb556ea12e867a3b9d8f885 /bfd/elflink.c
parent48e86e30dec0e1e70c071c16fd93bd07d2afec94 (diff)
downloadbinutils-redhat-c756b971bc0938e4270912f3d87fb1da13fd1567.tar.gz
* elfcode.h (elf_checksum_contents): Free contents.
* elf-bfd.h (_bfd_elf_link_hash_table_free): Declare. * elflink.c (_bfd_elf_link_hash_table_free): New function. (elf_final_link_free): New function, extracted from.. (bfd_elf_final_link): ..here. Always call _bfd_elf_write_section_eh_frame_hdr. * elfxx-target.h (bfd_elfNN_bfd_link_hash_table_free): Default to _bfd_elf_link_hash_table_free. * libbfd-in.h (_bfd_merge_sections_free): Declare. * libbfd.h: Regenerate. * merge.c (_bfd_merge_sections_free): New function. * elf-eh-frame.c (_bfd_elf_write_section_eh_frame_hdr): Free hdr_info->array. * elf-m10300.c (elf32_mn10300_link_hash_table_free): Call _bfd_elf_link_hash_table_free. * elf32-arm.c (elf32_arm_link_hash_table_free): Likewise. * elf32-avr.c (elf32_avr_link_hash_table_free): Likewise. * elf32-hppa.c (elf32_hppa_link_hash_table_free): Likewise. * elf32-i386.c (elf_i386_link_hash_table_free): Likewise. * elf32-m68hc1x.c (m68hc11_elf_hash_table_free): Likewise. * elf32-m68k.c (elf_m68k_link_hash_table_free): Likewise. * elf32-metag.c (elf_metag_link_hash_table_free): Likewise. * elf32-xgate.c (xgate_elf_bfd_link_hash_table_free): Likewise. * elf64-aarch64.c (elf64_aarch64_link_hash_table_free): Likewise. * elf64-ia64-vms.c (elf64_ia64_hash_table_free): Likewise. * elf64-ppc.c (ppc64_elf_link_hash_table_free): Likewise. * elf64-x86-64.c (elf_x86_64_link_hash_table_free): Likewise. * elfnn-ia64.c (elfNN_ia64_hash_table_free): Likewise. * elf32-cr16.c (elf32_cr16_link_hash_table_free): Delete. (bfd_elf32_bfd_link_hash_table_free): Don't define. * elf32-tic6x.c (elf32_tic6x_link_hash_table_free): Delete. (bfd_elf32_bfd_link_hash_table_free): Dont' define.
Diffstat (limited to 'bfd/elflink.c')
-rw-r--r--bfd/elflink.c118
1 files changed, 52 insertions, 66 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 1bae437fc3..d423ca41a2 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -6962,6 +6962,18 @@ _bfd_elf_link_hash_table_create (bfd *abfd)
return &ret->root;
}
+/* Destroy an ELF linker hash table. */
+
+void
+_bfd_elf_link_hash_table_free (struct bfd_link_hash_table *hash)
+{
+ struct elf_link_hash_table *htab = (struct elf_link_hash_table *) 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);
+}
+
/* This is a hook for the ELF emulation code in the generic linker to
tell the backend linker what file name to use for the DT_NEEDED
entry for a dynamic object. */
@@ -10432,6 +10444,42 @@ elf_fixup_link_order (bfd *abfd, asection *o)
return TRUE;
}
+static void
+elf_final_link_free (bfd *obfd, struct elf_final_link_info *flinfo)
+{
+ asection *o;
+
+ if (flinfo->symstrtab != NULL)
+ _bfd_stringtab_free (flinfo->symstrtab);
+ if (flinfo->contents != NULL)
+ free (flinfo->contents);
+ if (flinfo->external_relocs != NULL)
+ free (flinfo->external_relocs);
+ if (flinfo->internal_relocs != NULL)
+ free (flinfo->internal_relocs);
+ if (flinfo->external_syms != NULL)
+ free (flinfo->external_syms);
+ if (flinfo->locsym_shndx != NULL)
+ free (flinfo->locsym_shndx);
+ if (flinfo->internal_syms != NULL)
+ free (flinfo->internal_syms);
+ if (flinfo->indices != NULL)
+ free (flinfo->indices);
+ if (flinfo->sections != NULL)
+ free (flinfo->sections);
+ if (flinfo->symbuf != NULL)
+ free (flinfo->symbuf);
+ if (flinfo->symshndxbuf != NULL)
+ free (flinfo->symshndxbuf);
+ for (o = obfd->sections; o != NULL; o = o->next)
+ {
+ struct bfd_elf_section_data *esdo = elf_section_data (o);
+ if ((o->flags & SEC_RELOC) != 0 && esdo->rel.hashes != NULL)
+ free (esdo->rel.hashes);
+ if ((o->flags & SEC_RELOC) != 0 && esdo->rela.hashes != NULL)
+ free (esdo->rela.hashes);
+ }
+}
/* Do the final step of an ELF link. */
@@ -11479,42 +11527,10 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
goto error_return;
}
- if (info->eh_frame_hdr)
- {
- if (! _bfd_elf_write_section_eh_frame_hdr (abfd, info))
- goto error_return;
- }
+ if (! _bfd_elf_write_section_eh_frame_hdr (abfd, info))
+ goto error_return;
- if (flinfo.symstrtab != NULL)
- _bfd_stringtab_free (flinfo.symstrtab);
- if (flinfo.contents != NULL)
- free (flinfo.contents);
- if (flinfo.external_relocs != NULL)
- free (flinfo.external_relocs);
- if (flinfo.internal_relocs != NULL)
- free (flinfo.internal_relocs);
- if (flinfo.external_syms != NULL)
- free (flinfo.external_syms);
- if (flinfo.locsym_shndx != NULL)
- free (flinfo.locsym_shndx);
- if (flinfo.internal_syms != NULL)
- free (flinfo.internal_syms);
- if (flinfo.indices != NULL)
- free (flinfo.indices);
- if (flinfo.sections != NULL)
- free (flinfo.sections);
- if (flinfo.symbuf != NULL)
- free (flinfo.symbuf);
- if (flinfo.symshndxbuf != NULL)
- free (flinfo.symshndxbuf);
- for (o = abfd->sections; o != NULL; o = o->next)
- {
- struct bfd_elf_section_data *esdo = elf_section_data (o);
- if ((o->flags & SEC_RELOC) != 0 && esdo->rel.hashes != NULL)
- free (esdo->rel.hashes);
- if ((o->flags & SEC_RELOC) != 0 && esdo->rela.hashes != NULL)
- free (esdo->rela.hashes);
- }
+ elf_final_link_free (abfd, &flinfo);
elf_tdata (abfd)->linker = TRUE;
@@ -11531,37 +11547,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
return TRUE;
error_return:
- if (flinfo.symstrtab != NULL)
- _bfd_stringtab_free (flinfo.symstrtab);
- if (flinfo.contents != NULL)
- free (flinfo.contents);
- if (flinfo.external_relocs != NULL)
- free (flinfo.external_relocs);
- if (flinfo.internal_relocs != NULL)
- free (flinfo.internal_relocs);
- if (flinfo.external_syms != NULL)
- free (flinfo.external_syms);
- if (flinfo.locsym_shndx != NULL)
- free (flinfo.locsym_shndx);
- if (flinfo.internal_syms != NULL)
- free (flinfo.internal_syms);
- if (flinfo.indices != NULL)
- free (flinfo.indices);
- if (flinfo.sections != NULL)
- free (flinfo.sections);
- if (flinfo.symbuf != NULL)
- free (flinfo.symbuf);
- if (flinfo.symshndxbuf != NULL)
- free (flinfo.symshndxbuf);
- for (o = abfd->sections; o != NULL; o = o->next)
- {
- struct bfd_elf_section_data *esdo = elf_section_data (o);
- if ((o->flags & SEC_RELOC) != 0 && esdo->rel.hashes != NULL)
- free (esdo->rel.hashes);
- if ((o->flags & SEC_RELOC) != 0 && esdo->rela.hashes != NULL)
- free (esdo->rela.hashes);
- }
-
+ elf_final_link_free (abfd, &flinfo);
return FALSE;
}