From c48cc8a51e9c991bdfc476a01d014465cc5dbb51 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Thu, 4 Feb 2010 09:16:36 +0000 Subject: [PATCH] * elf-bfd.h (emum elf_object_id): Rename to elf_target_id. Add entries for other architectures. (struct elf_link_hash_table): Add hash_table_id field. (elf_hash_table_id): New accessor macro. * elflink.c (_bfd_elf_link_hash_table_init): Add target_id parameter. * elf-m10300.c (elf32_mn10300_hash_table): Check table id before returning cast pointer. (elf32_mn10300_link_hash_table_create): Identify new table as containing MN10300 extensions. (mn10300_elf_relax_section): Check pointer returned by elf32_mn10300_hash_table. * elf32-arm.c: Likewise, except using ARM extensions. * elf32-avr.c: Likewise, except using AVR extensions. * elf32-bfin.c: Likewise, except using BFIN extensions. * elf32-cris.c: Likewise, except using CRIS extensions. * elf32-frv.c: Likewise, except using FRV extensions. * elf32-hppa.c: Likewise, except using HPPA32 extensions. * elf32-i386.c: Likewise, except using I386 extensions. * elf32-lm32.c: Likewise, except using LM32 extensions. * elf32-m32r.c: Likewise, except using M32RM extensions. * elf32-m68hc11.c: Likewise, except using M68HC11 extensions. * elf32-m68hc1x.c: Likewise, except using M68HC11 extensions. * elf32-m68hc1x.h: Likewise, except using M68HC11 extensions. * elf32-m68k.c: Likewise, except using M68K extensions. * elf32-microblaze.c: Likewise, except using MICROBLAZE extensions. * elf32-ppc.c: Likewise, except using PPC32 extensions. * elf32-s390.c: Likewise, except using S390 extensions. * elf32-sh.c: Likewise, except using SH extensions. * elf32-spu.c: Likewise, except using SPU extensions. * elf32-xtensa.c: Likewise, except using XTENSA extensions. * elf64-alpha.c: Likewise, except using ALPHA extensions. * elf64-hppa.c: Likewise, except using HPPA64 extensions. * elf64-ppc.c: Likewise, except using PPC64 extensions. * elf64-s390.c: Likewise, except using S390 extensions. * elf64-x86-64.c: Likewise, except using X86_64 extensions. * elfxx-ia64.c: Likewise, except using IA64 extensions. * elfxx-mips.c: Likewise, except using MIPS extensions. * elfxx-sparc.c: Likewise, except using SPARC extensions. * elfxx-sparc.h: Likewise, except using SPARC extensions. * elf32-cr16.c (struct elf32_cr16_link_hash_table): Delete redundant structure. (elf32_cr16_hash_table): Delete unused macro. (elf32_cr16_link_hash_traverse): Delete unused macro. * elf32-score.c: Likewise. * elf32-score7.c: Likewise. * elf32-vax.c: Likewise. * elf64-sh64.c: Likewise. * emultempl/alphaelf.em: Update value expected from elf_object_id. * emultempl/hppaelf.em: Likewise. * emultempl/mipself.em: Likewise. * emultempl/ppc32elf.em: Likewise. * emultempl/ppc64elf.em: Likewise. --- bfd/ChangeLog | 51 +++++++++++++++++ bfd/elf-bfd.h | 70 +++++++++++++++-------- bfd/elf-m10300.c | 13 +++-- bfd/elf.c | 4 +- bfd/elf32-arm.c | 141 +++++++++++++++++++++++++++++++++------------ bfd/elf32-avr.c | 18 +++--- bfd/elf32-bfin.c | 16 ++++-- bfd/elf32-cr16.c | 71 ++++------------------- bfd/elf32-cris.c | 145 +++++++++++++++++++++++++++-------------------- bfd/elf32-frv.c | 10 ++-- bfd/elf32-hppa.c | 64 +++++++++++++++++++-- bfd/elf32-i386.c | 101 +++++++++++++++++++++++---------- bfd/elf32-lm32.c | 41 ++++++++++++-- bfd/elf32-m32r.c | 35 ++++++++++-- bfd/elf32-m68hc11.c | 4 +- bfd/elf32-m68hc1x.c | 48 +++++++++++----- bfd/elf32-m68hc1x.h | 19 ++++--- bfd/elf32-m68k.c | 18 +++--- bfd/elf32-microblaze.c | 31 +++++++++- bfd/elf32-ppc.c | 10 ++-- bfd/elf32-s390.c | 10 ++-- bfd/elf32-score.c | 79 ++++++++++---------------- bfd/elf32-score7.c | 74 ++---------------------- bfd/elf32-sh.c | 35 ++++++++++-- bfd/elf32-spu.c | 6 +- bfd/elf32-vax.c | 32 ++++------- bfd/elf32-xtensa.c | 43 ++++++++++++-- bfd/elf64-alpha.c | 84 ++++++++++++++++++++------- bfd/elf64-hppa.c | 72 ++++++++++++++++++----- bfd/elf64-ppc.c | 111 ++++++++++++++++++++++++++++++++---- bfd/elf64-s390.c | 113 +++++++++++++++++++++--------------- bfd/elf64-sh64.c | 38 +++++-------- bfd/elf64-x86-64.c | 100 +++++++++++++++++++++++--------- bfd/elflink.c | 8 ++- bfd/elfxx-ia64.c | 85 +++++++++++++++++++-------- bfd/elfxx-mips.c | 97 +++++++++++++++++++++++++++---- bfd/elfxx-sparc.c | 27 +++++++-- bfd/elfxx-sparc.h | 8 ++- ld/ChangeLog | 8 +++ ld/emultempl/alphaelf.em | 2 +- ld/emultempl/hppaelf.em | 3 +- ld/emultempl/mipself.em | 2 +- ld/emultempl/ppc32elf.em | 2 +- ld/emultempl/ppc64elf.em | 2 +- 44 files changed, 1312 insertions(+), 639 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 3007e91bd..2b004d29d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,54 @@ +2010-02-03 Nick Clifton + + * elf-bfd.h (emum elf_object_id): Rename to elf_target_id. Add + entries for other architectures. + (struct elf_link_hash_table): Add hash_table_id field. + (elf_hash_table_id): New accessor macro. + * elflink.c (_bfd_elf_link_hash_table_init): Add target_id + parameter. + * elf-m10300.c (elf32_mn10300_hash_table): Check table id before + returning cast pointer. + (elf32_mn10300_link_hash_table_create): Identify new table as + containing MN10300 extensions. + (mn10300_elf_relax_section): Check pointer returned by + elf32_mn10300_hash_table. + * elf32-arm.c: Likewise, except using ARM extensions. + * elf32-avr.c: Likewise, except using AVR extensions. + * elf32-bfin.c: Likewise, except using BFIN extensions. + * elf32-cris.c: Likewise, except using CRIS extensions. + * elf32-frv.c: Likewise, except using FRV extensions. + * elf32-hppa.c: Likewise, except using HPPA32 extensions. + * elf32-i386.c: Likewise, except using I386 extensions. + * elf32-lm32.c: Likewise, except using LM32 extensions. + * elf32-m32r.c: Likewise, except using M32RM extensions. + * elf32-m68hc11.c: Likewise, except using M68HC11 extensions. + * elf32-m68hc1x.c: Likewise, except using M68HC11 extensions. + * elf32-m68hc1x.h: Likewise, except using M68HC11 extensions. + * elf32-m68k.c: Likewise, except using M68K extensions. + * elf32-microblaze.c: Likewise, except using MICROBLAZE extensions. + * elf32-ppc.c: Likewise, except using PPC32 extensions. + * elf32-s390.c: Likewise, except using S390 extensions. + * elf32-sh.c: Likewise, except using SH extensions. + * elf32-spu.c: Likewise, except using SPU extensions. + * elf32-xtensa.c: Likewise, except using XTENSA extensions. + * elf64-alpha.c: Likewise, except using ALPHA extensions. + * elf64-hppa.c: Likewise, except using HPPA64 extensions. + * elf64-ppc.c: Likewise, except using PPC64 extensions. + * elf64-s390.c: Likewise, except using S390 extensions. + * elf64-x86-64.c: Likewise, except using X86_64 extensions. + * elfxx-ia64.c: Likewise, except using IA64 extensions. + * elfxx-mips.c: Likewise, except using MIPS extensions. + * elfxx-sparc.c: Likewise, except using SPARC extensions. + * elfxx-sparc.h: Likewise, except using SPARC extensions. + * elf32-cr16.c (struct elf32_cr16_link_hash_table): Delete + redundant structure. + (elf32_cr16_hash_table): Delete unused macro. + (elf32_cr16_link_hash_traverse): Delete unused macro. + * elf32-score.c: Likewise. + * elf32-score7.c: Likewise. + * elf32-vax.c: Likewise. + * elf64-sh64.c: Likewise. + 2010-02-03 Alan Modra * elf64-ppc.c (struct plt_entry): Move earlier in file. diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 3c3ac9b25..681ded517 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -1,6 +1,6 @@ /* BFD back-end data structures for ELF files. Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, - 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 + 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. Written by Cygnus Support. @@ -396,12 +396,51 @@ struct eh_frame_hdr_info bfd_boolean table; }; +/* Enum used to identify target specific extensions to the elf_obj_tdata + and elf_link_hash_table structures. Note the enums deliberately start + from 1 so that we can detect an uninitialized field. The generic value + is last so that additions to this enum do not need to modify more than + one line. */ +enum elf_target_id +{ + ALPHA_ELF_DATA = 1, + ARM_ELF_DATA, + AVR_ELF_DATA, + BFIN_ELF_DATA, + CRIS_ELF_DATA, + FRV_ELF_DATA, + HPPA32_ELF_DATA, + HPPA64_ELF_DATA, + I386_ELF_DATA, + IA64_ELF_DATA, + LM32_ELF_DATA, + M32R_ELF_DATA, + M68HC11_ELF_DATA, + M68K_ELF_DATA, + MICROBLAZE_ELF_DATA, + MIPS_ELF_DATA, + MN10300_ELF_DATA, + PPC32_ELF_DATA, + PPC64_ELF_DATA, + S390_ELF_DATA, + SH_ELF_DATA, + SPARC_ELF_DATA, + SPU_ELF_DATA, + X86_64_ELF_DATA, + XTENSA_ELF_DATA, + GENERIC_ELF_DATA +}; + /* ELF linker hash table. */ struct elf_link_hash_table { struct bfd_link_hash_table root; + /* An identifier used to distinguish different target + specific extensions to this structure. */ + enum elf_target_id hash_table_id; + /* Whether we have created the special dynamic sections required when linking against or generating a shared object. */ bfd_boolean dynamic_sections_created; @@ -509,6 +548,8 @@ struct elf_link_hash_table #define elf_hash_table(p) ((struct elf_link_hash_table *) ((p)->hash)) +#define elf_hash_table_id(table) ((table) -> hash_table_id) + /* Returns TRUE if the hash table is a struct elf_link_hash_table. */ #define is_elf_hash_table(htab) \ (((struct bfd_link_hash_table *) (htab))->type == bfd_link_elf_hash_table) @@ -1418,27 +1459,6 @@ enum Tag_compatibility = 32 }; -/* Enum used to identify target specific extensions to the elf_obj_tdata - structure. Note the enums deliberately start from 1 so that we can - detect an uninitialized field. The generic value is last so that - additions to this enum do not need to modify more than one line. */ -enum elf_object_id -{ - ALPHA_ELF_TDATA = 1, - ARM_ELF_TDATA, - HPPA_ELF_TDATA, - I386_ELF_TDATA, - MIPS_ELF_TDATA, - PPC32_ELF_TDATA, - PPC64_ELF_TDATA, - S390_ELF_TDATA, - SH_ELF_TDATA, - SPARC_ELF_TDATA, - X86_64_ELF_TDATA, - XTENSA_ELF_TDATA, - GENERIC_ELF_TDATA -}; - /* Some private data is stashed away for future use using the tdata pointer in the bfd structure. */ @@ -1603,7 +1623,7 @@ struct elf_obj_tdata /* An identifier used to distinguish different target specific extensions to this structure. */ - enum elf_object_id object_id; + enum elf_target_id object_id; }; #define elf_tdata(bfd) ((bfd) -> tdata.elf_obj_data) @@ -1710,7 +1730,7 @@ extern unsigned long bfd_elf_gnu_hash extern bfd_reloc_status_type bfd_elf_generic_reloc (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); extern bfd_boolean bfd_elf_allocate_object - (bfd *, size_t, enum elf_object_id); + (bfd *, size_t, enum elf_target_id); extern bfd_boolean bfd_elf_make_generic_object (bfd *); extern bfd_boolean bfd_elf_mkcorefile @@ -1734,7 +1754,7 @@ extern bfd_boolean _bfd_elf_link_hash_table_init (struct elf_link_hash_table *, bfd *, struct bfd_hash_entry *(*) (struct bfd_hash_entry *, struct bfd_hash_table *, const char *), - unsigned int); + unsigned int, enum elf_target_id); extern bfd_boolean _bfd_elf_slurp_version_tables (bfd *, bfd_boolean); extern bfd_boolean _bfd_elf_merge_sections diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c index 4a9d4b051..8520335d3 100644 --- a/bfd/elf-m10300.c +++ b/bfd/elf-m10300.c @@ -1,6 +1,6 @@ /* Matsushita 10300 specific support for 32-bit ELF Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -98,7 +98,8 @@ struct elf32_mn10300_link_hash_table /* Get the MN10300 ELF linker hash table from a link_info structure. */ #define elf32_mn10300_hash_table(p) \ - ((struct elf32_mn10300_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == MN10300_ELF_DATA ? ((struct elf32_mn10300_link_hash_table *) ((p)->hash)) : NULL) #define elf32_mn10300_link_hash_traverse(table, func, info) \ (elf_link_hash_traverse \ @@ -2076,6 +2077,8 @@ mn10300_elf_relax_section (bfd *abfd, /* We need a pointer to the mn10300 specific hash table. */ hash_table = elf32_mn10300_hash_table (link_info); + if (hash_table == NULL) + return FALSE; /* Initialize fields in each hash table entry the first time through. */ if ((hash_table->flags & MN10300_HASH_ENTRIES_INITIALIZED) == 0) @@ -3977,7 +3980,8 @@ elf32_mn10300_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, elf32_mn10300_link_hash_newfunc, - sizeof (struct elf32_mn10300_link_hash_entry))) + sizeof (struct elf32_mn10300_link_hash_entry), + MN10300_ELF_DATA)) { free (ret); return NULL; @@ -3994,7 +3998,8 @@ elf32_mn10300_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&ret->static_hash_table->root, abfd, elf32_mn10300_link_hash_newfunc, - sizeof (struct elf32_mn10300_link_hash_entry))) + sizeof (struct elf32_mn10300_link_hash_entry), + MN10300_ELF_DATA)) { free (ret->static_hash_table); free (ret); diff --git a/bfd/elf.c b/bfd/elf.c index c1762564a..d8819dbb4 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -232,7 +232,7 @@ bfd_elf_gnu_hash (const char *namearg) bfd_boolean bfd_elf_allocate_object (bfd *abfd, size_t object_size, - enum elf_object_id object_id) + enum elf_target_id object_id) { BFD_ASSERT (object_size >= sizeof (struct elf_obj_tdata)); abfd->tdata.any = bfd_zalloc (abfd, object_size); @@ -249,7 +249,7 @@ bfd_boolean bfd_elf_make_generic_object (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct elf_obj_tdata), - GENERIC_ELF_TDATA); + GENERIC_ELF_DATA); } bfd_boolean diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index 8f00e211d..470e495c8 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -2439,13 +2439,13 @@ struct elf_arm_obj_tdata #define is_arm_elf(bfd) \ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ && elf_tdata (bfd) != NULL \ - && elf_object_id (bfd) == ARM_ELF_TDATA) + && elf_object_id (bfd) == ARM_ELF_DATA) static bfd_boolean elf32_arm_mkobject (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct elf_arm_obj_tdata), - ARM_ELF_TDATA); + ARM_ELF_DATA); } /* The ARM linker needs to keep track of the number of relocs that it @@ -2515,7 +2515,8 @@ struct elf32_arm_link_hash_entry /* Get the ARM elf linker hash table from a link_info structure. */ #define elf32_arm_hash_table(info) \ - ((struct elf32_arm_link_hash_table *) ((info)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \ + == ARM_ELF_DATA ? ((struct elf32_arm_link_hash_table *) ((info)->hash)) : NULL) #define arm_stub_hash_lookup(table, string, create, copy) \ ((struct elf32_arm_stub_hash_entry *) \ @@ -2744,6 +2745,9 @@ create_got_section (bfd *dynobj, struct bfd_link_info *info) struct elf32_arm_link_hash_table *htab; htab = elf32_arm_hash_table (info); + if (htab == NULL) + return FALSE; + /* BPABI objects never have a GOT, or associated sections. */ if (htab->symbian_p) return TRUE; @@ -2773,6 +2777,9 @@ elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) struct elf32_arm_link_hash_table *htab; htab = elf32_arm_hash_table (info); + if (htab == NULL) + return FALSE; + if (!htab->sgot && !create_got_section (dynobj, info)) return FALSE; @@ -2891,7 +2898,8 @@ elf32_arm_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (& ret->root, abfd, elf32_arm_link_hash_newfunc, - sizeof (struct elf32_arm_link_hash_entry))) + sizeof (struct elf32_arm_link_hash_entry), + ARM_ELF_DATA)) { free (ret); return NULL; @@ -3060,6 +3068,8 @@ arm_type_of_stub (struct bfd_link_info *info, return stub_type; globals = elf32_arm_hash_table (info); + if (globals == NULL) + return stub_type; thumb_only = using_thumb_only (globals); @@ -3439,8 +3449,8 @@ arm_build_one_stub (struct bfd_hash_entry *gen_entry, { #define MAXRELOCS 2 struct elf32_arm_stub_hash_entry *stub_entry; + struct elf32_arm_link_hash_table *globals; struct bfd_link_info *info; - struct elf32_arm_link_hash_table *htab; asection *stub_sec; bfd *stub_bfd; bfd_vma stub_addr; @@ -3450,7 +3460,6 @@ arm_build_one_stub (struct bfd_hash_entry *gen_entry, int size; const insn_sequence *template_sequence; int i; - struct elf32_arm_link_hash_table * globals; int stub_reloc_idx[MAXRELOCS] = {-1, -1}; int stub_reloc_offset[MAXRELOCS] = {0, 0}; int nrelocs = 0; @@ -3460,11 +3469,12 @@ arm_build_one_stub (struct bfd_hash_entry *gen_entry, info = (struct bfd_link_info *) in_arg; globals = elf32_arm_hash_table (info); + if (globals == NULL) + return FALSE; - htab = elf32_arm_hash_table (info); stub_sec = stub_entry->stub_sec; - if ((htab->fix_cortex_a8 < 0) + if ((globals->fix_cortex_a8 < 0) != (stub_entry->stub_type >= arm_stub_a8_veneer_lwm)) /* We have to do the a8 fixes last, as they are less aligned than the other veneers. */ @@ -3710,6 +3720,8 @@ elf32_arm_setup_section_lists (bfd *output_bfd, bfd_size_type amt; struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info); + if (htab == NULL) + return 0; if (! is_elf_hash_table (htab)) return 0; @@ -3781,6 +3793,9 @@ elf32_arm_next_input_section (struct bfd_link_info *info, { struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info); + if (htab == NULL) + return; + if (isec->output_section->index <= htab->top_index) { asection **list = htab->input_list + isec->output_section->index; @@ -3940,6 +3955,9 @@ cortex_a8_erratum_scan (bfd *input_bfd, unsigned int num_a8_fixes = *num_a8_fixes_p; unsigned int a8_fix_table_size = *a8_fix_table_size_p; + if (htab == NULL) + return FALSE; + for (section = input_bfd->sections; section != NULL; section = section->next) @@ -4231,6 +4249,9 @@ elf32_arm_size_stubs (bfd *output_bfd, struct a8_erratum_reloc *a8_relocs = NULL; unsigned int num_a8_relocs = 0, a8_reloc_table_size = 10, i; + if (htab == NULL) + return FALSE; + if (htab->fix_cortex_a8) { a8_fixes = (struct a8_erratum_fix *) @@ -4450,7 +4471,9 @@ elf32_arm_size_stubs (bfd *output_bfd, use the PLT stub as target address to decide whether a branch stub is needed. */ - if (globals->splt != NULL && hash != NULL + if (globals != NULL + && globals->splt != NULL + && hash != NULL && hash->root.plt.offset != (bfd_vma) -1) { sym_sec = globals->splt; @@ -4475,7 +4498,9 @@ elf32_arm_size_stubs (bfd *output_bfd, struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (info); - if (globals->splt != NULL && hash != NULL + if (globals != NULL + && globals->splt != NULL + && hash != NULL && hash->root.plt.offset != (bfd_vma) -1) { sym_sec = globals->splt; @@ -4753,6 +4778,8 @@ elf32_arm_build_stubs (struct bfd_link_info *info) struct elf32_arm_link_hash_table *htab; htab = elf32_arm_hash_table (info); + if (htab == NULL) + return FALSE; for (stub_sec = htab->stub_bfd->sections; stub_sec != NULL; @@ -4798,6 +4825,8 @@ find_thumb_glue (struct bfd_link_info *link_info, /* We need a pointer to the armelf specific hash table. */ hash_table = elf32_arm_hash_table (link_info); + if (hash_table == NULL) + return NULL; tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name) + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); @@ -4832,6 +4861,8 @@ find_arm_glue (struct bfd_link_info *link_info, /* We need a pointer to the elfarm specific hash table. */ hash_table = elf32_arm_hash_table (link_info); + if (hash_table == NULL) + return NULL; tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); @@ -4994,7 +5025,6 @@ record_arm_to_thumb_glue (struct bfd_link_info * link_info, bfd_size_type size; globals = elf32_arm_hash_table (link_info); - BFD_ASSERT (globals != NULL); BFD_ASSERT (globals->bfd_of_glue_owner != NULL); @@ -5067,7 +5097,6 @@ record_arm_bx_glue (struct bfd_link_info * link_info, int reg) return; globals = elf32_arm_hash_table (link_info); - BFD_ASSERT (globals != NULL); BFD_ASSERT (globals->bfd_of_glue_owner != NULL); @@ -5164,7 +5193,6 @@ record_vfp11_erratum_veneer (struct bfd_link_info *link_info, elf32_vfp11_erratum_list *newerr; hash_table = elf32_arm_hash_table (link_info); - BFD_ASSERT (hash_table != NULL); BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL); @@ -5329,7 +5357,6 @@ bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info) BFD_ASSERT (!(abfd->flags & DYNAMIC)); globals = elf32_arm_hash_table (info); - BFD_ASSERT (globals != NULL); if (globals->bfd_of_glue_owner != NULL) @@ -5369,7 +5396,6 @@ bfd_elf32_arm_process_before_allocation (bfd *abfd, /* Here we have a bfd that is to be included on the link. We have a hook to do reloc rummaging, before section sizes are nailed down. */ globals = elf32_arm_hash_table (link_info); - BFD_ASSERT (globals != NULL); check_use_blx (globals); @@ -5570,6 +5596,9 @@ bfd_elf32_arm_set_cortex_a8_fix (bfd *obfd, struct bfd_link_info *link_info) struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info); obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd); + if (globals == NULL) + return; + if (globals->fix_cortex_a8 == -1) { /* Turn on Cortex-A8 erratum workaround for ARMv7-A. */ @@ -5589,6 +5618,8 @@ bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info) struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info); obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd); + if (globals == NULL) + return; /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */ if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7) { @@ -5892,6 +5923,9 @@ bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info) struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info); int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR); + if (globals == NULL) + return FALSE; + /* We use a simple FSM to match troublesome VFP11 instruction sequences. The states transition as follows: @@ -6115,6 +6149,8 @@ bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd, return; globals = elf32_arm_hash_table (link_info); + if (globals == NULL) + return; tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10); @@ -6197,6 +6233,8 @@ bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd, struct elf32_arm_link_hash_table *globals; globals = elf32_arm_hash_table (link_info); + if (globals == NULL) + return; globals->target1_is_rel = target1_is_rel; if (strcmp (target2_type, "rel") == 0) @@ -6272,7 +6310,6 @@ elf32_thumb_to_arm_stub (struct bfd_link_info * info, return FALSE; globals = elf32_arm_hash_table (info); - BFD_ASSERT (globals != NULL); BFD_ASSERT (globals->bfd_of_glue_owner != NULL); @@ -6370,7 +6407,6 @@ elf32_arm_create_thumb_stub (struct bfd_link_info * info, return NULL; globals = elf32_arm_hash_table (info); - BFD_ASSERT (globals != NULL); BFD_ASSERT (globals->bfd_of_glue_owner != NULL); @@ -6466,7 +6502,6 @@ elf32_arm_to_thumb_stub (struct bfd_link_info * info, struct elf32_arm_link_hash_table * globals; globals = elf32_arm_hash_table (info); - BFD_ASSERT (globals != NULL); BFD_ASSERT (globals->bfd_of_glue_owner != NULL); @@ -6521,7 +6556,6 @@ elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf) return TRUE; globals = elf32_arm_hash_table (info); - BFD_ASSERT (globals != NULL); BFD_ASSERT (globals->bfd_of_glue_owner != NULL); @@ -6557,7 +6591,6 @@ elf32_arm_bx_glue (struct bfd_link_info * info, int reg) struct elf32_arm_link_hash_table *globals; globals = elf32_arm_hash_table (info); - BFD_ASSERT (globals != NULL); BFD_ASSERT (globals->bfd_of_glue_owner != NULL); @@ -6595,6 +6628,9 @@ elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED, return; globals = elf32_arm_hash_table (link_info); + if (globals == NULL) + return; + /* If blx is available then exported Thumb symbols are OK and there is nothing to do. */ if (globals->use_blx) @@ -6772,6 +6808,8 @@ elf32_arm_final_link_relocate (reloc_howto_type * howto, struct elf32_arm_link_hash_table * globals; globals = elf32_arm_hash_table (info); + if (globals == NULL) + return bfd_reloc_notsupported; BFD_ASSERT (is_arm_elf (input_bfd)); @@ -6875,7 +6913,7 @@ elf32_arm_final_link_relocate (reloc_howto_type * howto, run time. */ if ((info->shared || globals->root.is_relocatable_executable) && (input_section->flags & SEC_ALLOC) - && !(elf32_arm_hash_table (info)->vxworks_p + && !(globals->vxworks_p && strcmp (input_section->output_section->name, ".tls_vars") == 0) && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI) @@ -8747,6 +8785,8 @@ elf32_arm_relocate_section (bfd * output_bfd, struct elf32_arm_link_hash_table * globals; globals = elf32_arm_hash_table (info); + if (globals == NULL) + return FALSE; symtab_hdr = & elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); @@ -9318,6 +9358,9 @@ elf32_arm_final_link (bfd *abfd, struct bfd_link_info *info) { struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (info); + if (globals == NULL) + return FALSE; + /* Invoke the regular ELF backend linker to do all the work. */ if (!bfd_elf_final_link (abfd, info)) return FALSE; @@ -10465,6 +10508,8 @@ elf32_arm_gc_sweep_hook (bfd * abfd, return TRUE; globals = elf32_arm_hash_table (info); + if (globals == NULL) + return FALSE; elf_section_data (sec)->local_dynrel = NULL; @@ -10511,7 +10556,7 @@ elf32_arm_gc_sweep_hook (bfd * abfd, break; case R_ARM_TLS_LDM32: - elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1; + globals->tls_ldm_got.refcount -= 1; break; case R_ARM_ABS32: @@ -10607,6 +10652,9 @@ elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info, BFD_ASSERT (is_arm_elf (abfd)); htab = elf32_arm_hash_table (info); + if (htab == NULL) + return FALSE; + sreloc = NULL; /* Create dynamic sections for relocatable executables so that we can @@ -11129,6 +11177,9 @@ elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info, struct elf32_arm_link_hash_table *globals; globals = elf32_arm_hash_table (info); + if (globals == NULL) + return FALSE; + dynobj = elf_hash_table (info)->dynobj; /* Make sure we know what is going on here. */ @@ -11267,6 +11318,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) info = (struct bfd_link_info *) inf; htab = elf32_arm_hash_table (info); + if (htab == NULL) + return FALSE; if (htab->root.dynamic_sections_created && h->plt.refcount > 0) @@ -11496,7 +11549,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) } } - if (elf32_arm_hash_table (info)->vxworks_p) + if (htab->vxworks_p) { struct elf32_arm_relocs_copied **pp; @@ -11617,6 +11670,9 @@ bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info, struct elf32_arm_link_hash_table *globals; globals = elf32_arm_hash_table (info); + if (globals == NULL) + return; + globals->byteswap_code = byteswap_code; } @@ -11634,6 +11690,9 @@ elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED, struct elf32_arm_link_hash_table *htab; htab = elf32_arm_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = elf_hash_table (info)->dynobj; BFD_ASSERT (dynobj != NULL); check_use_blx (htab); @@ -11660,7 +11719,7 @@ elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED, bfd_size_type locsymcount; Elf_Internal_Shdr *symtab_hdr; asection *srel; - bfd_boolean is_vxworks = elf32_arm_hash_table (info)->vxworks_p; + bfd_boolean is_vxworks = htab->vxworks_p; if (! is_arm_elf (ibfd)) continue; @@ -11908,6 +11967,9 @@ elf32_arm_finish_dynamic_symbol (bfd * output_bfd, dynobj = elf_hash_table (info)->dynobj; htab = elf32_arm_hash_table (info); + if (htab == NULL) + return FALSE; + eh = (struct elf32_arm_link_hash_entry *) h; if (h->plt.offset != (bfd_vma) -1) @@ -12198,20 +12260,23 @@ elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info bfd * dynobj; asection * sgot; asection * sdyn; + struct elf32_arm_link_hash_table *htab; + + htab = elf32_arm_hash_table (info); + if (htab == NULL) + return FALSE; dynobj = elf_hash_table (info)->dynobj; sgot = bfd_get_section_by_name (dynobj, ".got.plt"); - BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL); + BFD_ASSERT (htab->symbian_p || sgot != NULL); sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); if (elf_hash_table (info)->dynamic_sections_created) { asection *splt; Elf32_External_Dyn *dyncon, *dynconend; - struct elf32_arm_link_hash_table *htab; - htab = elf32_arm_hash_table (info); splt = bfd_get_section_by_name (dynobj, ".plt"); BFD_ASSERT (splt != NULL && sdyn != NULL); @@ -12370,7 +12435,7 @@ elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info } /* Fill in the first entry in the procedure linkage table. */ - if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size) + if (splt->size > 0 && htab->plt_header_size) { const bfd_vma *plt0_entry; bfd_vma got_address, plt_address, got_displacement; @@ -12497,7 +12562,7 @@ elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATT if (link_info) { globals = elf32_arm_hash_table (link_info); - if (globals->byteswap_code) + if (globals != NULL && globals->byteswap_code) i_ehdrp->e_flags |= EF_ARM_BE8; } } @@ -12723,10 +12788,8 @@ elf32_arm_output_map_sym (output_arch_syminfo *osi, bfd_vma offset) { static const char *names[3] = {"$a", "$t", "$d"}; - struct elf32_arm_link_hash_table *htab; Elf_Internal_Sym sym; - htab = elf32_arm_hash_table (osi->info); sym.st_value = osi->sec->output_section->vma + osi->sec->output_offset + offset; @@ -12748,8 +12811,6 @@ elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf) struct elf32_arm_link_hash_entry *eh; bfd_vma addr; - htab = elf32_arm_hash_table (osi->info); - if (h->root.type == bfd_link_hash_indirect) return TRUE; @@ -12762,6 +12823,10 @@ elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf) if (h->plt.offset == (bfd_vma) -1) return TRUE; + htab = elf32_arm_hash_table (osi->info); + if (htab == NULL) + return FALSE; + eh = (struct elf32_arm_link_hash_entry *) h; addr = h->plt.offset; if (htab->symbian_p) @@ -12821,10 +12886,8 @@ static bfd_boolean elf32_arm_output_stub_sym (output_arch_syminfo *osi, const char *name, bfd_vma offset, bfd_vma size) { - struct elf32_arm_link_hash_table *htab; Elf_Internal_Sym sym; - htab = elf32_arm_hash_table (osi->info); sym.st_value = osi->sec->output_section->vma + osi->sec->output_offset + offset; @@ -12841,7 +12904,6 @@ arm_map_one_stub (struct bfd_hash_entry * gen_entry, { struct elf32_arm_stub_hash_entry *stub_entry; struct bfd_link_info *info; - struct elf32_arm_link_hash_table *htab; asection *stub_sec; bfd_vma addr; char *stub_name; @@ -12858,7 +12920,6 @@ arm_map_one_stub (struct bfd_hash_entry * gen_entry, info = osi->info; - htab = elf32_arm_hash_table (info); stub_sec = stub_entry->stub_sec; /* Ensure this stub is attached to the current section being @@ -12959,6 +13020,9 @@ elf32_arm_output_arch_local_syms (bfd *output_bfd, bfd_size_type size; htab = elf32_arm_hash_table (info); + if (htab == NULL) + return FALSE; + check_use_blx (htab); osi.finfo = finfo; @@ -13282,6 +13346,9 @@ elf32_arm_write_section (bfd *output_bfd, bfd_byte tmp; unsigned int i; + if (globals == NULL) + return FALSE; + /* If this section has not been allocated an _arm_elf_section_data structure then we cannot record anything. */ arm_data = get_arm_elf_section_data (sec); diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c index 804033e6a..0b85105ba 100644 --- a/bfd/elf32-avr.c +++ b/bfd/elf32-avr.c @@ -1,6 +1,6 @@ /* AVR-specific support for 32-bit ELF - Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 - Free Software Foundation, Inc. + Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, + 2010 Free Software Foundation, Inc. Contributed by Denis Chertykov This file is part of BFD, the Binary File Descriptor library. @@ -38,7 +38,7 @@ static bfd_boolean debug_stubs = FALSE; /* We use two hash tables to hold information for linking avr objects. - The first is the elf32_avr_link_hash_tablse which is derived from the + The first is the elf32_avr_link_hash_table which is derived from the stanard ELF linker hash table. We use this as a place to attach the other hash table and some static information. @@ -104,8 +104,8 @@ struct elf32_avr_link_hash_table /* Various hash macros and functions. */ #define avr_link_hash_table(p) \ /* PR 3874: Check that we have an AVR style hash table before using it. */\ - ((p)->hash->table.newfunc != elf32_avr_link_hash_newfunc ? NULL : \ - ((struct elf32_avr_link_hash_table *) ((p)->hash))) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == AVR_ELF_DATA ? ((struct elf32_avr_link_hash_table *) ((p)->hash)) : NULL) #define avr_stub_hash_entry(ent) \ ((struct elf32_avr_stub_hash_entry *)(ent)) @@ -617,7 +617,8 @@ elf32_avr_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&htab->etab, abfd, elf32_avr_link_hash_newfunc, - sizeof (struct elf_link_hash_entry))) + sizeof (struct elf_link_hash_entry), + AVR_ELF_DATA)) { free (htab); return NULL; @@ -1167,6 +1168,9 @@ elf32_avr_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, Elf_Internal_Rela * relend; struct elf32_avr_link_hash_table * htab = avr_link_hash_table (info); + if (htab == NULL) + return FALSE; + symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; sym_hashes = elf_sym_hashes (input_bfd); relend = relocs + input_section->reloc_count; @@ -2563,7 +2567,7 @@ elf32_avr_setup_section_lists (bfd *output_bfd, asection *section; asection **input_list, **list; bfd_size_type amt; - struct elf32_avr_link_hash_table *htab = avr_link_hash_table(info); + struct elf32_avr_link_hash_table *htab = avr_link_hash_table (info); if (htab == NULL || htab->no_stubs) return 0; diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c index 3f9483ac2..d208f353c 100644 --- a/bfd/elf32-bfin.c +++ b/bfd/elf32-bfin.c @@ -1,5 +1,6 @@ /* ADI Blackfin BFD support for 32-bit ELF. - Copyright 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + Copyright 2005, 2006, 2007, 2008, 2009, 2010 + Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -1716,8 +1717,8 @@ bfin_gc_sweep_hook (bfd * abfd, extern const bfd_target bfd_elf32_bfinfdpic_vec; #define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_bfinfdpic_vec) -/* An extension of the elf hash table data structure, containing some - additional Blackfin-specific data. */ +/* An extension of the elf hash table data structure, + containing some additional Blackfin-specific data. */ struct bfinfdpic_elf_link_hash_table { struct elf_link_hash_table elf; @@ -1748,7 +1749,8 @@ struct bfinfdpic_elf_link_hash_table /* Get the Blackfin ELF linker hash table from a link_info structure. */ #define bfinfdpic_hash_table(info) \ - ((struct bfinfdpic_elf_link_hash_table *) ((info)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \ + == BFIN_ELF_DATA ? ((struct bfinfdpic_elf_link_hash_table *) ((info)->hash)) : NULL) #define bfinfdpic_got_section(info) \ (bfinfdpic_hash_table (info)->sgot) @@ -1814,7 +1816,8 @@ bfinfdpic_elf_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, _bfd_elf_link_hash_newfunc, - sizeof (struct elf_link_hash_entry))) + sizeof (struct elf_link_hash_entry), + BFIN_ELF_DATA)) { free (ret); return NULL; @@ -5192,7 +5195,8 @@ bfin_link_hash_table_create (bfd * abfd) if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, bfin_link_hash_newfunc, - sizeof (struct elf_link_hash_entry))) + sizeof (struct elf_link_hash_entry), + BFIN_ELF_DATA)) { free (ret); return NULL; diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c index 84d955092..354cbd91f 100644 --- a/bfd/elf32-cr16.c +++ b/bfd/elf32-cr16.c @@ -32,7 +32,8 @@ linking with -Bsymbolic. We store the information in a field extending the regular ELF linker hash table. */ -struct elf32_cr16_link_hash_entry { +struct elf32_cr16_link_hash_entry +{ /* The basic elf link hash table entry. */ struct elf_link_hash_entry root; @@ -66,35 +67,6 @@ struct elf32_cr16_link_hash_entry { bfd_vma value; }; -/* We derive a hash table from the main elf linker hash table so - we can store state variables and a secondary hash table without - resorting to global variables. */ -struct elf32_cr16_link_hash_table { - /* The main hash table. */ - struct elf_link_hash_table root; - - /* A hash table for static functions. We could derive a new hash table - instead of using the full elf32_cr16_link_hash_table if we wanted - to save some memory. */ - struct elf32_cr16_link_hash_table *static_hash_table; - - /* Random linker state flags. */ -#define CR16_HASH_ENTRIES_INITIALIZED 0x1 - char flags; -}; - -/* For CR16 linker hash table. */ - -/* Get the CR16 ELF linker hash table from a link_info structure. */ - -#define elf32_cr16_hash_table(p) \ - ((struct elf32_cr16_link_hash_table *) ((p)->hash)) - -#define elf32_cr16_link_hash_traverse(table, func, info) \ - (elf_link_hash_traverse \ - (&(table)->root, \ - (bfd_boolean (*) ((struct elf_link_hash_entry *, void *))) (func), (info))) - /* cr16_reloc_map array maps BFD relocation enum into a CRGAS relocation type. */ struct cr16_reloc_map @@ -1700,40 +1672,23 @@ elf32_cr16_link_hash_newfunc (struct bfd_hash_entry *entry, static struct bfd_link_hash_table * elf32_cr16_link_hash_table_create (bfd *abfd) { - struct elf32_cr16_link_hash_table *ret; - bfd_size_type amt = sizeof (struct elf32_cr16_link_hash_table); + struct elf_link_hash_table *ret; + bfd_size_type amt = sizeof (struct elf_link_hash_table); - ret = (struct elf32_cr16_link_hash_table *) bfd_malloc (amt); - if (ret == (struct elf32_cr16_link_hash_table *) NULL) + ret = (struct elf_link_hash_table *) bfd_malloc (amt); + if (ret == (struct elf_link_hash_table *) NULL) return NULL; - if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, + if (!_bfd_elf_link_hash_table_init (ret, abfd, elf32_cr16_link_hash_newfunc, - sizeof (struct elf32_cr16_link_hash_entry))) - { - free (ret); - return NULL; - } - - ret->flags = 0; - amt = sizeof (struct elf_link_hash_table); - ret->static_hash_table - = (struct elf32_cr16_link_hash_table *) bfd_malloc (amt); - if (ret->static_hash_table == NULL) + sizeof (struct elf32_cr16_link_hash_entry), + GENERIC_ELF_DATA)) { free (ret); return NULL; } - if (!_bfd_elf_link_hash_table_init (&ret->static_hash_table->root, abfd, - elf32_cr16_link_hash_newfunc, - sizeof (struct elf32_cr16_link_hash_entry))) - { - free (ret->static_hash_table); - free (ret); - return NULL; - } - return &ret->root.root; + return &ret->root; } /* Free an cr16 ELF linker hash table. */ @@ -1741,12 +1696,10 @@ elf32_cr16_link_hash_table_create (bfd *abfd) static void elf32_cr16_link_hash_table_free (struct bfd_link_hash_table *hash) { - struct elf32_cr16_link_hash_table *ret - = (struct elf32_cr16_link_hash_table *) hash; + struct elf_link_hash_table *ret + = (struct elf_link_hash_table *) hash; _bfd_generic_link_hash_table_free - ((struct bfd_link_hash_table *) ret->static_hash_table); - _bfd_generic_link_hash_table_free ((struct bfd_link_hash_table *) ret); } diff --git a/bfd/elf32-cris.c b/bfd/elf32-cris.c index ca858d054..5fbaff6c8 100644 --- a/bfd/elf32-cris.c +++ b/bfd/elf32-cris.c @@ -1,6 +1,6 @@ /* CRIS-specific support for 32-bit ELF. - Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 - Free Software Foundation, Inc. + Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, + 2010 Free Software Foundation, Inc. Contributed by Axis Communications AB. Written by Hans-Peter Nilsson, based on elf32-fr30.c PIC and shlib bits based primarily on elf32-m68k.c and elf32-i386.c. @@ -885,13 +885,14 @@ struct elf_cris_link_hash_table #define elf_cris_link_hash_traverse(table, func, info) \ (elf_link_hash_traverse \ (&(table)->root, \ - (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \ + (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ (info))) /* Get the CRIS ELF linker hash table from a link_info structure. */ #define elf_cris_hash_table(p) \ - ((struct elf_cris_link_hash_table *) (p)->hash) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == CRIS_ELF_DATA ? ((struct elf_cris_link_hash_table *) ((p)->hash)) : NULL) /* Get the CRIS ELF linker hash entry from a regular hash entry (the "parent class"). The .root reference is just a simple type @@ -903,10 +904,9 @@ struct elf_cris_link_hash_table /* Create an entry in a CRIS ELF linker hash table. */ static struct bfd_hash_entry * -elf_cris_link_hash_newfunc (entry, table, string) - struct bfd_hash_entry *entry; - struct bfd_hash_table *table; - const char *string; +elf_cris_link_hash_newfunc (struct bfd_hash_entry *entry, + struct bfd_hash_table *table, + const char *string) { struct elf_cris_link_hash_entry *ret = (struct elf_cris_link_hash_entry *) entry; @@ -940,8 +940,7 @@ elf_cris_link_hash_newfunc (entry, table, string) /* Create a CRIS ELF linker hash table. */ static struct bfd_link_hash_table * -elf_cris_link_hash_table_create (abfd) - bfd *abfd; +elf_cris_link_hash_table_create (bfd *abfd) { struct elf_cris_link_hash_table *ret; bfd_size_type amt = sizeof (struct elf_cris_link_hash_table); @@ -952,7 +951,8 @@ elf_cris_link_hash_table_create (abfd) if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, elf_cris_link_hash_newfunc, - sizeof (struct elf_cris_link_hash_entry))) + sizeof (struct elf_cris_link_hash_entry), + CRIS_ELF_DATA)) { free (ret); return NULL; @@ -1027,17 +1027,16 @@ static int additional_relocation_error_msg_count = 10; copied, for further comments. */ static bfd_boolean -cris_elf_relocate_section (output_bfd, info, input_bfd, input_section, - contents, relocs, local_syms, local_sections) - bfd *output_bfd ATTRIBUTE_UNUSED; - struct bfd_link_info *info; - bfd *input_bfd; - asection *input_section; - bfd_byte *contents; - Elf_Internal_Rela *relocs; - Elf_Internal_Sym *local_syms; - asection **local_sections; +cris_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, + struct bfd_link_info *info, + bfd *input_bfd, + asection *input_section, + bfd_byte *contents, + Elf_Internal_Rela *relocs, + Elf_Internal_Sym *local_syms, + asection **local_sections) { + struct elf_cris_link_hash_table * htab; bfd *dynobj; Elf_Internal_Shdr *symtab_hdr; struct elf_link_hash_entry **sym_hashes; @@ -1049,6 +1048,10 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section, Elf_Internal_Rela *relend; asection *srelgot; + htab = elf_cris_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = elf_hash_table (info)->dynobj; local_got_offsets = elf_local_got_offsets (input_bfd); symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; @@ -1587,8 +1590,6 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section, indx = elf_section_data (osec)->dynindx; if (indx == 0) { - struct elf_cris_link_hash_table *htab; - htab = elf_cris_hash_table (info); osec = htab->root.text_index_section; indx = elf_section_data (osec)->dynindx; } @@ -1644,14 +1645,14 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section, } BFD_ASSERT ((input_section->flags & SEC_ALLOC) == 0 - || elf_cris_hash_table (info)->dtpmod_refcount != 0); + || htab->dtpmod_refcount != 0); /* Fill in a R_CRIS_DTPMOD reloc at offset 3 if we haven't already done so. Note that we do this in .got.plt, not in .got, as .got.plt contains the first part, still the reloc is against .got, because the linker script directs (is required to direct) them both into .got. */ - if (elf_cris_hash_table (info)->dtpmod_refcount > 0 + if (htab->dtpmod_refcount > 0 && (input_section->flags & SEC_ALLOC) != 0) { asection *sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); @@ -1686,8 +1687,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section, /* Reverse the sign to mark that we've emitted the required GOT entry. */ - elf_cris_hash_table (info)->dtpmod_refcount - = -elf_cris_hash_table (info)->dtpmod_refcount; + htab->dtpmod_refcount = - htab->dtpmod_refcount; } /* The relocation is the offset from the start of the module @@ -2113,12 +2113,12 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section, dynamic sections here. */ static bfd_boolean -elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym) - bfd *output_bfd; - struct bfd_link_info *info; - struct elf_link_hash_entry *h; - Elf_Internal_Sym *sym; +elf_cris_finish_dynamic_symbol (bfd *output_bfd, + struct bfd_link_info *info, + struct elf_link_hash_entry *h, + Elf_Internal_Sym *sym) { + struct elf_cris_link_hash_table * htab; bfd *dynobj; /* Where in the plt entry to put values. */ @@ -2135,6 +2135,10 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym) const bfd_byte *plt_entry = elf_cris_plt_entry; const bfd_byte *plt_pic_entry = elf_cris_pic_plt_entry; + htab = elf_cris_hash_table (info); + if (htab == NULL) + return FALSE; + /* Adjust the various PLT entry offsets. */ if (bfd_get_mach (output_bfd) == bfd_mach_cris_v32) { @@ -2174,7 +2178,7 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym) processed as part of the runtime lazy .rela.plt relocation). FIXME: There be literal constants here... */ bfd_vma rela_plt_index - = (elf_cris_hash_table (info)->dtpmod_refcount != 0 + = (htab->dtpmod_refcount != 0 ? gotplt_offset/4 - 2 - 3 : gotplt_offset/4 - 3); /* Get the offset into the .got table of the entry that corresponds @@ -2185,7 +2189,7 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym) bfd_vma got_offset = (has_gotplt ? gotplt_offset - : h->got.offset + elf_cris_hash_table(info)->next_gotplt_entry); + : h->got.offset + htab->next_gotplt_entry); /* This symbol has an entry in the procedure linkage table. Set it up. */ @@ -2537,6 +2541,7 @@ cris_elf_gc_sweep_hook (bfd *abfd, asection *sec, const Elf_Internal_Rela *relocs) { + struct elf_cris_link_hash_table * htab; Elf_Internal_Shdr *symtab_hdr; struct elf_link_hash_entry **sym_hashes; bfd_signed_vma *local_got_refcounts; @@ -2552,6 +2557,10 @@ cris_elf_gc_sweep_hook (bfd *abfd, if (dynobj == NULL) return TRUE; + htab = elf_cris_hash_table (info); + if (htab == NULL) + return FALSE; + symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); local_got_refcounts = elf_local_got_refcounts (abfd); @@ -2689,9 +2698,9 @@ cris_elf_gc_sweep_hook (bfd *abfd, break; /* Fall through. */ case R_CRIS_16_DTPREL: - elf_cris_hash_table (info)->dtpmod_refcount--; - if (elf_cris_hash_table (info)->dtpmod_refcount == 0) - elf_cris_hash_table (info)->next_gotplt_entry -= 8; + htab->dtpmod_refcount--; + if (htab->dtpmod_refcount == 0) + htab->next_gotplt_entry -= 8; BFD_ASSERT (local_got_refcounts != NULL); local_got_refcounts[-1]--; break; @@ -2856,14 +2865,18 @@ elf_cris_hide_symbol (info, h, force_local) understand. */ static bfd_boolean -elf_cris_adjust_dynamic_symbol (info, h) - struct bfd_link_info *info; - struct elf_link_hash_entry *h; +elf_cris_adjust_dynamic_symbol (struct bfd_link_info *info, + struct elf_link_hash_entry *h) { + struct elf_cris_link_hash_table * htab; bfd *dynobj; asection *s; bfd_size_type plt_entry_size; + htab = elf_cris_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = elf_hash_table (info)->dynobj; /* Make sure we know what is going on here. */ @@ -2988,8 +3001,8 @@ elf_cris_adjust_dynamic_symbol (info, h) /* We also need to make an entry in the .got.plt section, which will be placed in the .got section by the linker script. */ ((struct elf_cris_link_hash_entry *) h)->gotplt_offset - = elf_cris_hash_table (info)->next_gotplt_entry; - elf_cris_hash_table (info)->next_gotplt_entry += 4; + = htab->next_gotplt_entry; + htab->next_gotplt_entry += 4; s = bfd_get_section_by_name (dynobj, ".got.plt"); BFD_ASSERT (s != NULL); @@ -3113,12 +3126,12 @@ elf_cris_copy_indirect_symbol (struct bfd_link_info *info, /* Look through the relocs for a section during the first phase. */ static bfd_boolean -cris_elf_check_relocs (abfd, info, sec, relocs) - bfd *abfd; - struct bfd_link_info *info; - asection *sec; - const Elf_Internal_Rela *relocs; +cris_elf_check_relocs (bfd *abfd, + struct bfd_link_info *info, + asection *sec, + const Elf_Internal_Rela *relocs) { + struct elf_cris_link_hash_table * htab; bfd *dynobj; Elf_Internal_Shdr *symtab_hdr; struct elf_link_hash_entry **sym_hashes; @@ -3132,6 +3145,10 @@ cris_elf_check_relocs (abfd, info, sec, relocs) if (info->relocatable) return TRUE; + htab = elf_cris_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = elf_hash_table (info)->dynobj; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); @@ -3183,9 +3200,10 @@ cris_elf_check_relocs (abfd, info, sec, relocs) case R_CRIS_16_DTPREL: /* The first .got.plt entry is right after the R_CRIS_DTPMOD entry at index 3. */ - if (elf_cris_hash_table (info)->dtpmod_refcount == 0) - elf_cris_hash_table (info)->next_gotplt_entry += 8; - elf_cris_hash_table (info)->dtpmod_refcount++; + if (htab->dtpmod_refcount == 0) + htab->next_gotplt_entry += 8; + + htab->dtpmod_refcount++; /* Fall through. */ case R_CRIS_32_IE: @@ -3718,15 +3736,19 @@ cris_elf_check_relocs (abfd, info, sec, relocs) /* Set the sizes of the dynamic sections. */ static bfd_boolean -elf_cris_size_dynamic_sections (output_bfd, info) - bfd *output_bfd ATTRIBUTE_UNUSED; - struct bfd_link_info *info; +elf_cris_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, + struct bfd_link_info *info) { + struct elf_cris_link_hash_table * htab; bfd *dynobj; asection *s; bfd_boolean plt; bfd_boolean relocs; + htab = elf_cris_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = elf_hash_table (info)->dynobj; BFD_ASSERT (dynobj != NULL); @@ -3744,9 +3766,8 @@ elf_cris_size_dynamic_sections (output_bfd, info) else { /* Adjust all expected GOTPLT uses to use a GOT entry instead. */ - elf_cris_link_hash_traverse (elf_cris_hash_table (info), - elf_cris_adjust_gotplt_to_got, - (PTR) info); + elf_cris_link_hash_traverse (htab, elf_cris_adjust_gotplt_to_got, + info); /* We may have created entries in the .rela.got section. However, if we are not creating the dynamic sections, we will @@ -3766,13 +3787,13 @@ elf_cris_size_dynamic_sections (output_bfd, info) visibility changes. For programs, we discard space for relocs for symbols not referenced by any dynamic object. */ if (info->shared) - elf_cris_link_hash_traverse (elf_cris_hash_table (info), + elf_cris_link_hash_traverse (htab, elf_cris_discard_excess_dso_dynamics, - (PTR) info); + info); else - elf_cris_link_hash_traverse (elf_cris_hash_table (info), + elf_cris_link_hash_traverse (htab, elf_cris_discard_excess_program_dynamics, - (PTR) info); + info); /* The check_relocs and adjust_dynamic_symbol entry points have determined the sizes of the various dynamic sections. Allocate @@ -3800,13 +3821,13 @@ elf_cris_size_dynamic_sections (output_bfd, info) /* The .got.plt contains the .got header as well as the actual .got.plt contents. The .got header may contain a R_CRIS_DTPMOD entry at index 3. */ - s->size += elf_cris_hash_table (info)->dtpmod_refcount != 0 + s->size += htab->dtpmod_refcount != 0 ? 8 : 0; } else if (CONST_STRNEQ (name, ".rela")) { if (strcmp (name, ".rela.got") == 0 - && elf_cris_hash_table (info)->dtpmod_refcount != 0 + && htab->dtpmod_refcount != 0 && info->shared) s->size += sizeof (Elf32_External_Rela); diff --git a/bfd/elf32-frv.c b/bfd/elf32-frv.c index 00b39c223..8d940c089 100644 --- a/bfd/elf32-frv.c +++ b/bfd/elf32-frv.c @@ -1,5 +1,5 @@ /* FRV-specific support for 32-bit ELF. - Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 + Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -882,8 +882,9 @@ struct frvfdpic_elf_link_hash_table /* Get the FRV ELF linker hash table from a link_info structure. */ -#define frvfdpic_hash_table(info) \ - ((struct frvfdpic_elf_link_hash_table *) ((info)->hash)) +#define frvfdpic_hash_table(p) \ + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == FRV_ELF_DATA ? ((struct frvfdpic_elf_link_hash_table *) ((p)->hash)) : NULL) #define frvfdpic_got_section(info) \ (frvfdpic_hash_table (info)->sgot) @@ -1006,7 +1007,8 @@ frvfdpic_elf_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, _bfd_elf_link_hash_newfunc, - sizeof (struct elf_link_hash_entry))) + sizeof (struct elf_link_hash_entry), + FRV_ELF_DATA)) { free (ret); return NULL; diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c index babe9f20a..5142d3cf2 100644 --- a/bfd/elf32-hppa.c +++ b/bfd/elf32-hppa.c @@ -1,6 +1,6 @@ /* BFD back-end for HP PA-RISC ELF files. Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001, - 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 + 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. Original code by @@ -314,7 +314,8 @@ struct elf32_hppa_link_hash_table /* Various hash macros and functions. */ #define hppa_link_hash_table(p) \ - ((struct elf32_hppa_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == HPPA32_ELF_DATA ? ((struct elf32_hppa_link_hash_table *) ((p)->hash)) : NULL) #define hppa_elf_hash_entry(ent) \ ((struct elf32_hppa_link_hash_entry *)(ent)) @@ -341,7 +342,7 @@ static bfd_boolean elf32_hppa_mkobject (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct elf_obj_tdata), - HPPA_ELF_TDATA); + HPPA32_ELF_DATA); } /* Assorted hash table functions. */ @@ -432,7 +433,8 @@ elf32_hppa_link_hash_table_create (bfd *abfd) return NULL; if (!_bfd_elf_link_hash_table_init (&htab->etab, abfd, hppa_link_hash_newfunc, - sizeof (struct elf32_hppa_link_hash_entry))) + sizeof (struct elf32_hppa_link_hash_entry), + HPPA32_ELF_DATA)) { free (htab); return NULL; @@ -728,6 +730,9 @@ hppa_build_one_stub (struct bfd_hash_entry *bh, void *in_arg) info = (struct bfd_link_info *)in_arg; htab = hppa_link_hash_table (info); + if (htab == NULL) + return FALSE; + stub_sec = hsh->stub_sec; /* Make a note of the offset within the stubs for this entry. */ @@ -1000,6 +1005,8 @@ elf32_hppa_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) /* Don't try to create the .plt and .got twice. */ htab = hppa_link_hash_table (info); + if (htab == NULL) + return FALSE; if (htab->splt != NULL) return TRUE; @@ -1160,6 +1167,8 @@ elf32_hppa_check_relocs (bfd *abfd, return TRUE; htab = hppa_link_hash_table (info); + if (htab == NULL) + return FALSE; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; eh_syms = elf_sym_hashes (abfd); sreloc = NULL; @@ -1369,7 +1378,7 @@ elf32_hppa_check_relocs (bfd *abfd, if (r_type == R_PARISC_TLS_LDM21L || r_type == R_PARISC_TLS_LDM14R) - hppa_link_hash_table (info)->tls_ldm_got.refcount += 1; + htab->tls_ldm_got.refcount += 1; else { if (hh != NULL) @@ -1601,10 +1610,15 @@ elf32_hppa_gc_sweep_hook (bfd *abfd, bfd_signed_vma *local_got_refcounts; bfd_signed_vma *local_plt_refcounts; const Elf_Internal_Rela *rela, *relend; + struct elf32_hppa_link_hash_table *htab; if (info->relocatable) return TRUE; + htab = hppa_link_hash_table (info); + if (htab == NULL) + return FALSE; + elf_section_data (sec)->local_dynrel = NULL; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; @@ -1669,7 +1683,7 @@ elf32_hppa_gc_sweep_hook (bfd *abfd, case R_PARISC_TLS_LDM21L: case R_PARISC_TLS_LDM14R: - hppa_link_hash_table (info)->tls_ldm_got.refcount -= 1; + htab->tls_ldm_got.refcount -= 1; break; case R_PARISC_PCREL12F: @@ -1904,6 +1918,8 @@ elf32_hppa_adjust_dynamic_symbol (struct bfd_link_info *info, same memory location for the variable. */ htab = hppa_link_hash_table (info); + if (htab == NULL) + return FALSE; /* We must generate a COPY reloc to tell the dynamic linker to copy the initial value out of the dynamic object and into the @@ -1939,6 +1955,9 @@ allocate_plt_static (struct elf_link_hash_entry *eh, void *inf) info = (struct bfd_link_info *) inf; hh = hppa_elf_hash_entry (eh); htab = hppa_link_hash_table (info); + if (htab == NULL) + return FALSE; + if (htab->etab.dynamic_sections_created && eh->plt.refcount > 0) { @@ -2005,6 +2024,9 @@ allocate_dynrelocs (struct elf_link_hash_entry *eh, void *inf) info = inf; htab = hppa_link_hash_table (info); + if (htab == NULL) + return FALSE; + hh = hppa_elf_hash_entry (eh); if (htab->etab.dynamic_sections_created @@ -2212,6 +2234,9 @@ elf32_hppa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, bfd_boolean relocs; htab = hppa_link_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->etab.dynobj; if (dynobj == NULL) abort (); @@ -2505,6 +2530,9 @@ elf32_hppa_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info) bfd_size_type amt; struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info); + if (htab == NULL) + return -1; + /* Count the number of input BFDs and find the top input section id. */ for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0; input_bfd != NULL; @@ -2572,6 +2600,9 @@ elf32_hppa_next_input_section (struct bfd_link_info *info, asection *isec) { struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info); + if (htab == NULL) + return; + if (isec->output_section->index <= htab->top_index) { asection **list = htab->input_list + isec->output_section->index; @@ -2679,6 +2710,9 @@ get_local_syms (bfd *output_bfd, bfd *input_bfd, struct bfd_link_info *info) int stub_changed = 0; struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info); + if (htab == NULL) + return -1; + /* We want to read in symbol extension records only once. To do this we need to read in the local symbols in parallel and save them for later use; so hold pointers to the local symbols in an array. */ @@ -2807,6 +2841,9 @@ elf32_hppa_size_stubs bfd_boolean stub_changed; struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info); + if (htab == NULL) + return FALSE; + /* Stash our params away. */ htab->stub_bfd = stub_bfd; htab->multi_subspace = multi_subspace; @@ -3092,6 +3129,9 @@ elf32_hppa_set_gp (bfd *abfd, struct bfd_link_info *info) struct elf32_hppa_link_hash_table *htab; htab = hppa_link_hash_table (info); + if (htab == NULL) + return FALSE; + h = bfd_link_hash_lookup (&htab->etab.root, "$global$", FALSE, FALSE, FALSE); if (h != NULL @@ -3176,6 +3216,8 @@ elf32_hppa_build_stubs (struct bfd_link_info *info) struct elf32_hppa_link_hash_table *htab; htab = hppa_link_hash_table (info); + if (htab == NULL) + return FALSE; for (stub_sec = htab->stub_bfd->sections; stub_sec != NULL; @@ -3252,6 +3294,8 @@ hppa_record_segment_addr (bfd *abfd, asection *section, void *data) struct elf32_hppa_link_hash_table *htab; htab = (struct elf32_hppa_link_hash_table*) data; + if (htab == NULL) + return; if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) { @@ -3633,6 +3677,9 @@ elf32_hppa_relocate_section (bfd *output_bfd, symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; htab = hppa_link_hash_table (info); + if (htab == NULL) + return FALSE; + local_got_offsets = elf_local_got_offsets (input_bfd); rela = relocs; @@ -4300,6 +4347,8 @@ elf32_hppa_finish_dynamic_symbol (bfd *output_bfd, bfd_byte *loc; htab = hppa_link_hash_table (info); + if (htab == NULL) + return FALSE; if (eh->plt.offset != (bfd_vma) -1) { @@ -4469,6 +4518,9 @@ elf32_hppa_finish_dynamic_sections (bfd *output_bfd, asection *sdyn; htab = hppa_link_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->etab.dynobj; sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 61e309720..7e1baac7f 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -1,6 +1,6 @@ /* Intel 80386/80486-specific support for 32-bit ELF Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, - 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -634,13 +634,13 @@ struct elf_i386_obj_tdata #define is_i386_elf(bfd) \ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ && elf_tdata (bfd) != NULL \ - && elf_object_id (bfd) == I386_ELF_TDATA) + && elf_object_id (bfd) == I386_ELF_DATA) static bfd_boolean elf_i386_mkobject (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct elf_i386_obj_tdata), - I386_ELF_TDATA); + I386_ELF_DATA); } /* i386 ELF linker hash table. */ @@ -653,19 +653,8 @@ struct elf_i386_link_hash_table asection *sdynbss; asection *srelbss; - /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */ - asection *srelplt2; - - /* True if the target system is VxWorks. */ - int is_vxworks; - - /* Value used to fill the last word of the first plt entry. */ - bfd_byte plt0_pad_byte; - - /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */ - bfd_vma next_tls_desc_index; - - union { + union + { bfd_signed_vma refcount; bfd_vma offset; } tls_ldm_got; @@ -682,13 +671,26 @@ struct elf_i386_link_hash_table /* Used by local STT_GNU_IFUNC symbols. */ htab_t loc_hash_table; - void *loc_hash_memory; + void * loc_hash_memory; + + /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */ + asection *srelplt2; + + /* True if the target system is VxWorks. */ + int is_vxworks; + + /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */ + bfd_vma next_tls_desc_index; + + /* Value used to fill the last word of the first plt entry. */ + bfd_byte plt0_pad_byte; }; /* Get the i386 ELF linker hash table from a link_info structure. */ #define elf_i386_hash_table(p) \ - ((struct elf_i386_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == I386_ELF_DATA ? ((struct elf_i386_link_hash_table *) ((p)->hash)) : NULL) #define elf_i386_compute_jump_table_size(htab) \ ((htab)->next_tls_desc_index * 4) @@ -808,7 +810,8 @@ elf_i386_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, elf_i386_link_hash_newfunc, - sizeof (struct elf_i386_link_hash_entry))) + sizeof (struct elf_i386_link_hash_entry), + I386_ELF_DATA)) { free (ret); return NULL; @@ -867,6 +870,9 @@ elf_i386_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) return FALSE; htab = elf_i386_hash_table (info); + if (htab == NULL) + return FALSE; + htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); if (!info->shared) htab->srelbss = bfd_get_section_by_name (dynobj, ".rel.bss"); @@ -1234,12 +1240,19 @@ elf_i386_tls_transition (struct bfd_link_info *info, bfd *abfd, name = h->root.root.string; else { - Elf_Internal_Sym *isym; struct elf_i386_link_hash_table *htab; + htab = elf_i386_hash_table (info); - isym = bfd_sym_from_r_symndx (&htab->sym_cache, - abfd, r_symndx); - name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL); + if (htab == NULL) + name = "*unknown*"; + else + { + Elf_Internal_Sym *isym; + + isym = bfd_sym_from_r_symndx (&htab->sym_cache, + abfd, r_symndx); + name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL); + } } (*_bfd_error_handler) @@ -1278,6 +1291,9 @@ elf_i386_check_relocs (bfd *abfd, BFD_ASSERT (is_i386_elf (abfd)); htab = elf_i386_hash_table (info); + if (htab == NULL) + return FALSE; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); @@ -1757,6 +1773,7 @@ elf_i386_gc_sweep_hook (bfd *abfd, asection *sec, const Elf_Internal_Rela *relocs) { + struct elf_i386_link_hash_table *htab; Elf_Internal_Shdr *symtab_hdr; struct elf_link_hash_entry **sym_hashes; bfd_signed_vma *local_got_refcounts; @@ -1765,6 +1782,10 @@ elf_i386_gc_sweep_hook (bfd *abfd, if (info->relocatable) return TRUE; + htab = elf_i386_hash_table (info); + if (htab == NULL) + return FALSE; + elf_section_data (sec)->local_dynrel = NULL; symtab_hdr = &elf_symtab_hdr (abfd); @@ -1810,8 +1831,8 @@ elf_i386_gc_sweep_hook (bfd *abfd, switch (r_type) { case R_386_TLS_LDM: - if (elf_i386_hash_table (info)->tls_ldm_got.refcount > 0) - elf_i386_hash_table (info)->tls_ldm_got.refcount -= 1; + if (htab->tls_ldm_got.refcount > 0) + htab->tls_ldm_got.refcount -= 1; break; case R_386_TLS_GD: @@ -1946,6 +1967,8 @@ elf_i386_adjust_dynamic_symbol (struct bfd_link_info *info, } htab = elf_i386_hash_table (info); + if (htab == NULL) + return FALSE; /* If there aren't any dynamic relocs in read-only sections, then we can keep the dynamic relocs and avoid the copy reloc. This @@ -2025,6 +2048,8 @@ elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) info = (struct bfd_link_info *) inf; htab = elf_i386_hash_table (info); + if (htab == NULL) + return FALSE; /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it here if it is defined and referenced in a non-shared object. */ @@ -2348,6 +2373,8 @@ elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, bfd *ibfd; htab = elf_i386_hash_table (info); + if (htab == NULL) + return FALSE; dynobj = htab->elf.dynobj; if (dynobj == NULL) abort (); @@ -2634,17 +2661,22 @@ elf_i386_always_size_sections (bfd *output_bfd, if (tlsbase && tlsbase->type == STT_TLS) { + struct elf_i386_link_hash_table *htab; struct bfd_link_hash_entry *bh = NULL; const struct elf_backend_data *bed = get_elf_backend_data (output_bfd); + htab = elf_i386_hash_table (info); + if (htab == NULL) + return FALSE; + if (!(_bfd_generic_link_add_one_symbol (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL, tls_sec, 0, NULL, FALSE, bed->collect, &bh))) return FALSE; - elf_i386_hash_table (info)->tls_module_base = bh; + htab->tls_module_base = bh; tlsbase = (struct elf_link_hash_entry *)bh; tlsbase->def_regular = 1; @@ -2698,17 +2730,21 @@ elf_i386_fake_sections (bfd *abfd ATTRIBUTE_UNUSED, static void elf_i386_set_tls_module_base (struct bfd_link_info *info) { + struct elf_i386_link_hash_table *htab; struct bfd_link_hash_entry *base; if (!info->executable) return; - base = elf_i386_hash_table (info)->tls_module_base; + htab = elf_i386_hash_table (info); + if (htab == NULL) + return; - if (!base) + base = htab->tls_module_base; + if (base == NULL) return; - base->u.def.value = elf_hash_table (info)->tls_size; + base->u.def.value = htab->elf.tls_size; } /* Return the base VMA address which should be subtracted from real addresses @@ -2762,6 +2798,8 @@ elf_i386_relocate_section (bfd *output_bfd, BFD_ASSERT (is_i386_elf (input_bfd)); htab = elf_i386_hash_table (info); + if (htab == NULL) + return FALSE; symtab_hdr = &elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); local_got_offsets = elf_local_got_offsets (input_bfd); @@ -4046,6 +4084,8 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd, struct elf_i386_link_hash_table *htab; htab = elf_i386_hash_table (info); + if (htab == NULL) + return FALSE; if (h->plt.offset != (bfd_vma) -1) { @@ -4365,6 +4405,9 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd, asection *sdyn; htab = elf_i386_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->elf.dynobj; sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c index 6184f49fc..68195c3bf 100644 --- a/bfd/elf32-lm32.c +++ b/bfd/elf32-lm32.c @@ -1,5 +1,5 @@ /* Lattice Mico32-specific support for 32-bit ELF - Copyright 2008, 2009 Free Software Foundation, Inc. + Copyright 2008, 2009, 2010 Free Software Foundation, Inc. Contributed by Jon Beniston This file is part of BFD, the Binary File Descriptor library. @@ -102,7 +102,8 @@ struct elf_lm32_link_hash_table /* Get the lm32 ELF linker hash table from a link_info structure. */ #define lm32_elf_hash_table(p) \ - ((struct elf_lm32_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == LM32_ELF_DATA ? ((struct elf_lm32_link_hash_table *) ((p)->hash)) : NULL) #define lm32fdpic_got_section(info) \ (lm32_elf_hash_table (info)->sgot) @@ -164,7 +165,8 @@ lm32_elf_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, lm32_elf_link_hash_newfunc, - sizeof (struct elf_lm32_link_hash_entry))) + sizeof (struct elf_lm32_link_hash_entry), + LM32_ELF_DATA)) { free (ret); return NULL; @@ -219,10 +221,13 @@ create_got_section (bfd *dynobj, struct bfd_link_info *info) if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0) return TRUE; + htab = lm32_elf_hash_table (info); + if (htab == NULL) + return FALSE; + if (! _bfd_elf_create_got_section (dynobj, info)) return FALSE; - htab = lm32_elf_hash_table (info); htab->sgot = bfd_get_section_by_name (dynobj, ".got"); htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); htab->srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); @@ -241,7 +246,10 @@ create_rofixup_section (bfd *dynobj, struct bfd_link_info *info) struct elf_lm32_link_hash_table *htab; htab = lm32_elf_hash_table (info); - /* Fixup section for R_LM32_32 relocs */ + if (htab == NULL) + return FALSE; + + /* Fixup section for R_LM32_32 relocs. */ lm32fdpic_fixup32_section (info) = bfd_make_section_with_flags (dynobj, ".rofixup", (SEC_ALLOC @@ -818,12 +826,14 @@ lm32_elf_relocate_section (bfd *output_bfd, Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd); Elf_Internal_Rela *rel, *relend; - struct elf_lm32_link_hash_table *htab = lm32_elf_hash_table (info); bfd *dynobj; bfd_vma *local_got_offsets; asection *sgot, *splt, *sreloc; + if (htab == NULL) + return FALSE; + dynobj = htab->root.dynobj; local_got_offsets = elf_local_got_offsets (input_bfd); @@ -1296,6 +1306,9 @@ lm32_elf_check_relocs (bfd *abfd, sym_hashes_end -= symtab_hdr->sh_info; htab = lm32_elf_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->root.dynobj; local_got_offsets = elf_local_got_offsets (abfd); @@ -1424,6 +1437,9 @@ lm32_elf_finish_dynamic_sections (bfd *output_bfd, asection *sgot; htab = lm32_elf_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->root.dynobj; sgot = htab->sgotplt; @@ -1603,6 +1619,9 @@ lm32_elf_finish_dynamic_symbol (bfd *output_bfd, bfd_byte *loc; htab = lm32_elf_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->root.dynobj; if (h->plt.offset != (bfd_vma) -1) @@ -1884,6 +1903,9 @@ lm32_elf_adjust_dynamic_symbol (struct bfd_link_info *info, same memory location for the variable. */ htab = lm32_elf_hash_table (info); + if (htab == NULL) + return FALSE; + s = htab->sdynbss; BFD_ASSERT (s != NULL); @@ -1926,6 +1948,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) info = (struct bfd_link_info *) inf; htab = lm32_elf_hash_table (info); + if (htab == NULL) + return FALSE; eh = (struct elf_lm32_link_hash_entry *) h; @@ -2142,6 +2166,9 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, bfd *ibfd; htab = lm32_elf_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->root.dynobj; BFD_ASSERT (dynobj != NULL); @@ -2469,6 +2496,8 @@ lm32_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) int ptralign = 2; /* 32bit */ htab = lm32_elf_hash_table (info); + if (htab == NULL) + return FALSE; /* Make sure we have a GOT - For the case where we have a dynamic object but none of the relocs in check_relocs */ diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c index bd2fd993f..4c683ed18 100644 --- a/bfd/elf32-m32r.c +++ b/bfd/elf32-m32r.c @@ -1,6 +1,6 @@ /* M32R-specific support for 32-bit ELF. Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -1540,9 +1540,9 @@ struct elf_m32r_link_hash_table /* Get the m32r ELF linker hash table from a link_info structure. */ - #define m32r_elf_hash_table(p) \ - ((struct elf_m32r_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == M32R_ELF_DATA ? ((struct elf_m32r_link_hash_table *) ((p)->hash)) : NULL) /* Create an entry in an m32r ELF linker hash table. */ @@ -1591,7 +1591,8 @@ m32r_elf_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, m32r_elf_link_hash_newfunc, - sizeof (struct elf_m32r_link_hash_entry))) + sizeof (struct elf_m32r_link_hash_entry), + M32R_ELF_DATA)) { free (ret); return NULL; @@ -1621,6 +1622,9 @@ create_got_section (bfd *dynobj, struct bfd_link_info *info) return FALSE; htab = m32r_elf_hash_table (info); + if (htab == NULL) + return FALSE; + htab->sgot = bfd_get_section_by_name (dynobj, ".got"); htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); htab->srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); @@ -1642,6 +1646,8 @@ m32r_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) int ptralign = 2; /* 32bit */ htab = m32r_elf_hash_table (info); + if (htab == NULL) + return FALSE; /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and .rel[a].bss sections. */ @@ -1934,6 +1940,9 @@ m32r_elf_adjust_dynamic_symbol (struct bfd_link_info *info, same memory location for the variable. */ htab = m32r_elf_hash_table (info); + if (htab == NULL) + return FALSE; + s = htab->sdynbss; BFD_ASSERT (s != NULL); @@ -1976,6 +1985,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) info = (struct bfd_link_info *) inf; htab = m32r_elf_hash_table (info); + if (htab == NULL) + return FALSE; eh = (struct elf_m32r_link_hash_entry *) h; @@ -2196,6 +2207,9 @@ m32r_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, #endif htab = m32r_elf_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->root.dynobj; BFD_ASSERT (dynobj != NULL); @@ -2434,13 +2448,15 @@ m32r_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, Elf_Internal_Rela *rel, *relend; /* Assume success. */ bfd_boolean ret = TRUE; - struct elf_m32r_link_hash_table *htab = m32r_elf_hash_table (info); bfd *dynobj; bfd_vma *local_got_offsets; asection *sgot, *splt, *sreloc; bfd_vma high_address = bfd_get_section_limit (input_bfd, input_section); + if (htab == NULL) + return FALSE; + dynobj = htab->root.dynobj; local_got_offsets = elf_local_got_offsets (input_bfd); @@ -3145,6 +3161,9 @@ m32r_elf_finish_dynamic_symbol (bfd *output_bfd, #endif htab = m32r_elf_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->root.dynobj; if (h->plt.offset != (bfd_vma) -1) @@ -3347,6 +3366,9 @@ m32r_elf_finish_dynamic_sections (bfd *output_bfd, #endif htab = m32r_elf_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->root.dynobj; sgot = htab->sgotplt; @@ -3764,6 +3786,9 @@ m32r_elf_check_relocs (bfd *abfd, sym_hashes = elf_sym_hashes (abfd); htab = m32r_elf_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->root.dynobj; local_got_offsets = elf_local_got_offsets (abfd); diff --git a/bfd/elf32-m68hc11.c b/bfd/elf32-m68hc11.c index 0fee7dff0..5e5b890d2 100644 --- a/bfd/elf32-m68hc11.c +++ b/bfd/elf32-m68hc11.c @@ -1,5 +1,5 @@ /* Motorola 68HC11-specific support for 32-bit ELF - Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 + Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2010 Free Software Foundation, Inc. Contributed by Stephane Carrez (stcarrez@nerim.fr) (Heavily copied from the D10V port by Martin Hunt (hunt@cygnus.com)) @@ -409,6 +409,8 @@ m68hc11_elf_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) info = (struct bfd_link_info *) in_arg; htab = m68hc11_elf_hash_table (info); + if (htab == NULL) + return FALSE; stub_sec = stub_entry->stub_sec; diff --git a/bfd/elf32-m68hc1x.c b/bfd/elf32-m68hc1x.c index db63856d4..9199f6936 100644 --- a/bfd/elf32-m68hc1x.c +++ b/bfd/elf32-m68hc1x.c @@ -1,6 +1,6 @@ /* Motorola 68HC11/HC12-specific support for 32-bit ELF Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, - 2009 Free Software Foundation, Inc. + 2009, 2010 Free Software Foundation, Inc. Contributed by Stephane Carrez (stcarrez@nerim.fr) This file is part of BFD, the Binary File Descriptor library. @@ -74,7 +74,8 @@ m68hc11_elf_hash_table_create (bfd *abfd) memset (ret, 0, amt); if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, _bfd_elf_link_hash_newfunc, - sizeof (struct elf_link_hash_entry))) + sizeof (struct elf_link_hash_entry), + M68HC11_ELF_DATA)) { free (ret); return NULL; @@ -232,6 +233,8 @@ elf32_m68hc11_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info) struct m68hc11_elf_link_hash_table *htab; htab = m68hc11_elf_hash_table (info); + if (htab == NULL) + return -1; if (bfd_get_flavour (info->output_bfd) != bfd_target_elf_flavour) return 0; @@ -320,9 +323,11 @@ elf32_m68hc11_size_stubs (bfd *output_bfd, bfd *stub_bfd, unsigned int bfd_indx, bfd_count; bfd_size_type amt; asection *stub_sec; - struct m68hc11_elf_link_hash_table *htab = m68hc11_elf_hash_table (info); + if (htab == NULL) + return FALSE; + /* Stash our params away. */ htab->stub_bfd = stub_bfd; htab->add_stub_section = add_stub_section; @@ -331,9 +336,7 @@ elf32_m68hc11_size_stubs (bfd *output_bfd, bfd *stub_bfd, for (input_bfd = info->input_bfds, bfd_count = 0; input_bfd != NULL; input_bfd = input_bfd->link_next) - { - bfd_count += 1; - } + bfd_count += 1; /* We want to read in symbol extension records only once. To do this we need to read in the local symbols in parallel and save them for @@ -567,6 +570,8 @@ m68hc11_elf_export_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) info = (struct bfd_link_info *) in_arg; htab = m68hc11_elf_hash_table (info); + if (htab == NULL) + return FALSE; /* Massage our args to the form they really have. */ stub_entry = (struct elf32_m68hc11_stub_hash_entry *) gen_entry; @@ -628,6 +633,8 @@ elf32_m68hc11_build_stubs (bfd *abfd, struct bfd_link_info *info) m68hc11_elf_get_bank_parameters (info); htab = m68hc11_elf_hash_table (info); + if (htab == NULL) + return FALSE; for (stub_sec = htab->stub_bfd->sections; stub_sec != NULL; @@ -677,8 +684,13 @@ m68hc11_elf_get_bank_parameters (struct bfd_link_info *info) unsigned i; struct m68hc11_page_info *pinfo; struct bfd_link_hash_entry *h; + struct m68hc11_elf_link_hash_table *htab; + + htab = m68hc11_elf_hash_table (info); + if (htab == NULL) + return; - pinfo = &m68hc11_elf_hash_table (info)->pinfo; + pinfo = & htab->pinfo; if (pinfo->bank_param_initialized) return; @@ -891,16 +903,22 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, const char *name = NULL; struct m68hc11_page_info *pinfo; const struct elf_backend_data * const ebd = get_elf_backend_data (input_bfd); + struct m68hc11_elf_link_hash_table *htab; symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; sym_hashes = elf_sym_hashes (input_bfd); + htab = m68hc11_elf_hash_table (info); + if (htab == NULL) + return FALSE; + /* Get memory bank parameters. */ m68hc11_elf_get_bank_parameters (info); - pinfo = &m68hc11_elf_hash_table (info)->pinfo; + pinfo = & htab->pinfo; rel = relocs; relend = relocs + input_section->reloc_count; + for (; rel < relend; rel++) { int r_type; @@ -993,9 +1011,7 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, if (is_far && ELF32_R_TYPE (rel->r_info) == R_M68HC11_16) { struct elf32_m68hc11_stub_hash_entry* stub; - struct m68hc11_elf_link_hash_table *htab; - htab = m68hc11_elf_hash_table (info); stub = m68hc12_stub_hash_lookup (htab->stub_hash_table, name, FALSE, FALSE); if (stub) @@ -1320,15 +1336,22 @@ void elf32_m68hc11_post_process_headers (bfd *abfd, struct bfd_link_info *link_info) { struct m68hc11_scan_param param; + struct m68hc11_elf_link_hash_table *htab; + + if (link_info == NULL) + return; - if (link_info == 0) + htab = m68hc11_elf_hash_table (link_info); + if (htab == NULL) return; m68hc11_elf_get_bank_parameters (link_info); param.use_memory_banks = FALSE; - param.pinfo = &m68hc11_elf_hash_table (link_info)->pinfo; + param.pinfo = & htab->pinfo; + bfd_map_over_sections (abfd, scan_sections_for_abi, ¶m); + if (param.use_memory_banks) { Elf_Internal_Ehdr * i_ehdrp; @@ -1337,4 +1360,3 @@ elf32_m68hc11_post_process_headers (bfd *abfd, struct bfd_link_info *link_info) i_ehdrp->e_flags |= E_M68HC12_BANKS; } } - diff --git a/bfd/elf32-m68hc1x.h b/bfd/elf32-m68hc1x.h index 5bc547afa..317371f6f 100644 --- a/bfd/elf32-m68hc1x.h +++ b/bfd/elf32-m68hc1x.h @@ -1,5 +1,6 @@ /* Motorola 68HC11/68HC12-specific support for 32-bit ELF - Copyright 2003, 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. + Copyright 2003, 2004, 2005, 2006, 2007, 2009, 2010 + Free Software Foundation, Inc. Contributed by Stephane Carrez (stcarrez@nerim.fr) This file is part of BFD, the Binary File Descriptor library. @@ -42,8 +43,8 @@ extern bfd_boolean _bfd_m68hc11_elf_print_private_bfd_data (bfd*, void*); The trampoline is used when a pointer to a far function is used. It takes care of installing the proper memory bank as well as creating the 'call/rtc' calling convention. */ -struct elf32_m68hc11_stub_hash_entry { - +struct elf32_m68hc11_stub_hash_entry +{ /* Base hash table entry structure. */ struct bfd_hash_entry root; @@ -83,9 +84,8 @@ struct elf32_m68hc11_stub_hash_entry { less or equal to the page size) For 68HC12, the window is at 0x8000 and the page size is 16K (full window). - For 68HC11 this is board specific (implemented by external hardware). + For 68HC11 this is board specific (implemented by external hardware). */ -*/ struct m68hc11_page_info { bfd_vma bank_virtual; @@ -113,7 +113,7 @@ struct m68hc11_elf_link_hash_table asection* tramp_section; /* Linker call-backs. */ - asection * (*add_stub_section) PARAMS ((const char *, asection *)); + asection * (*add_stub_section) (const char *, asection *); /* Assorted information used by elf32_hppa_size_stubs. */ unsigned int bfd_count; @@ -123,14 +123,15 @@ struct m68hc11_elf_link_hash_table /* Small local sym cache. */ struct sym_cache sym_cache; - bfd_boolean (* size_one_stub) PARAMS((struct bfd_hash_entry*, void*)); - bfd_boolean (* build_one_stub) PARAMS((struct bfd_hash_entry*, void*)); + bfd_boolean (* size_one_stub) (struct bfd_hash_entry*, void*); + bfd_boolean (* build_one_stub) (struct bfd_hash_entry*, void*); }; /* Get the Sparc64 ELF linker hash table from a link_info structure. */ #define m68hc11_elf_hash_table(p) \ - ((struct m68hc11_elf_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == M68HC11_ELF_DATA ? ((struct m68hc11_elf_link_hash_table *) ((p)->hash)) : NULL) /* Create a 68HC11/68HC12 ELF linker hash table. */ diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c index 17a5e0b52..0eb4133b0 100644 --- a/bfd/elf32-m68k.c +++ b/bfd/elf32-m68k.c @@ -1,6 +1,6 @@ /* Motorola 68k series support for 32-bit ELF Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, - 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -937,7 +937,8 @@ struct elf_m68k_link_hash_table /* Get the m68k ELF linker hash table from a link_info structure. */ #define elf_m68k_hash_table(p) \ - ((struct elf_m68k_link_hash_table *) (p)->hash) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == M68K_ELF_DATA ? ((struct elf_m68k_link_hash_table *) ((p)->hash)) : NULL) /* Shortcut to multi-GOT data. */ #define elf_m68k_multi_got(INFO) (&elf_m68k_hash_table (INFO)->multi_got_) @@ -945,10 +946,9 @@ struct elf_m68k_link_hash_table /* Create an entry in an m68k ELF linker hash table. */ static struct bfd_hash_entry * -elf_m68k_link_hash_newfunc (entry, table, string) - struct bfd_hash_entry *entry; - struct bfd_hash_table *table; - const char *string; +elf_m68k_link_hash_newfunc (struct bfd_hash_entry *entry, + struct bfd_hash_table *table, + const char *string) { struct bfd_hash_entry *ret = entry; @@ -975,8 +975,7 @@ elf_m68k_link_hash_newfunc (entry, table, string) /* Create an m68k ELF linker hash table. */ static struct bfd_link_hash_table * -elf_m68k_link_hash_table_create (abfd) - bfd *abfd; +elf_m68k_link_hash_table_create (bfd *abfd) { struct elf_m68k_link_hash_table *ret; bfd_size_type amt = sizeof (struct elf_m68k_link_hash_table); @@ -987,7 +986,8 @@ elf_m68k_link_hash_table_create (abfd) if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, elf_m68k_link_hash_newfunc, - sizeof (struct elf_m68k_link_hash_entry))) + sizeof (struct elf_m68k_link_hash_entry), + M68K_ELF_DATA)) { free (ret); return NULL; diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c index 47e4d5181..da80c8535 100644 --- a/bfd/elf32-microblaze.c +++ b/bfd/elf32-microblaze.c @@ -576,7 +576,8 @@ struct elf32_mb_link_hash_table /* Get the ELF linker hash table from a link_info structure. */ #define elf32_mb_hash_table(p) \ - ((struct elf32_mb_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == MICROBLAZE_ELF_DATA ? ((struct elf32_mb_link_hash_table *) ((p)->hash)) : NULL) /* Create an entry in a microblaze ELF linker hash table. */ @@ -621,7 +622,8 @@ microblaze_elf_link_hash_table_create (bfd *abfd) return NULL; if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc, - sizeof (struct elf32_mb_link_hash_entry))) + sizeof (struct elf32_mb_link_hash_entry), + MICROBLAZE_ELF_DATA)) { free (ret); return NULL; @@ -709,6 +711,9 @@ microblaze_elf_relocate_section (bfd *output_bfd, microblaze_elf_howto_init (); htab = elf32_mb_hash_table (info); + if (htab == NULL) + return FALSE; + local_got_offsets = elf_local_got_offsets (input_bfd); sreloc = elf_section_data (input_section)->sreloc; @@ -1867,6 +1872,9 @@ create_got_section (bfd *dynobj, struct bfd_link_info *info) if (! _bfd_elf_create_got_section (dynobj, info)) return FALSE; htab = elf32_mb_hash_table (info); + if (htab == NULL) + return FALSE; + htab->sgot = bfd_get_section_by_name (dynobj, ".got"); htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); if (!htab->sgot || !htab->sgotplt) @@ -1906,6 +1914,9 @@ microblaze_elf_check_relocs (bfd * abfd, return TRUE; htab = elf32_mb_hash_table (info); + if (htab == NULL) + return FALSE; + local_got_offsets = elf_local_got_offsets (abfd); symtab_hdr = & elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); @@ -2148,6 +2159,9 @@ microblaze_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) struct elf32_mb_link_hash_table *htab; htab = elf32_mb_hash_table (info); + if (htab == NULL) + return FALSE; + if (!htab->sgot && !create_got_section (dynobj, info)) return FALSE; @@ -2228,6 +2242,8 @@ microblaze_elf_adjust_dynamic_symbol (struct bfd_link_info *info, bfd *dynobj; htab = elf32_mb_hash_table (info); + if (htab == NULL) + return FALSE; /* If this is a function, put it in the procedure linkage table. We will fill in the contents of the procedure linkage table later, @@ -2376,6 +2392,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * dat) info = (struct bfd_link_info *) dat; htab = elf32_mb_hash_table (info); + if (htab == NULL) + return FALSE; if (htab->elf.dynamic_sections_created && h->plt.refcount > 0) @@ -2538,6 +2556,9 @@ microblaze_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, bfd *ibfd; htab = elf32_mb_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->elf.dynobj; BFD_ASSERT (dynobj != NULL); @@ -2730,6 +2751,9 @@ microblaze_elf_finish_dynamic_symbol (bfd *output_bfd, struct elf32_mb_link_hash_table *htab; htab = elf32_mb_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->elf.dynobj; if (h->plt.offset != (bfd_vma) -1) @@ -2888,6 +2912,9 @@ microblaze_elf_finish_dynamic_sections (bfd *output_bfd, struct elf32_mb_link_hash_table *htab; htab = elf32_mb_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->elf.dynobj; sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index fc4347e44..539ff9d60 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -1796,7 +1796,7 @@ struct ppc_elf_obj_tdata #define is_ppc_elf(bfd) \ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ - && elf_object_id (bfd) == PPC32_ELF_TDATA) + && elf_object_id (bfd) == PPC32_ELF_DATA) /* Override the generic function because we store some extras. */ @@ -1804,7 +1804,7 @@ static bfd_boolean ppc_elf_mkobject (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct ppc_elf_obj_tdata), - PPC32_ELF_TDATA); + PPC32_ELF_DATA); } /* Fix bad default arch selected for a 32 bit input bfd when the @@ -2782,7 +2782,8 @@ struct ppc_elf_link_hash_table /* Get the PPC ELF linker hash table from a link_info structure. */ #define ppc_elf_hash_table(p) \ - ((struct ppc_elf_link_hash_table *) (p)->hash) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == PPC32_ELF_DATA ? ((struct ppc_elf_link_hash_table *) ((p)->hash)) : NULL) /* Create an entry in a PPC ELF linker hash table. */ @@ -2826,7 +2827,8 @@ ppc_elf_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, ppc_elf_link_hash_newfunc, - sizeof (struct ppc_elf_link_hash_entry))) + sizeof (struct ppc_elf_link_hash_entry), + PPC32_ELF_DATA)) { free (ret); return NULL; diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c index 41178d683..336ba36e8 100644 --- a/bfd/elf32-s390.c +++ b/bfd/elf32-s390.c @@ -693,13 +693,13 @@ struct elf_s390_obj_tdata #define is_s390_elf(bfd) \ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ && elf_tdata (bfd) != NULL \ - && elf_object_id (bfd) == S390_ELF_TDATA) + && elf_object_id (bfd) == S390_ELF_DATA) static bfd_boolean elf_s390_mkobject (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct elf_s390_obj_tdata), - S390_ELF_TDATA); + S390_ELF_DATA); } static bfd_boolean @@ -737,7 +737,8 @@ struct elf_s390_link_hash_table /* Get the s390 ELF linker hash table from a link_info structure. */ #define elf_s390_hash_table(p) \ - ((struct elf_s390_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == S390_ELF_DATA ? ((struct elf_s390_link_hash_table *) ((p)->hash)) : NULL) /* Create an entry in an s390 ELF linker hash table. */ @@ -786,7 +787,8 @@ elf_s390_link_hash_table_create (abfd) return NULL; if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc, - sizeof (struct elf_s390_link_hash_entry))) + sizeof (struct elf_s390_link_hash_entry), + S390_ELF_DATA)) { free (ret); return NULL; diff --git a/bfd/elf32-score.c b/bfd/elf32-score.c index 15612d379..61c9c0812 100644 --- a/bfd/elf32-score.c +++ b/bfd/elf32-score.c @@ -1,5 +1,5 @@ /* 32-bit ELF support for S+core. - Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. Contributed by Brain.lin (brain.lin@sunplusct.com) Mei Ligang (ligang@sunnorth.com.cn) @@ -37,13 +37,6 @@ int score3 = 0; int score7 = 1; -/* Score ELF linker hash table. */ -struct score_elf_link_hash_table -{ - /* The main hash table. */ - struct elf_link_hash_table root; -}; - /* The SCORE ELF linker needs additional information for each symbol in the global hash table. */ struct score_elf_link_hash_entry @@ -68,14 +61,10 @@ struct score_elf_link_hash_entry /* Traverse a score ELF linker hash table. */ #define score_elf_link_hash_traverse(table, func, info) \ (elf_link_hash_traverse \ - (&(table)->root, \ + ((table), \ (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ (info))) -/* Get the SCORE elf linker hash table from a link_info structure. */ -#define score_elf_hash_table(info) \ - ((struct score_elf_link_hash_table *) ((info)->hash)) - /* This structure is used to hold .got entries while estimating got sizes. */ struct score_got_entry { @@ -1135,10 +1124,9 @@ score_elf_sort_hash_table (struct bfd_link_info *info, too large offsets. */ - (g->next ? g->assigned_gotno : 0); hsd.max_non_got_dynindx = max_local; - score_elf_link_hash_traverse (((struct score_elf_link_hash_table *) - elf_hash_table (info)), - score_elf_sort_hash_table_f, - &hsd); + score_elf_link_hash_traverse (elf_hash_table (info), + score_elf_sort_hash_table_f, + &hsd); /* There should have been enough room in the symbol table to accommodate both the GOT and non-GOT symbols. */ @@ -1154,22 +1142,23 @@ score_elf_sort_hash_table (struct bfd_link_info *info, } /* Create an entry in an score ELF linker hash table. */ + static struct bfd_hash_entry * score_elf_link_hash_newfunc (struct bfd_hash_entry *entry, struct bfd_hash_table *table, const char *string) { - struct score_elf_link_hash_entry *ret = (struct score_elf_link_hash_entry *)entry; + struct score_elf_link_hash_entry *ret = (struct score_elf_link_hash_entry *) entry; /* Allocate the structure if it has not already been allocated by a subclass. */ if (ret == NULL) ret = bfd_hash_allocate (table, sizeof (struct score_elf_link_hash_entry)); if (ret == NULL) - return (struct bfd_hash_entry *)ret; + return (struct bfd_hash_entry *) ret; /* Call the allocation method of the superclass. */ ret = ((struct score_elf_link_hash_entry *) - _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *)ret, table, string)); + _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, table, string)); if (ret != NULL) { @@ -1179,7 +1168,7 @@ score_elf_link_hash_newfunc (struct bfd_hash_entry *entry, ret->forced_local = FALSE; } - return (struct bfd_hash_entry *)ret; + return (struct bfd_hash_entry *) ret; } /* Returns the first relocation of type r_type found, beginning with @@ -2083,7 +2072,7 @@ score_elf_final_link_relocate (reloc_howto_type *howto, { g = score_elf_global_got_index (elf_hash_table (info)->dynobj, (struct elf_link_hash_entry *) h); - if ((! elf_hash_table(info)->dynamic_sections_created + if ((! elf_hash_table (info)->dynamic_sections_created || (info->shared && (info->symbolic || h->root.dynindx == -1) && h->root.def_regular))) @@ -4006,28 +3995,6 @@ elf32_score_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, return NULL; } -/* Create a score elf linker hash table. */ - -static struct bfd_link_hash_table * -s3_elf32_score_link_hash_table_create (bfd *abfd) -{ - struct score_elf_link_hash_table *ret; - bfd_size_type amt = sizeof (struct score_elf_link_hash_table); - - ret = bfd_malloc (amt); - if (ret == NULL) - return NULL; - - if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, score_elf_link_hash_newfunc, - sizeof (struct score_elf_link_hash_entry))) - { - free (ret); - return NULL; - } - - return &ret->root.root; -} - static bfd_boolean s3_elf32_score_print_private_bfd_data (bfd *abfd, void * ptr) { @@ -4394,13 +4361,29 @@ elf32_score_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_t return s7_elf32_score_reloc_type_lookup (abfd, code); } +/* Create a score elf linker hash table. + This is a copy of _bfd_elf_link_hash_table_create() except with a + different hash table entry creation function. */ + static struct bfd_link_hash_table * elf32_score_link_hash_table_create (bfd *abfd) { - if (bfd_get_mach (abfd) == bfd_mach_score3) - return s3_elf32_score_link_hash_table_create (abfd); - else - return s7_elf32_score_link_hash_table_create (abfd); + struct elf_link_hash_table *ret; + bfd_size_type amt = sizeof (struct elf_link_hash_table); + + ret = (struct elf_link_hash_table *) bfd_malloc (amt); + if (ret == NULL) + return NULL; + + if (!_bfd_elf_link_hash_table_init (ret, abfd, score_elf_link_hash_newfunc, + sizeof (struct score_elf_link_hash_entry), + GENERIC_ELF_DATA)) + { + free (ret); + return NULL; + } + + return &ret->root; } static bfd_boolean diff --git a/bfd/elf32-score7.c b/bfd/elf32-score7.c index bb74f28c2..cd87ff346 100644 --- a/bfd/elf32-score7.c +++ b/bfd/elf32-score7.c @@ -1,5 +1,5 @@ /* 32-bit ELF support for S+core. - Copyright 2009 Free Software Foundation, Inc. + Copyright 2009, 2010 Free Software Foundation, Inc. Contributed by Brain.lin (brain.lin@sunplusct.com) Mei Ligang (ligang@sunnorth.com.cn) @@ -34,13 +34,6 @@ #include "elf32-score.h" -/* Score ELF linker hash table. */ -struct score_elf_link_hash_table -{ - /* The main hash table. */ - struct elf_link_hash_table root; -}; - /* The SCORE ELF linker needs additional information for each symbol in the global hash table. */ struct score_elf_link_hash_entry @@ -65,14 +58,10 @@ struct score_elf_link_hash_entry /* Traverse a score ELF linker hash table. */ #define score_elf_link_hash_traverse(table, func, info) \ (elf_link_hash_traverse \ - (&(table)->root, \ + ((table), \ (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ (info))) -/* Get the SCORE elf linker hash table from a link_info structure. */ -#define score_elf_hash_table(info) \ - ((struct score_elf_link_hash_table *) ((info)->hash)) - /* This structure is used to hold .got entries while estimating got sizes. */ struct score_got_entry { @@ -1020,10 +1009,9 @@ score_elf_sort_hash_table (struct bfd_link_info *info, too large offsets. */ - (g->next ? g->assigned_gotno : 0); hsd.max_non_got_dynindx = max_local; - score_elf_link_hash_traverse (((struct score_elf_link_hash_table *) - elf_hash_table (info)), - score_elf_sort_hash_table_f, - &hsd); + score_elf_link_hash_traverse (elf_hash_table (info), + score_elf_sort_hash_table_f, + &hsd); /* There should have been enough room in the symbol table to accommodate both the GOT and non-GOT symbols. */ @@ -1038,36 +1026,6 @@ score_elf_sort_hash_table (struct bfd_link_info *info, return TRUE; } -/* Create an entry in an score ELF linker hash table. */ - -static struct bfd_hash_entry * -score_elf_link_hash_newfunc (struct bfd_hash_entry *entry, - struct bfd_hash_table *table, - const char *string) -{ - struct score_elf_link_hash_entry *ret = (struct score_elf_link_hash_entry *) entry; - - /* Allocate the structure if it has not already been allocated by a subclass. */ - if (ret == NULL) - ret = bfd_hash_allocate (table, sizeof (struct score_elf_link_hash_entry)); - if (ret == NULL) - return (struct bfd_hash_entry *) ret; - - /* Call the allocation method of the superclass. */ - ret = ((struct score_elf_link_hash_entry *) - _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, table, string)); - - if (ret != NULL) - { - ret->possibly_dynamic_relocs = 0; - ret->readonly_reloc = FALSE; - ret->no_fn_stub = FALSE; - ret->forced_local = FALSE; - } - - return (struct bfd_hash_entry *) ret; -} - /* Returns the first relocation of type r_type found, beginning with RELOCATION. RELEND is one-past-the-end of the relocation table. */ @@ -3841,28 +3799,6 @@ s7_elf32_score_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_rea return NULL; } -/* Create a score elf linker hash table. */ - -struct bfd_link_hash_table * -s7_elf32_score_link_hash_table_create (bfd *abfd) -{ - struct score_elf_link_hash_table *ret; - bfd_size_type amt = sizeof (struct score_elf_link_hash_table); - - ret = bfd_malloc (amt); - if (ret == NULL) - return NULL; - - if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, score_elf_link_hash_newfunc, - sizeof (struct score_elf_link_hash_entry))) - { - free (ret); - return NULL; - } - - return &ret->root.root; -} - bfd_boolean s7_elf32_score_print_private_bfd_data (bfd *abfd, void * ptr) { diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c index b16e3e1dd..23ee06a1d 100644 --- a/bfd/elf32-sh.c +++ b/bfd/elf32-sh.c @@ -1,6 +1,6 @@ /* Renesas / SuperH SH specific support for 32-bit ELF Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. Contributed by Ian Lance Taylor, Cygnus Support. This file is part of BFD, the Binary File Descriptor library. @@ -2157,7 +2157,7 @@ struct sh_elf_obj_tdata #define is_sh_elf(bfd) \ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ && elf_tdata (bfd) != NULL \ - && elf_object_id (bfd) == SH_ELF_TDATA) + && elf_object_id (bfd) == SH_ELF_DATA) /* Override the generic function because we need to store sh_elf_obj_tdata as the specific tdata. */ @@ -2166,7 +2166,7 @@ static bfd_boolean sh_elf_mkobject (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct sh_elf_obj_tdata), - SH_ELF_TDATA); + SH_ELF_DATA); } /* sh ELF linker hash table. */ @@ -2215,7 +2215,8 @@ struct elf_sh_link_hash_table /* Get the sh ELF linker hash table from a link_info structure. */ #define sh_elf_hash_table(p) \ - ((struct elf_sh_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == SH_ELF_DATA ? ((struct elf_sh_link_hash_table *) ((p)->hash)) : NULL) /* Create an entry in an sh ELF linker hash table. */ @@ -2267,7 +2268,8 @@ sh_elf_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, sh_elf_link_hash_newfunc, - sizeof (struct elf_sh_link_hash_entry))) + sizeof (struct elf_sh_link_hash_entry), + SH_ELF_DATA)) { free (ret); return NULL; @@ -2301,6 +2303,9 @@ create_got_section (bfd *dynobj, struct bfd_link_info *info) return FALSE; htab = sh_elf_hash_table (info); + if (htab == NULL) + return FALSE; + htab->sgot = bfd_get_section_by_name (dynobj, ".got"); htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); htab->srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); @@ -2336,6 +2341,9 @@ sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) } htab = sh_elf_hash_table (info); + if (htab == NULL) + return FALSE; + if (htab->root.dynamic_sections_created) return TRUE; @@ -2482,6 +2490,8 @@ sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info, asection *s; htab = sh_elf_hash_table (info); + if (htab == NULL) + return FALSE; /* Make sure we know what is going on here. */ BFD_ASSERT (htab->root.dynobj != NULL @@ -2628,6 +2638,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) info = (struct bfd_link_info *) inf; htab = sh_elf_hash_table (info); + if (htab == NULL) + return FALSE; eh = (struct elf_sh_link_hash_entry *) h; if ((h->got.refcount > 0 @@ -2935,6 +2947,9 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, bfd *ibfd; htab = sh_elf_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->root.dynobj; BFD_ASSERT (dynobj != NULL); @@ -3182,6 +3197,8 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, BFD_ASSERT (is_sh_elf (input_bfd)); htab = sh_elf_hash_table (info); + if (htab == NULL) + return FALSE; symtab_hdr = &elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); dynobj = htab->root.dynobj; @@ -4860,6 +4877,9 @@ sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, sym_hashes = elf_sym_hashes (abfd); htab = sh_elf_hash_table (info); + if (htab == NULL) + return FALSE; + local_got_offsets = elf_local_got_offsets (abfd); rel_end = relocs + sec->reloc_count; @@ -5414,6 +5434,8 @@ sh_elf_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info, struct elf_sh_link_hash_table *htab; htab = sh_elf_hash_table (info); + if (htab == NULL) + return FALSE; if (h->plt.offset != (bfd_vma) -1) { @@ -5718,6 +5740,9 @@ sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) asection *sdyn; htab = sh_elf_hash_table (info); + if (htab == NULL) + return FALSE; + sgot = htab->sgotplt; sdyn = bfd_get_section_by_name (htab->root.dynobj, ".dynamic"); diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c index c6139c9da..b29b35c24 100644 --- a/bfd/elf32-spu.c +++ b/bfd/elf32-spu.c @@ -356,7 +356,8 @@ struct got_entry }; #define spu_hash_table(p) \ - ((struct spu_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == SPU_ELF_DATA ? ((struct spu_link_hash_table *) ((p)->hash)) : NULL) struct call_info { @@ -443,7 +444,8 @@ spu_elf_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&htab->elf, abfd, _bfd_elf_link_hash_newfunc, - sizeof (struct elf_link_hash_entry))) + sizeof (struct elf_link_hash_entry), + SPU_ELF_DATA)) { free (htab); return NULL; diff --git a/bfd/elf32-vax.c b/bfd/elf32-vax.c index 63f74ab28..2c29179da 100644 --- a/bfd/elf32-vax.c +++ b/bfd/elf32-vax.c @@ -1,6 +1,6 @@ /* VAX series support for 32-bit ELF Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, - 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. Contributed by Matt Thomas . This file is part of BFD, the Binary File Descriptor library. @@ -407,35 +407,24 @@ struct elf_vax_link_hash_entry bfd_vma got_addend; }; -/* VAX ELF linker hash table. */ - -struct elf_vax_link_hash_table -{ - struct elf_link_hash_table root; -}; - /* Declare this now that the above structures are defined. */ static bfd_boolean elf_vax_discard_copies (struct elf_vax_link_hash_entry *, - PTR); + void *); /* Declare this now that the above structures are defined. */ static bfd_boolean elf_vax_instantiate_got_entries (struct elf_link_hash_entry *, - PTR); + void *); /* Traverse an VAX ELF linker hash table. */ #define elf_vax_link_hash_traverse(table, func, info) \ (elf_link_hash_traverse \ - (&(table)->root, \ + ((table), \ (bfd_boolean (*) (struct elf_link_hash_entry *, PTR)) (func), \ (info))) -/* Get the VAX ELF linker hash table from a link_info structure. */ - -#define elf_vax_hash_table(p) ((struct elf_vax_link_hash_table *) (p)->hash) - /* Create an entry in an VAX ELF linker hash table. */ static struct bfd_hash_entry * @@ -472,22 +461,23 @@ elf_vax_link_hash_newfunc (struct bfd_hash_entry *entry, static struct bfd_link_hash_table * elf_vax_link_hash_table_create (bfd *abfd) { - struct elf_vax_link_hash_table *ret; - bfd_size_type amt = sizeof (struct elf_vax_link_hash_table); + struct elf_link_hash_table *ret; + bfd_size_type amt = sizeof (struct elf_link_hash_table); ret = bfd_malloc (amt); if (ret == NULL) return NULL; - if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, + if (!_bfd_elf_link_hash_table_init (ret, abfd, elf_vax_link_hash_newfunc, - sizeof (struct elf_vax_link_hash_entry))) + sizeof (struct elf_vax_link_hash_entry), + GENERIC_ELF_DATA)) { free (ret); return NULL; } - return &ret->root.root; + return &ret->root; } /* Keep vax-specific flags in the ELF header */ @@ -1132,7 +1122,7 @@ elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) allocated space for them in the check_relocs routine, but we will not fill them in in the relocate_section routine. */ if (info->shared && info->symbolic) - elf_vax_link_hash_traverse (elf_vax_hash_table (info), + elf_vax_link_hash_traverse (elf_hash_table (info), elf_vax_discard_copies, NULL); diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c index 1740c355a..1992c9488 100644 --- a/bfd/elf32-xtensa.c +++ b/bfd/elf32-xtensa.c @@ -1,5 +1,5 @@ /* Xtensa-specific support for 32-bit ELF. - Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 + Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -572,13 +572,13 @@ struct elf_xtensa_obj_tdata #define is_xtensa_elf(bfd) \ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ && elf_tdata (bfd) != NULL \ - && elf_object_id (bfd) == XTENSA_ELF_TDATA) + && elf_object_id (bfd) == XTENSA_ELF_DATA) static bfd_boolean elf_xtensa_mkobject (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct elf_xtensa_obj_tdata), - XTENSA_ELF_TDATA); + XTENSA_ELF_DATA); } /* Xtensa ELF linker hash table. */ @@ -610,7 +610,8 @@ struct elf_xtensa_link_hash_table /* Get the Xtensa ELF linker hash table from a link_info structure. */ #define elf_xtensa_hash_table(p) \ - ((struct elf_xtensa_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == XTENSA_ELF_DATA ? ((struct elf_xtensa_link_hash_table *) ((p)->hash)) : NULL) /* Create an entry in an Xtensa ELF linker hash table. */ @@ -656,7 +657,8 @@ elf_xtensa_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, elf_xtensa_link_hash_newfunc, - sizeof (struct elf_xtensa_link_hash_entry))) + sizeof (struct elf_xtensa_link_hash_entry), + XTENSA_ELF_DATA)) { free (ret); return NULL; @@ -977,6 +979,9 @@ elf_xtensa_check_relocs (bfd *abfd, BFD_ASSERT (is_xtensa_elf (abfd)); htab = elf_xtensa_hash_table (info); + if (htab == NULL) + return FALSE; + symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); @@ -1278,6 +1283,8 @@ elf_xtensa_gc_sweep_hook (bfd *abfd, struct elf_xtensa_link_hash_table *htab; htab = elf_xtensa_hash_table (info); + if (htab == NULL) + return FALSE; if (info->relocatable) return TRUE; @@ -1397,6 +1404,8 @@ elf_xtensa_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) flagword flags, noalloc_flags; htab = elf_xtensa_hash_table (info); + if (htab == NULL) + return FALSE; /* First do all the standard stuff. */ if (! _bfd_elf_create_dynamic_sections (dynobj, info)) @@ -1523,6 +1532,8 @@ elf_xtensa_allocate_dynrelocs (struct elf_link_hash_entry *h, void *arg) info = (struct bfd_link_info *) arg; htab = elf_xtensa_hash_table (info); + if (htab == NULL) + return FALSE; /* If we saw any use of an IE model for this symbol, we can then optimize away GOT entries for any TLSDESC_FN relocs. */ @@ -1552,6 +1563,8 @@ elf_xtensa_allocate_local_got_size (struct bfd_link_info *info) bfd *i; htab = elf_xtensa_hash_table (info); + if (htab == NULL) + return; for (i = info->input_bfds; i; i = i->link_next) { @@ -1602,6 +1615,9 @@ elf_xtensa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, plt_chunks = 0; htab = elf_xtensa_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = elf_hash_table (info)->dynobj; if (dynobj == NULL) abort (); @@ -1835,6 +1851,9 @@ elf_xtensa_always_size_sections (bfd *output_bfd, asection *tls_sec; htab = elf_xtensa_hash_table (info); + if (htab == NULL) + return FALSE; + tls_sec = htab->elf.tls_sec; if (tls_sec && (htab->tlsbase->tls_type & GOT_TLS_ANY) != 0) @@ -2546,6 +2565,9 @@ elf_xtensa_relocate_section (bfd *output_bfd, BFD_ASSERT (is_xtensa_elf (input_bfd)); htab = elf_xtensa_hash_table (info); + if (htab == NULL) + return FALSE; + symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; sym_hashes = elf_sym_hashes (input_bfd); local_got_tls_types = elf_xtensa_local_got_tls_type (input_bfd); @@ -3231,6 +3253,9 @@ elf_xtensa_finish_dynamic_sections (bfd *output_bfd, return TRUE; htab = elf_xtensa_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = elf_hash_table (info)->dynobj; sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); BFD_ASSERT (sdyn != NULL); @@ -9495,6 +9520,9 @@ shrink_dynamic_reloc_sections (struct bfd_link_info *info, bfd_boolean dynamic_symbol; htab = elf_xtensa_hash_table (info); + if (htab == NULL) + return; + symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); @@ -10225,6 +10253,9 @@ elf_xtensa_get_plt_section (struct bfd_link_info *info, int chunk) if (chunk == 0) { htab = elf_xtensa_hash_table (info); + if (htab == NULL) + return NULL; + return htab->splt; } @@ -10244,6 +10275,8 @@ elf_xtensa_get_gotplt_section (struct bfd_link_info *info, int chunk) if (chunk == 0) { htab = elf_xtensa_hash_table (info); + if (htab == NULL) + return NULL; return htab->sgotplt; } diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c index 501e2ef5d..649d37087 100644 --- a/bfd/elf64-alpha.c +++ b/bfd/elf64-alpha.c @@ -1,6 +1,6 @@ /* Alpha specific support for 64-bit ELF Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. Contributed by Richard Henderson . This file is part of BFD, the Binary File Descriptor library. @@ -216,7 +216,8 @@ struct alpha_elf_link_hash_table /* Get the Alpha ELF linker hash table from a link_info structure. */ #define alpha_elf_hash_table(p) \ - ((struct alpha_elf_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == ALPHA_ELF_DATA ? ((struct alpha_elf_link_hash_table *) ((p)->hash)) : NULL) /* Get the object's symbols as our own entry type. */ @@ -287,7 +288,8 @@ elf64_alpha_bfd_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, elf64_alpha_link_hash_newfunc, - sizeof (struct alpha_elf_link_hash_entry))) + sizeof (struct alpha_elf_link_hash_entry), + ALPHA_ELF_DATA)) { free (ret); return NULL; @@ -333,13 +335,13 @@ struct alpha_elf_obj_tdata #define is_alpha_elf(bfd) \ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ && elf_tdata (bfd) != NULL \ - && elf_object_id (bfd) == ALPHA_ELF_TDATA) + && elf_object_id (bfd) == ALPHA_ELF_DATA) static bfd_boolean elf64_alpha_mkobject (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct alpha_elf_obj_tdata), - ALPHA_ELF_TDATA); + ALPHA_ELF_DATA); } static bfd_boolean @@ -2322,7 +2324,13 @@ elf64_alpha_calc_got_offsets_for_symbol (struct alpha_elf_link_hash_entry *h, static void elf64_alpha_calc_got_offsets (struct bfd_link_info *info) { - bfd *i, *got_list = alpha_elf_hash_table(info)->got_list; + bfd *i, *got_list; + struct alpha_elf_link_hash_table * htab; + + htab = alpha_elf_hash_table (info); + if (htab == NULL) + return; + got_list = htab->got_list; /* First, zero out the .got sizes, as we may be recalculating the .got after optimizing it. */ @@ -2330,7 +2338,7 @@ elf64_alpha_calc_got_offsets (struct bfd_link_info *info) alpha_elf_tdata(i)->got->size = 0; /* Next, fill in the offsets for all the global entries. */ - alpha_elf_link_hash_traverse (alpha_elf_hash_table (info), + alpha_elf_link_hash_traverse (htab, elf64_alpha_calc_got_offsets_for_symbol, NULL); @@ -2368,8 +2376,12 @@ static bfd_boolean elf64_alpha_size_got_sections (struct bfd_link_info *info) { bfd *i, *got_list, *cur_got_obj = NULL; + struct alpha_elf_link_hash_table * htab; - got_list = alpha_elf_hash_table (info)->got_list; + htab = alpha_elf_hash_table (info); + if (htab == NULL) + return FALSE; + got_list = htab->got_list; /* On the first time through, pretend we have an existing got list consisting of all of the input files. */ @@ -2409,7 +2421,7 @@ elf64_alpha_size_got_sections (struct bfd_link_info *info) if (got_list == NULL) return TRUE; - alpha_elf_hash_table (info)->got_list = got_list; + htab->got_list = got_list; } cur_got_obj = got_list; @@ -2480,6 +2492,11 @@ elf64_alpha_size_plt_section (struct bfd_link_info *info) asection *splt, *spltrel, *sgotplt; unsigned long entries; bfd *dynobj; + struct alpha_elf_link_hash_table * htab; + + htab = alpha_elf_hash_table (info); + if (htab == NULL) + return; dynobj = elf_hash_table(info)->dynobj; splt = bfd_get_section_by_name (dynobj, ".plt"); @@ -2488,7 +2505,7 @@ elf64_alpha_size_plt_section (struct bfd_link_info *info) splt->size = 0; - alpha_elf_link_hash_traverse (alpha_elf_hash_table (info), + alpha_elf_link_hash_traverse (htab, elf64_alpha_size_plt_section_1, splt); /* Every plt entry requires a JMP_SLOT relocation. */ @@ -2518,20 +2535,24 @@ elf64_alpha_always_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) { bfd *i; + struct alpha_elf_link_hash_table * htab; if (info->relocatable) return TRUE; + htab = alpha_elf_hash_table (info); + if (htab == NULL) + return FALSE; + /* First, take care of the indirect symbols created by versioning. */ - alpha_elf_link_hash_traverse (alpha_elf_hash_table (info), - elf64_alpha_merge_ind_symbols, + alpha_elf_link_hash_traverse (htab, elf64_alpha_merge_ind_symbols, NULL); if (!elf64_alpha_size_got_sections (info)) return FALSE; /* Allocate space for all of the .got subsections. */ - i = alpha_elf_hash_table (info)->got_list; + i = htab->got_list; for ( ; i ; i = alpha_elf_tdata(i)->got_link_next) { asection *s = alpha_elf_tdata(i)->got; @@ -2687,12 +2708,17 @@ elf64_alpha_size_rela_got_section (struct bfd_link_info *info) unsigned long entries; bfd *i, *dynobj; asection *srel; + struct alpha_elf_link_hash_table * htab; + + htab = alpha_elf_hash_table (info); + if (htab == NULL) + return; /* Shared libraries often require RELATIVE relocs, and some relocs require attention for the main application as well. */ entries = 0; - for (i = alpha_elf_hash_table(info)->got_list; + for (i = htab->got_list; i ; i = alpha_elf_tdata(i)->got_link_next) { bfd *j; @@ -2725,7 +2751,7 @@ elf64_alpha_size_rela_got_section (struct bfd_link_info *info) srel->size = sizeof (Elf64_External_Rela) * entries; /* Now do the non-local symbols. */ - alpha_elf_link_hash_traverse (alpha_elf_hash_table (info), + alpha_elf_link_hash_traverse (htab, elf64_alpha_size_rela_got_1, info); } @@ -2738,6 +2764,11 @@ elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, bfd *dynobj; asection *s; bfd_boolean relplt; + struct alpha_elf_link_hash_table * htab; + + htab = alpha_elf_hash_table (info); + if (htab == NULL) + return FALSE; dynobj = elf_hash_table(info)->dynobj; BFD_ASSERT(dynobj != NULL); @@ -2757,7 +2788,7 @@ elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, symbols need dynamic relocation entries and which don't. We've collected information in check_relocs that we can now apply to size the dynamic relocation sections. */ - alpha_elf_link_hash_traverse (alpha_elf_hash_table (info), + alpha_elf_link_hash_traverse (htab, elf64_alpha_calc_dynrel_sizes, info); elf64_alpha_size_rela_got_section (info); @@ -3597,6 +3628,11 @@ elf64_alpha_relax_section (bfd *abfd, asection *sec, Elf_Internal_Sym *isymbuf = NULL; struct alpha_elf_got_entry **local_got_entries; struct alpha_relax_info info; + struct alpha_elf_link_hash_table * htab; + + htab = alpha_elf_hash_table (link_info); + if (htab == NULL) + return FALSE; /* There's nothing to change, yet. */ *again = FALSE; @@ -3610,9 +3646,9 @@ elf64_alpha_relax_section (bfd *abfd, asection *sec, BFD_ASSERT (is_alpha_elf (abfd)); /* Make sure our GOT and PLT tables are up-to-date. */ - if (alpha_elf_hash_table(link_info)->relax_trip != link_info->relax_trip) + if (htab->relax_trip != link_info->relax_trip) { - alpha_elf_hash_table(link_info)->relax_trip = link_info->relax_trip; + htab->relax_trip = link_info->relax_trip; /* This should never fail after the initial round, since the only error is GOT overflow, and relaxation only shrinks the table. */ @@ -4933,7 +4969,12 @@ elf64_alpha_final_link (bfd *abfd, struct bfd_link_info *info) const struct ecoff_debug_swap *swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; HDRR *symhdr = &debug.symbolic_header; - PTR mdebug_handle = NULL; + void * mdebug_handle = NULL; + struct alpha_elf_link_hash_table * htab; + + htab = alpha_elf_hash_table (info); + if (htab == NULL) + return FALSE; /* Go through the sections and collect the mdebug information. */ mdebug_sec = NULL; @@ -5088,8 +5129,7 @@ elf64_alpha_final_link (bfd *abfd, struct bfd_link_info *info) continue; name = input_debug.ssext + ext.asym.iss; - h = alpha_elf_link_hash_lookup (alpha_elf_hash_table (info), - name, FALSE, FALSE, TRUE); + h = alpha_elf_link_hash_lookup (htab, name, FALSE, FALSE, TRUE); if (h == NULL || h->esym.ifd != -2) continue; @@ -5153,7 +5193,7 @@ elf64_alpha_final_link (bfd *abfd, struct bfd_link_info *info) /* The .got subsections... */ { bfd *i, *dynobj = elf_hash_table(info)->dynobj; - for (i = alpha_elf_hash_table(info)->got_list; + for (i = htab->got_list; i != NULL; i = alpha_elf_tdata(i)->got_link_next) { diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c index 06a3ae4d1..957e61a00 100644 --- a/bfd/elf64-hppa.c +++ b/bfd/elf64-hppa.c @@ -1,6 +1,6 @@ /* Support for HPPA 64-bit ELF - 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 - Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, + 2010 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -148,7 +148,8 @@ struct elf64_hppa_link_hash_table }; #define hppa_link_hash_table(p) \ - ((struct elf64_hppa_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == HPPA64_ELF_DATA ? ((struct elf64_hppa_link_hash_table *) ((p)->hash)) : NULL) #define hppa_elf_hash_entry(ent) \ ((struct elf64_hppa_link_hash_entry *)(ent)) @@ -303,7 +304,8 @@ elf64_hppa_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&htab->root, abfd, hppa64_link_hash_newfunc, - sizeof (struct elf64_hppa_link_hash_entry))) + sizeof (struct elf64_hppa_link_hash_entry), + HPPA64_ELF_DATA)) { bfd_release (abfd, htab); return NULL; @@ -530,6 +532,8 @@ elf64_hppa_check_relocs (bfd *abfd, } hppa_info = hppa_link_hash_table (info); + if (hppa_info == NULL) + return FALSE; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; /* If necessary, build a new table holding section symbols indices @@ -951,6 +955,8 @@ elf64_hppa_mark_exported_functions (struct elf_link_hash_entry *eh, void *data) struct elf64_hppa_link_hash_table *hppa_info; hppa_info = hppa_link_hash_table (info); + if (hppa_info == NULL) + return FALSE; if (eh->root.type == bfd_link_hash_warning) eh = (struct elf_link_hash_entry *) eh->root.u.i.link; @@ -1012,7 +1018,7 @@ static bfd_boolean allocate_global_data_plt (struct elf_link_hash_entry *eh, void *data) { struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); - struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data; + struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *) data; if (hh->want_plt && elf64_hppa_dynamic_symbol_p (eh, x->info) @@ -1023,7 +1029,15 @@ allocate_global_data_plt (struct elf_link_hash_entry *eh, void *data) hh->plt_offset = x->ofs; x->ofs += PLT_ENTRY_SIZE; if (hh->plt_offset < 0x2000) - hppa_link_hash_table (x->info)->gp_offset = hh->plt_offset; + { + struct elf64_hppa_link_hash_table *hppa_info; + + hppa_info = hppa_link_hash_table (x->info); + if (hppa_info == NULL) + return FALSE; + + hppa_info->gp_offset = hh->plt_offset; + } } else hh->want_plt = 0; @@ -1340,17 +1354,22 @@ elf64_hppa_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) { asection *s; + struct elf64_hppa_link_hash_table *hppa_info; + + hppa_info = hppa_link_hash_table (info); + if (hppa_info == NULL) + return FALSE; - if (! get_stub (abfd, info, hppa_link_hash_table (info))) + if (! get_stub (abfd, info, hppa_info)) return FALSE; - if (! get_dlt (abfd, info, hppa_link_hash_table (info))) + if (! get_dlt (abfd, info, hppa_info)) return FALSE; - if (! get_plt (abfd, info, hppa_link_hash_table (info))) + if (! get_plt (abfd, info, hppa_info)) return FALSE; - if (! get_opd (abfd, info, hppa_link_hash_table (info))) + if (! get_opd (abfd, info, hppa_info)) return FALSE; s = bfd_make_section_with_flags (abfd, ".rela.dlt", @@ -1362,7 +1381,7 @@ elf64_hppa_create_dynamic_sections (bfd *abfd, if (s == NULL || !bfd_set_section_alignment (abfd, s, 3)) return FALSE; - hppa_link_hash_table (info)->dlt_rel_sec = s; + hppa_info->dlt_rel_sec = s; s = bfd_make_section_with_flags (abfd, ".rela.plt", (SEC_ALLOC | SEC_LOAD @@ -1373,7 +1392,7 @@ elf64_hppa_create_dynamic_sections (bfd *abfd, if (s == NULL || !bfd_set_section_alignment (abfd, s, 3)) return FALSE; - hppa_link_hash_table (info)->plt_rel_sec = s; + hppa_info->plt_rel_sec = s; s = bfd_make_section_with_flags (abfd, ".rela.data", (SEC_ALLOC | SEC_LOAD @@ -1384,7 +1403,7 @@ elf64_hppa_create_dynamic_sections (bfd *abfd, if (s == NULL || !bfd_set_section_alignment (abfd, s, 3)) return FALSE; - hppa_link_hash_table (info)->other_rel_sec = s; + hppa_info->other_rel_sec = s; s = bfd_make_section_with_flags (abfd, ".rela.opd", (SEC_ALLOC | SEC_LOAD @@ -1395,7 +1414,7 @@ elf64_hppa_create_dynamic_sections (bfd *abfd, if (s == NULL || !bfd_set_section_alignment (abfd, s, 3)) return FALSE; - hppa_link_hash_table (info)->opd_rel_sec = s; + hppa_info->opd_rel_sec = s; return TRUE; } @@ -1413,6 +1432,9 @@ allocate_dynrel_entries (struct elf_link_hash_entry *eh, void *data) bfd_boolean dynamic_symbol, shared; hppa_info = hppa_link_hash_table (x->info); + if (hppa_info == NULL) + return FALSE; + dynamic_symbol = elf64_hppa_dynamic_symbol_p (eh, x->info); shared = x->info->shared; @@ -1547,6 +1569,8 @@ elf64_hppa_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) bfd_boolean reltext; hppa_info = hppa_link_hash_table (info); + if (hppa_info == NULL) + return FALSE; dynobj = elf_hash_table (info)->dynobj; BFD_ASSERT (dynobj != NULL); @@ -1959,6 +1983,8 @@ elf64_hppa_finish_dynamic_symbol (bfd *output_bfd, struct elf64_hppa_link_hash_table *hppa_info; hppa_info = hppa_link_hash_table (info); + if (hppa_info == NULL) + return FALSE; stub = hppa_info->stub_sec; splt = hppa_info->plt_sec; @@ -2130,6 +2156,9 @@ elf64_hppa_finalize_opd (struct elf_link_hash_entry *eh, void *data) asection *sopdrel; hppa_info = hppa_link_hash_table (info); + if (hppa_info == NULL) + return FALSE; + sopd = hppa_info->opd_sec; sopdrel = hppa_info->opd_rel_sec; @@ -2247,6 +2276,8 @@ elf64_hppa_finalize_dlt (struct elf_link_hash_entry *eh, void *data) asection *sdlt, *sdltrel; hppa_info = hppa_link_hash_table (info); + if (hppa_info == NULL) + return FALSE; sdlt = hppa_info->dlt_sec; sdltrel = hppa_info->dlt_rel_sec; @@ -2350,6 +2381,8 @@ elf64_hppa_finalize_dynreloc (struct elf_link_hash_entry *eh, int dynindx; hppa_info = hppa_link_hash_table (info); + if (hppa_info == NULL) + return FALSE; /* We may need to do a relocation against a local symbol, in which case we have to look up it's dynamic symbol index off @@ -2473,6 +2506,8 @@ elf64_hppa_finish_dynamic_sections (bfd *output_bfd, struct elf64_hppa_link_hash_table *hppa_info; hppa_info = hppa_link_hash_table (info); + if (hppa_info == NULL) + return FALSE; /* Finalize the contents of the .opd section. */ elf_link_hash_traverse (elf_hash_table (info), @@ -2948,6 +2983,9 @@ elf_hppa_final_link (bfd *abfd, struct bfd_link_info *info) bfd_boolean retval; struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info); + if (hppa_info == NULL) + return FALSE; + if (! info->relocatable) { struct elf_link_hash_entry *gp; @@ -3189,6 +3227,9 @@ elf_hppa_final_link_relocate (Elf_Internal_Rela *rel, unsigned int r_type = howto->type; bfd_byte *hit_data = contents + offset; + if (hppa_info == NULL) + return bfd_reloc_notsupported; + symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; local_offsets = elf_local_got_offsets (input_bfd); insn = bfd_get_32 (input_bfd, hit_data); @@ -3812,6 +3853,9 @@ elf64_hppa_relocate_section (bfd *output_bfd, struct elf64_hppa_link_hash_table *hppa_info; hppa_info = hppa_link_hash_table (info); + if (hppa_info == NULL) + return FALSE; + symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; rel = relocs; diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index b44eeabd5..33b26cb46 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -2602,7 +2602,7 @@ struct ppc64_elf_obj_tdata #define is_ppc64_elf(bfd) \ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ - && elf_object_id (bfd) == PPC64_ELF_TDATA) + && elf_object_id (bfd) == PPC64_ELF_DATA) /* Override the generic function because we store some extras. */ @@ -2610,7 +2610,7 @@ static bfd_boolean ppc64_elf_mkobject (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct ppc64_elf_obj_tdata), - PPC64_ELF_TDATA); + PPC64_ELF_DATA); } /* Fix bad default arch selected for a 64 bit input bfd when the @@ -3806,7 +3806,8 @@ struct ppc_link_hash_table /* Get the ppc64 ELF linker hash table from a link_info structure. */ #define ppc_hash_table(p) \ - ((struct ppc_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL) #define ppc_stub_hash_lookup(table, string, create, copy) \ ((struct ppc_stub_hash_entry *) \ @@ -3951,7 +3952,8 @@ ppc64_elf_link_hash_table_create (bfd *abfd) return NULL; if (!_bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc, - sizeof (struct ppc_link_hash_entry))) + sizeof (struct ppc_link_hash_entry), + PPC64_ELF_DATA)) { free (htab); return NULL; @@ -4008,6 +4010,8 @@ ppc64_elf_init_stub_bfd (bfd *abfd, struct bfd_link_info *info) linker created stub bfd. This ensures that the GOT header is at the start of the output TOC section. */ htab = ppc_hash_table (info); + if (htab == NULL) + return; htab->stub_bfd = abfd; htab->elf.dynobj = abfd; } @@ -4167,6 +4171,8 @@ create_linkage_sections (bfd *dynobj, struct bfd_link_info *info) flagword flags; htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; /* Create .sfpr for code to save and restore fp regs. */ flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY @@ -4235,6 +4241,8 @@ create_got_section (bfd *abfd, struct bfd_link_info *info) if (!is_ppc64_elf (abfd)) return FALSE; + if (htab == NULL) + return FALSE; if (!htab->got) { @@ -4276,6 +4284,9 @@ ppc64_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) return FALSE; htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; + if (!htab->got) htab->got = bfd_get_section_by_name (dynobj, ".got"); htab->plt = bfd_get_section_by_name (dynobj, ".plt"); @@ -4608,6 +4619,9 @@ add_symbol_adjust (struct ppc_link_hash_entry *eh, struct bfd_link_info *info) abort (); htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; + fdh = lookup_fdh (eh, htab); if (fdh == NULL) { @@ -4655,9 +4669,11 @@ ppc64_elf_process_dot_syms (bfd *ibfd, struct bfd_link_info *info) struct ppc_link_hash_table *htab; struct ppc_link_hash_entry **p, *eh; - htab = ppc_hash_table (info); if (!is_ppc64_elf (info->output_bfd)) return TRUE; + htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; if (is_ppc64_elf (ibfd)) { @@ -4696,7 +4712,12 @@ static bfd_boolean ppc64_elf_as_needed_cleanup (bfd *ibfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) { - ppc_hash_table (info)->dot_syms = NULL; + struct ppc_link_hash_table *htab = ppc_hash_table (info); + + if (htab == NULL) + return FALSE; + + htab->dot_syms = NULL; return TRUE; } @@ -4822,6 +4843,9 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, BFD_ASSERT (is_ppc64_elf (abfd)); htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; + tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr", FALSE, FALSE, TRUE); dottga = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr", @@ -5547,6 +5571,9 @@ ppc64_elf_gc_keep (struct bfd_link_info *info) struct ppc_link_hash_table *htab = ppc_hash_table (info); struct bfd_sym_chain *sym; + if (htab == NULL) + return; + for (sym = info->gc_sym_list; sym != NULL; sym = sym->next) { struct ppc_link_hash_entry *eh, *fh; @@ -5734,6 +5761,9 @@ ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, elf_section_data (sec)->local_dynrel = NULL; htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_ents = elf_local_got_ents (abfd); @@ -5897,7 +5927,7 @@ struct sfpr_def_parms /* Auto-generate _save*, _rest* functions in .sfpr. */ -static unsigned int +static bfd_boolean sfpr_define (struct bfd_link_info *info, const struct sfpr_def_parms *parm) { struct ppc_link_hash_table *htab = ppc_hash_table (info); @@ -5906,6 +5936,9 @@ sfpr_define (struct bfd_link_info *info, const struct sfpr_def_parms *parm) bfd_boolean writing = FALSE; char sym[16]; + if (htab == NULL) + return FALSE; + memcpy (sym, parm->name, len); sym[len + 2] = 0; @@ -6132,6 +6165,8 @@ func_desc_adjust (struct elf_link_hash_entry *h, void *inf) info = inf; htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; /* Resolve undefined references to dot-symbols as the value in the function descriptor, if we have one in a regular object. @@ -6270,6 +6305,9 @@ ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED, }; htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; + if (htab->sfpr == NULL) /* We don't have any relocs. */ return TRUE; @@ -6302,6 +6340,8 @@ ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info, asection *s; htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; /* Deal with function syms. */ if (h->type == STT_FUNC @@ -6461,6 +6501,9 @@ ppc64_elf_hide_symbol (struct bfd_link_info *info, save = *p; *(char *) p = '.'; htab = ppc_hash_table (info); + if (htab == NULL) + return; + fh = (struct ppc_link_hash_entry *) elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE); *(char *) p = save; @@ -7074,8 +7117,12 @@ ppc64_elf_edit_opd (bfd *obfd, struct bfd_link_info *info, if (h != NULL && h->root.root.string[0] == '.') { - fdh = lookup_fdh ((struct ppc_link_hash_entry *) h, - ppc_hash_table (info)); + struct ppc_link_hash_table *htab; + + htab = ppc_hash_table (info); + if (htab != NULL) + fdh = lookup_fdh ((struct ppc_link_hash_entry *) h, + htab); if (fdh != NULL && fdh->elf.root.type != bfd_link_hash_defined && fdh->elf.root.type != bfd_link_hash_defweak) @@ -7232,6 +7279,9 @@ ppc64_elf_tls_setup (bfd *obfd, struct ppc_link_hash_table *htab; htab = ppc_hash_table (info); + if (htab == NULL) + return NULL; + htab->tls_get_addr = ((struct ppc_link_hash_entry *) elf_link_hash_lookup (&htab->elf, ".__tls_get_addr", FALSE, FALSE, TRUE)); @@ -7360,6 +7410,9 @@ ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) return TRUE; htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) { Elf_Internal_Sym *locsyms = NULL; @@ -8239,6 +8292,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) info = (struct bfd_link_info *) inf; htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; if ((htab->elf.dynamic_sections_created && h->dynindx != -1 @@ -8497,6 +8552,9 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, bfd *ibfd; htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->elf.dynobj; if (dynobj == NULL) abort (); @@ -9067,6 +9125,8 @@ ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) info = in_arg; htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; /* Make a note of the offset within the stubs for this entry. */ stub_entry->stub_offset = stub_entry->stub_sec->size; @@ -9463,6 +9523,8 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) info = in_arg; htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; if (stub_entry->stub_type == ppc_stub_plt_call) { @@ -9614,6 +9676,8 @@ ppc64_elf_setup_section_lists bfd_size_type amt; struct ppc_link_hash_table *htab = ppc_hash_table (info); + if (htab == NULL) + return -1; /* Stash our params away. */ htab->add_stub_section = add_stub_section; htab->layout_sections_again = layout_sections_again; @@ -9689,6 +9753,9 @@ ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec) struct ppc_link_hash_table *htab = ppc_hash_table (info); bfd_vma addr, off; + if (htab == NULL) + return FALSE; + if (!htab->second_toc_pass) { /* Keep track of the first .toc or .got section for this input bfd. */ @@ -10019,6 +10086,9 @@ ppc64_elf_finish_multitoc_partition (struct bfd_link_info *info) { struct ppc_link_hash_table *htab = ppc_hash_table (info); + if (htab == NULL) + return; + /* After the second pass, toc_curr tracks the TOC offset used for code sections below in ppc64_elf_next_input_section. */ htab->toc_curr = TOC_BASE_OFF; @@ -10062,6 +10132,9 @@ toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec) local_syms = NULL; ret = 0; htab = ppc_hash_table (info); + if (htab == NULL) + return -1; + for (rel = relstart; rel < relstart + isec->reloc_count; ++rel) { enum elf_ppc64_reloc_type r_type; @@ -10234,6 +10307,9 @@ ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec) { struct ppc_link_hash_table *htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; + if ((isec->output_section->flags & SEC_CODE) != 0 && isec->output_section->index <= htab->top_index) { @@ -10399,6 +10475,9 @@ ppc64_elf_size_stubs (struct bfd_link_info *info, bfd_signed_vma group_size) bfd_boolean stubs_always_before_branch; struct ppc_link_hash_table *htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; + stubs_always_before_branch = group_size < 0; if (group_size < 0) stub_group_size = -group_size; @@ -10820,6 +10899,9 @@ ppc64_elf_build_stubs (bfd_boolean emit_stub_syms, bfd_byte *p; int stub_sec_count = 0; + if (htab == NULL) + return FALSE; + htab->emit_stub_syms = emit_stub_syms; /* Allocate memory to hold the linker stubs. */ @@ -11019,7 +11101,9 @@ void ppc64_elf_restore_symbols (struct bfd_link_info *info) { struct ppc_link_hash_table *htab = ppc_hash_table (info); - elf_link_hash_traverse (&htab->elf, undo_symbol_twiddle, info); + + if (htab != NULL) + elf_link_hash_traverse (&htab->elf, undo_symbol_twiddle, info); } /* What to do when ld finds relocations against symbols defined in @@ -11099,6 +11183,8 @@ ppc64_elf_relocate_section (bfd *output_bfd, ppc_howto_init (); htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; /* Don't relocate stub sections. */ if (input_section->owner == htab->stub_bfd) @@ -12708,6 +12794,8 @@ ppc64_elf_finish_dynamic_symbol (bfd *output_bfd, bfd_byte *loc; htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; for (ent = h->plt.plist; ent != NULL; ent = ent->next) if (ent->plt.offset != (bfd_vma) -1) @@ -12807,6 +12895,9 @@ ppc64_elf_finish_dynamic_sections (bfd *output_bfd, asection *sdyn; htab = ppc_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->elf.dynobj; sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c index fbe86683a..e994e4610 100644 --- a/bfd/elf64-s390.c +++ b/bfd/elf64-s390.c @@ -1,6 +1,6 @@ /* IBM S/390-specific support for 64-bit ELF - Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 - Free Software Foundation, Inc. + Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, + 2010 Free Software Foundation, Inc. Contributed Martin Schwidefsky (schwidefsky@de.ibm.com). This file is part of BFD, the Binary File Descriptor library. @@ -648,13 +648,13 @@ struct elf_s390_obj_tdata #define is_s390_elf(bfd) \ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ && elf_tdata (bfd) != NULL \ - && elf_object_id (bfd) == S390_ELF_TDATA) + && elf_object_id (bfd) == S390_ELF_DATA) static bfd_boolean elf_s390_mkobject (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct elf_s390_obj_tdata), - S390_ELF_TDATA); + S390_ELF_DATA); } static bfd_boolean @@ -692,7 +692,8 @@ struct elf_s390_link_hash_table /* Get the s390 ELF linker hash table from a link_info structure. */ #define elf_s390_hash_table(p) \ - ((struct elf_s390_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == S390_ELF_DATA ? ((struct elf_s390_link_hash_table *) ((p)->hash)) : NULL) /* Create an entry in an s390 ELF linker hash table. */ @@ -741,7 +742,8 @@ elf_s390_link_hash_table_create (abfd) return NULL; if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc, - sizeof (struct elf_s390_link_hash_entry))) + sizeof (struct elf_s390_link_hash_entry), + S390_ELF_DATA)) { free (ret); return NULL; @@ -764,9 +766,8 @@ elf_s390_link_hash_table_create (abfd) shortcuts to them in our hash table. */ static bfd_boolean -create_got_section (dynobj, info) - bfd *dynobj; - struct bfd_link_info *info; +create_got_section (bfd *dynobj, + struct bfd_link_info *info) { struct elf_s390_link_hash_table *htab; @@ -774,6 +775,9 @@ create_got_section (dynobj, info) return FALSE; htab = elf_s390_hash_table (info); + if (htab == NULL) + return FALSE; + htab->sgot = bfd_get_section_by_name (dynobj, ".got"); htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); htab->srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); @@ -787,13 +791,15 @@ create_got_section (dynobj, info) hash table. */ static bfd_boolean -elf_s390_create_dynamic_sections (dynobj, info) - bfd *dynobj; - struct bfd_link_info *info; +elf_s390_create_dynamic_sections (bfd *dynobj, + struct bfd_link_info *info) { struct elf_s390_link_hash_table *htab; htab = elf_s390_hash_table (info); + if (htab == NULL) + return FALSE; + if (!htab->sgot && !create_got_section (dynobj, info)) return FALSE; @@ -911,11 +917,10 @@ elf_s390_tls_transition (info, r_type, is_local) table. */ static bfd_boolean -elf_s390_check_relocs (abfd, info, sec, relocs) - bfd *abfd; - struct bfd_link_info *info; - asection *sec; - const Elf_Internal_Rela *relocs; +elf_s390_check_relocs (bfd *abfd, + struct bfd_link_info *info, + asection *sec, + const Elf_Internal_Rela *relocs) { struct elf_s390_link_hash_table *htab; Elf_Internal_Shdr *symtab_hdr; @@ -932,6 +937,9 @@ elf_s390_check_relocs (abfd, info, sec, relocs) BFD_ASSERT (is_s390_elf (abfd)); htab = elf_s390_hash_table (info); + if (htab == NULL) + return FALSE; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_refcounts = elf_local_got_refcounts (abfd); @@ -1353,6 +1361,7 @@ elf_s390_gc_sweep_hook (bfd *abfd, asection *sec, const Elf_Internal_Rela *relocs) { + struct elf_s390_link_hash_table *htab; Elf_Internal_Shdr *symtab_hdr; struct elf_link_hash_entry **sym_hashes; bfd_signed_vma *local_got_refcounts; @@ -1361,6 +1370,10 @@ elf_s390_gc_sweep_hook (bfd *abfd, if (info->relocatable) return TRUE; + htab = elf_s390_hash_table (info); + if (htab == NULL) + return FALSE; + elf_section_data (sec)->local_dynrel = NULL; symtab_hdr = &elf_symtab_hdr (abfd); @@ -1401,8 +1414,8 @@ elf_s390_gc_sweep_hook (bfd *abfd, switch (r_type) { case R_390_TLS_LDM64: - if (elf_s390_hash_table (info)->tls_ldm_got.refcount > 0) - elf_s390_hash_table (info)->tls_ldm_got.refcount -= 1; + if (htab->tls_ldm_got.refcount > 0) + htab->tls_ldm_got.refcount -= 1; break; case R_390_TLS_GD64: @@ -1522,9 +1535,8 @@ elf_s390_adjust_gotplt (h) understand. */ static bfd_boolean -elf_s390_adjust_dynamic_symbol (info, h) - struct bfd_link_info *info; - struct elf_link_hash_entry *h; +elf_s390_adjust_dynamic_symbol (struct bfd_link_info *info, + struct elf_link_hash_entry *h) { struct elf_s390_link_hash_table *htab; asection *s; @@ -1636,6 +1648,8 @@ elf_s390_adjust_dynamic_symbol (info, h) same memory location for the variable. */ htab = elf_s390_hash_table (info); + if (htab == NULL) + return FALSE; /* We must generate a R_390_COPY reloc to tell the dynamic linker to copy the initial value out of the dynamic object and into the @@ -1655,9 +1669,8 @@ elf_s390_adjust_dynamic_symbol (info, h) dynamic relocs. */ static bfd_boolean -allocate_dynrelocs (h, inf) - struct elf_link_hash_entry *h; - PTR inf; +allocate_dynrelocs (struct elf_link_hash_entry *h, + void * inf) { struct bfd_link_info *info; struct elf_s390_link_hash_table *htab; @@ -1675,6 +1688,8 @@ allocate_dynrelocs (h, inf) info = (struct bfd_link_info *) inf; htab = elf_s390_hash_table (info); + if (htab == NULL) + return FALSE; if (htab->elf.dynamic_sections_created && h->plt.refcount > 0) @@ -1916,9 +1931,8 @@ readonly_dynrelocs (h, inf) /* Set the sizes of the dynamic sections. */ static bfd_boolean -elf_s390_size_dynamic_sections (output_bfd, info) - bfd *output_bfd ATTRIBUTE_UNUSED; - struct bfd_link_info *info; +elf_s390_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, + struct bfd_link_info *info) { struct elf_s390_link_hash_table *htab; bfd *dynobj; @@ -1927,6 +1941,9 @@ elf_s390_size_dynamic_sections (output_bfd, info) bfd *ibfd; htab = elf_s390_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->elf.dynobj; if (dynobj == NULL) abort (); @@ -2187,16 +2204,14 @@ invalid_tls_insn (input_bfd, input_section, rel) /* Relocate a 390 ELF section. */ static bfd_boolean -elf_s390_relocate_section (output_bfd, info, input_bfd, input_section, - contents, relocs, local_syms, local_sections) - bfd *output_bfd; - struct bfd_link_info *info; - bfd *input_bfd; - asection *input_section; - bfd_byte *contents; - Elf_Internal_Rela *relocs; - Elf_Internal_Sym *local_syms; - asection **local_sections; +elf_s390_relocate_section (bfd *output_bfd, + struct bfd_link_info *info, + bfd *input_bfd, + asection *input_section, + bfd_byte *contents, + Elf_Internal_Rela *relocs, + Elf_Internal_Sym *local_syms, + asection **local_sections) { struct elf_s390_link_hash_table *htab; Elf_Internal_Shdr *symtab_hdr; @@ -2208,6 +2223,9 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section, BFD_ASSERT (is_s390_elf (input_bfd)); htab = elf_s390_hash_table (info); + if (htab == NULL) + return FALSE; + symtab_hdr = &elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); local_got_offsets = elf_local_got_offsets (input_bfd); @@ -3038,15 +3056,16 @@ elf_s390_relocate_section (output_bfd, info, input_bfd, input_section, dynamic sections here. */ static bfd_boolean -elf_s390_finish_dynamic_symbol (output_bfd, info, h, sym) - bfd *output_bfd; - struct bfd_link_info *info; - struct elf_link_hash_entry *h; - Elf_Internal_Sym *sym; +elf_s390_finish_dynamic_symbol (bfd *output_bfd, + struct bfd_link_info *info, + struct elf_link_hash_entry *h, + Elf_Internal_Sym *sym) { struct elf_s390_link_hash_table *htab; htab = elf_s390_hash_table (info); + if (htab == NULL) + return FALSE; if (h->plt.offset != (bfd_vma) -1) { @@ -3233,15 +3252,17 @@ elf_s390_reloc_type_class (rela) /* Finish up the dynamic sections. */ static bfd_boolean -elf_s390_finish_dynamic_sections (output_bfd, info) - bfd *output_bfd; - struct bfd_link_info *info; +elf_s390_finish_dynamic_sections (bfd *output_bfd, + struct bfd_link_info *info) { struct elf_s390_link_hash_table *htab; bfd *dynobj; asection *sdyn; htab = elf_s390_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->elf.dynobj; sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); diff --git a/bfd/elf64-sh64.c b/bfd/elf64-sh64.c index 478197df1..d045d90c6 100644 --- a/bfd/elf64-sh64.c +++ b/bfd/elf64-sh64.c @@ -1,6 +1,6 @@ /* SuperH SH64-specific support for 64-bit ELF - Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 - Free Software Foundation, Inc. + Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, + 2010 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -89,26 +89,14 @@ struct elf_sh64_link_hash_entry struct elf_sh64_pcrel_relocs_copied *pcrel_relocs_copied; }; -/* sh ELF linker hash table. */ - -struct elf_sh64_link_hash_table -{ - struct elf_link_hash_table root; -}; - /* Traverse an sh ELF linker hash table. */ -#define sh64_elf64_link_hash_traverse(table, func, info) \ - (elf_link_hash_traverse \ - (&(table)->root, \ +#define sh64_elf64_link_hash_traverse(table, func, info) \ + (elf_link_hash_traverse \ + ((table), \ (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ (info))) -/* Get the sh ELF linker hash table from a link_info structure. */ - -#define sh64_elf64_hash_table(p) \ - ((struct elf_sh64_link_hash_table *) ((p)->hash)) - static bfd_reloc_status_type sh_elf64_ignore_reloc (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); static bfd_reloc_status_type sh_elf64_reloc @@ -3084,22 +3072,22 @@ sh64_elf64_link_hash_newfunc (struct bfd_hash_entry *entry, static struct bfd_link_hash_table * sh64_elf64_link_hash_table_create (bfd *abfd) { - struct elf_sh64_link_hash_table *ret; + struct elf_link_hash_table *ret; - ret = ((struct elf_sh64_link_hash_table *) - bfd_malloc (sizeof (struct elf_sh64_link_hash_table))); - if (ret == (struct elf_sh64_link_hash_table *) NULL) + ret = (struct elf_link_hash_table *) bfd_malloc (sizeof (* ret)); + if (ret == (struct elf_link_hash_table *) NULL) return NULL; - if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, + if (!_bfd_elf_link_hash_table_init (ret, abfd, sh64_elf64_link_hash_newfunc, - sizeof (struct elf_sh64_link_hash_entry))) + sizeof (struct elf_sh64_link_hash_entry), + GENERIC_ELF_DATA)) { free (ret); return NULL; } - return &ret->root.root; + return &ret->root; } inline static void @@ -3497,7 +3485,7 @@ sh64_elf64_size_dynamic_sections (bfd *output_bfd, We allocated space for them in the check_relocs routine, but we will not fill them in in the relocate_section routine. */ if (info->shared && info->symbolic) - sh64_elf64_link_hash_traverse (sh64_elf64_hash_table (info), + sh64_elf64_link_hash_traverse (elf_hash_table (info), sh64_elf64_discard_copies, NULL); /* The check_relocs and adjust_dynamic_symbol entry points have diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index e6b1f111d..373cab82b 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -1,6 +1,6 @@ /* X86-64 specific support for 64-bit ELF - Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 - Free Software Foundation, Inc. + Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, + 2010 Free Software Foundation, Inc. Contributed by Jan Hubicka . This file is part of BFD, the Binary File Descriptor library. @@ -451,13 +451,13 @@ struct elf64_x86_64_obj_tdata #define is_x86_64_elf(bfd) \ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ && elf_tdata (bfd) != NULL \ - && elf_object_id (bfd) == X86_64_ELF_TDATA) + && elf_object_id (bfd) == X86_64_ELF_DATA) static bfd_boolean elf64_x86_64_mkobject (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct elf64_x86_64_obj_tdata), - X86_64_ELF_TDATA); + X86_64_ELF_DATA); } /* x86-64 ELF linker hash table. */ @@ -470,16 +470,8 @@ struct elf64_x86_64_link_hash_table asection *sdynbss; asection *srelbss; - /* The offset into splt of the PLT entry for the TLS descriptor - resolver. Special values are 0, if not necessary (or not found - to be necessary yet), and -1 if needed but not determined - yet. */ - bfd_vma tlsdesc_plt; - /* The offset into sgot of the GOT entry used by the PLT entry - above. */ - bfd_vma tlsdesc_got; - - union { + union + { bfd_signed_vma refcount; bfd_vma offset; } tls_ld_got; @@ -495,13 +487,23 @@ struct elf64_x86_64_link_hash_table /* Used by local STT_GNU_IFUNC symbols. */ htab_t loc_hash_table; - void *loc_hash_memory; + void * loc_hash_memory; + + /* The offset into splt of the PLT entry for the TLS descriptor + resolver. Special values are 0, if not necessary (or not found + to be necessary yet), and -1 if needed but not determined + yet. */ + bfd_vma tlsdesc_plt; + /* The offset into sgot of the GOT entry used by the PLT entry + above. */ + bfd_vma tlsdesc_got; }; /* Get the x86-64 ELF linker hash table from a link_info structure. */ #define elf64_x86_64_hash_table(p) \ - ((struct elf64_x86_64_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == X86_64_ELF_DATA ? ((struct elf64_x86_64_link_hash_table *) ((p)->hash)) : NULL) #define elf64_x86_64_compute_jump_table_size(htab) \ ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE) @@ -622,7 +624,8 @@ elf64_x86_64_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, elf64_x86_64_link_hash_newfunc, - sizeof (struct elf64_x86_64_link_hash_entry))) + sizeof (struct elf64_x86_64_link_hash_entry), + X86_64_ELF_DATA)) { free (ret); return NULL; @@ -636,7 +639,7 @@ elf64_x86_64_link_hash_table_create (bfd *abfd) ret->tls_ld_got.refcount = 0; ret->sgotplt_jump_table_size = 0; ret->tls_module_base = NULL; - + ret->loc_hash_table = htab_try_create (1024, elf64_x86_64_local_htab_hash, elf64_x86_64_local_htab_eq, @@ -679,6 +682,9 @@ elf64_x86_64_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) return FALSE; htab = elf64_x86_64_hash_table (info); + if (htab == NULL) + return FALSE; + htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); if (!info->shared) htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss"); @@ -1018,12 +1024,19 @@ elf64_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd, name = h->root.root.string; else { - Elf_Internal_Sym *isym; struct elf64_x86_64_link_hash_table *htab; + htab = elf64_x86_64_hash_table (info); - isym = bfd_sym_from_r_symndx (&htab->sym_cache, - abfd, r_symndx); - name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL); + if (htab == NULL) + name = "*unknown*"; + else + { + Elf_Internal_Sym *isym; + + isym = bfd_sym_from_r_symndx (&htab->sym_cache, + abfd, r_symndx); + name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL); + } } (*_bfd_error_handler) @@ -1061,6 +1074,9 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info, BFD_ASSERT (is_x86_64_elf (abfd)); htab = elf64_x86_64_hash_table (info); + if (htab == NULL) + return FALSE; + symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); @@ -1594,6 +1610,7 @@ elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, asection *sec, const Elf_Internal_Rela *relocs) { + struct elf64_x86_64_link_hash_table *htab; Elf_Internal_Shdr *symtab_hdr; struct elf_link_hash_entry **sym_hashes; bfd_signed_vma *local_got_refcounts; @@ -1602,6 +1619,10 @@ elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, if (info->relocatable) return TRUE; + htab = elf64_x86_64_hash_table (info); + if (htab == NULL) + return FALSE; + elf_section_data (sec)->local_dynrel = NULL; symtab_hdr = &elf_symtab_hdr (abfd); @@ -1647,8 +1668,8 @@ elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, switch (r_type) { case R_X86_64_TLSLD: - if (elf64_x86_64_hash_table (info)->tls_ld_got.refcount > 0) - elf64_x86_64_hash_table (info)->tls_ld_got.refcount -= 1; + if (htab->tls_ld_got.refcount > 0) + htab->tls_ld_got.refcount -= 1; break; case R_X86_64_TLSGD: @@ -1834,6 +1855,8 @@ elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info, same memory location for the variable. */ htab = elf64_x86_64_hash_table (info); + if (htab == NULL) + return FALSE; /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker to copy the initial value out of the dynamic object and into the @@ -1869,6 +1892,8 @@ elf64_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) info = (struct bfd_link_info *) inf; htab = elf64_x86_64_hash_table (info); + if (htab == NULL) + return FALSE; /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it here if it is defined and referenced in a non-shared object. */ @@ -2159,6 +2184,9 @@ elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, bfd *ibfd; htab = elf64_x86_64_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->elf.dynobj; if (dynobj == NULL) abort (); @@ -2454,17 +2482,22 @@ elf64_x86_64_always_size_sections (bfd *output_bfd, if (tlsbase && tlsbase->type == STT_TLS) { + struct elf64_x86_64_link_hash_table *htab; struct bfd_link_hash_entry *bh = NULL; const struct elf_backend_data *bed = get_elf_backend_data (output_bfd); + htab = elf64_x86_64_hash_table (info); + if (htab == NULL) + return FALSE; + if (!(_bfd_generic_link_add_one_symbol (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL, tls_sec, 0, NULL, FALSE, bed->collect, &bh))) return FALSE; - elf64_x86_64_hash_table (info)->tls_module_base = bh; + htab->tls_module_base = bh; tlsbase = (struct elf_link_hash_entry *)bh; tlsbase->def_regular = 1; @@ -2484,17 +2517,21 @@ elf64_x86_64_always_size_sections (bfd *output_bfd, static void elf64_x86_64_set_tls_module_base (struct bfd_link_info *info) { + struct elf64_x86_64_link_hash_table *htab; struct bfd_link_hash_entry *base; if (!info->executable) return; - base = elf64_x86_64_hash_table (info)->tls_module_base; + htab = elf64_x86_64_hash_table (info); + if (htab == NULL) + return; - if (!base) + base = htab->tls_module_base; + if (base == NULL) return; - base->u.def.value = elf_hash_table (info)->tls_size; + base->u.def.value = htab->elf.tls_size; } /* Return the base VMA address which should be subtracted from real addresses @@ -2572,6 +2609,8 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info, BFD_ASSERT (is_x86_64_elf (input_bfd)); htab = elf64_x86_64_hash_table (info); + if (htab == NULL) + return FALSE; symtab_hdr = &elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); local_got_offsets = elf_local_got_offsets (input_bfd); @@ -3702,6 +3741,8 @@ elf64_x86_64_finish_dynamic_symbol (bfd *output_bfd, struct elf64_x86_64_link_hash_table *htab; htab = elf64_x86_64_hash_table (info); + if (htab == NULL) + return FALSE; if (h->plt.offset != (bfd_vma) -1) { @@ -3981,6 +4022,9 @@ elf64_x86_64_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *inf asection *sdyn; htab = elf64_x86_64_hash_table (info); + if (htab == NULL) + return FALSE; + dynobj = htab->elf.dynobj; sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); diff --git a/bfd/elflink.c b/bfd/elflink.c index cca2d53ff..a325c00ca 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -6782,7 +6782,8 @@ _bfd_elf_link_hash_table_init struct bfd_hash_entry *(*newfunc) (struct bfd_hash_entry *, struct bfd_hash_table *, const char *), - unsigned int entsize) + unsigned int entsize, + enum elf_target_id target_id) { bfd_boolean ret; int can_refcount = get_elf_backend_data (abfd)->can_refcount; @@ -6796,7 +6797,9 @@ _bfd_elf_link_hash_table_init table->dynsymcount = 1; ret = _bfd_link_hash_table_init (&table->root, abfd, newfunc, entsize); + table->root.type = bfd_link_elf_hash_table; + table->hash_table_id = target_id; return ret; } @@ -6814,7 +6817,8 @@ _bfd_elf_link_hash_table_create (bfd *abfd) return NULL; if (! _bfd_elf_link_hash_table_init (ret, abfd, _bfd_elf_link_hash_newfunc, - sizeof (struct elf_link_hash_entry))) + sizeof (struct elf_link_hash_entry), + GENERIC_ELF_DATA)) { free (ret); return NULL; diff --git a/bfd/elfxx-ia64.c b/bfd/elfxx-ia64.c index f7563329d..e35fcbf8f 100644 --- a/bfd/elfxx-ia64.c +++ b/bfd/elfxx-ia64.c @@ -1,6 +1,6 @@ /* IA-64 support for 64-bit ELF Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, - 2008, 2009 Free Software Foundation, Inc. + 2008, 2009, 2010 Free Software Foundation, Inc. Contributed by David Mosberger-Tang This file is part of BFD, the Binary File Descriptor library. @@ -70,7 +70,7 @@ #define NELEMS(a) ((int) (sizeof (a) / sizeof ((a)[0]))) typedef struct bfd_hash_entry *(*new_hash_entry_func) - PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); + (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); /* In dynamically (linker-) created sections, we generally need to keep track of the place a symbol or expression got allocated to. This is done via hash @@ -163,23 +163,23 @@ struct elfNN_ia64_link_hash_table /* The main hash table. */ struct elf_link_hash_table root; - asection *fptr_sec; /* function descriptor table (or NULL) */ - asection *rel_fptr_sec; /* dynamic relocation section for same */ - asection *pltoff_sec; /* private descriptors for plt (or NULL) */ - asection *rel_pltoff_sec; /* dynamic relocation section for same */ + asection *fptr_sec; /* Function descriptor table (or NULL). */ + asection *rel_fptr_sec; /* Dynamic relocation section for same. */ + asection *pltoff_sec; /* Private descriptors for plt (or NULL). */ + asection *rel_pltoff_sec; /* Dynamic relocation section for same. */ - bfd_size_type minplt_entries; /* number of minplt entries */ - unsigned reltext : 1; /* are there relocs against readonly sections? */ - unsigned self_dtpmod_done : 1;/* has self DTPMOD entry been finished? */ - bfd_vma self_dtpmod_offset; /* .got offset to self DTPMOD entry */ + bfd_size_type minplt_entries; /* Number of minplt entries. */ + unsigned reltext : 1; /* Are there relocs against readonly sections? */ + unsigned self_dtpmod_done : 1;/* Has self DTPMOD entry been finished? */ + bfd_vma self_dtpmod_offset; /* .got offset to self DTPMOD entry. */ /* There are maybe R_IA64_GPREL22 relocations, including those optimized from R_IA64_LTOFF22X, against non-SHF_IA_64_SHORT sections. We need to record those sections so that we can choose a proper GP to cover all R_IA64_GPREL22 relocations. */ - asection *max_short_sec; /* maximum short output section */ - bfd_vma max_short_offset; /* maximum short offset */ - asection *min_short_sec; /* minimum short output section */ - bfd_vma min_short_offset; /* minimum short offset */ + asection *max_short_sec; /* Maximum short output section. */ + bfd_vma max_short_offset; /* Maximum short offset. */ + asection *min_short_sec; /* Minimum short output section. */ + bfd_vma min_short_offset; /* Minimum short offset. */ htab_t loc_hash_table; void *loc_hash_memory; @@ -193,7 +193,8 @@ struct elfNN_ia64_allocate_data }; #define elfNN_ia64_hash_table(p) \ - ((struct elfNN_ia64_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == IA64_ELF_DATA ? ((struct elfNN_ia64_link_hash_table *) ((p)->hash)) : NULL) static struct elfNN_ia64_dyn_sym_info * get_dyn_sym_info (struct elfNN_ia64_link_hash_table *ia64_info, @@ -843,16 +844,19 @@ elfNN_ia64_relax_section (bfd *abfd, asection *sec, || (link_info->relax_pass == 1 && sec->skip_relax_pass_1)) return TRUE; + ia64_info = elfNN_ia64_hash_table (link_info); + if (ia64_info == NULL) + return FALSE; + symtab_hdr = &elf_tdata (abfd)->symtab_hdr; /* Load the relocations for this section. */ internal_relocs = (_bfd_elf_link_read_relocs - (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL, + (abfd, sec, NULL, (Elf_Internal_Rela *) NULL, link_info->keep_memory)); if (internal_relocs == NULL) return FALSE; - ia64_info = elfNN_ia64_hash_table (link_info); irelend = internal_relocs + sec->reloc_count; /* Get the section contents. */ @@ -1884,21 +1888,22 @@ elfNN_ia64_local_htab_eq (const void *ptr1, const void *ptr2) derived hash table to keep information specific to the IA-64 ElF linker (without using static variables). */ -static struct bfd_link_hash_table* +static struct bfd_link_hash_table * elfNN_ia64_hash_table_create (bfd *abfd) { struct elfNN_ia64_link_hash_table *ret; ret = bfd_zmalloc ((bfd_size_type) sizeof (*ret)); if (!ret) - return 0; + return NULL; if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, elfNN_ia64_new_elf_hash_entry, - sizeof (struct elfNN_ia64_link_hash_entry))) + sizeof (struct elfNN_ia64_link_hash_entry), + IA64_ELF_DATA)) { free (ret); - return 0; + return NULL; } ret->loc_hash_table = htab_try_create (1024, elfNN_ia64_local_htab_hash, @@ -1907,7 +1912,7 @@ elfNN_ia64_hash_table_create (bfd *abfd) if (!ret->loc_hash_table || !ret->loc_hash_memory) { free (ret); - return 0; + return NULL; } return &ret->root.root; @@ -2053,6 +2058,8 @@ elfNN_ia64_create_dynamic_sections (bfd *abfd, return FALSE; ia64_info = elfNN_ia64_hash_table (info); + if (ia64_info == NULL) + return FALSE; { flagword flags = bfd_get_section_flags (abfd, ia64_info->root.sgot); @@ -2680,6 +2687,8 @@ elfNN_ia64_check_relocs (bfd *abfd, struct bfd_link_info *info, symtab_hdr = &elf_tdata (abfd)->symtab_hdr; ia64_info = elfNN_ia64_hash_table (info); + if (ia64_info == NULL) + return FALSE; got = fptr = srel = pltoff = NULL; @@ -3107,7 +3116,7 @@ elfNN_ia64_check_relocs (bfd *abfd, struct bfd_link_info *info, static bfd_boolean allocate_global_data_got (struct elfNN_ia64_dyn_sym_info *dyn_i, - PTR data) + void * data) { struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; @@ -3135,6 +3144,9 @@ allocate_global_data_got (struct elfNN_ia64_dyn_sym_info *dyn_i, struct elfNN_ia64_link_hash_table *ia64_info; ia64_info = elfNN_ia64_hash_table (x->info); + if (ia64_info == NULL) + return FALSE; + if (ia64_info->self_dtpmod_offset == (bfd_vma) -1) { ia64_info->self_dtpmod_offset = x->ofs; @@ -3155,7 +3167,7 @@ allocate_global_data_got (struct elfNN_ia64_dyn_sym_info *dyn_i, static bfd_boolean allocate_global_fptr_got (struct elfNN_ia64_dyn_sym_info *dyn_i, - PTR data) + void * data) { struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; @@ -3344,6 +3356,8 @@ allocate_dynrel_entries (struct elfNN_ia64_dyn_sym_info *dyn_i, bfd_boolean dynamic_symbol, shared, resolved_zero; ia64_info = elfNN_ia64_hash_table (x->info); + if (ia64_info == NULL) + return FALSE; /* Note that this can't be used in relation to FPTR relocs below. */ dynamic_symbol = elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, 0); @@ -3491,6 +3505,8 @@ elfNN_ia64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, dynobj = elf_hash_table(info)->dynobj; ia64_info = elfNN_ia64_hash_table (info); + if (ia64_info == NULL) + return FALSE; ia64_info->self_dtpmod_offset = (bfd_vma) -1; BFD_ASSERT(dynobj != NULL); data.info = info; @@ -3996,6 +4012,9 @@ set_got_entry (bfd *abfd, struct bfd_link_info *info, bfd_vma got_offset; ia64_info = elfNN_ia64_hash_table (info); + if (ia64_info == NULL) + return 0; + got_sec = ia64_info->root.sgot; switch (dyn_r_type) @@ -4133,6 +4152,9 @@ set_fptr_entry (bfd *abfd, struct bfd_link_info *info, asection *fptr_sec; ia64_info = elfNN_ia64_hash_table (info); + if (ia64_info == NULL) + return 0; + fptr_sec = ia64_info->fptr_sec; if (!dyn_i->fptr_done) @@ -4183,6 +4205,9 @@ set_pltoff_entry (bfd *abfd, struct bfd_link_info *info, asection *pltoff_sec; ia64_info = elfNN_ia64_hash_table (info); + if (ia64_info == NULL) + return 0; + pltoff_sec = ia64_info->pltoff_sec; /* Don't do anything if this symbol uses a real PLT entry. In @@ -4283,6 +4308,8 @@ elfNN_ia64_choose_gp (bfd *abfd, struct bfd_link_info *info) struct elfNN_ia64_link_hash_table *ia64_info; ia64_info = elfNN_ia64_hash_table (info); + if (ia64_info == NULL) + return FALSE; /* Find the min and max vma of all sections marked short. Also collect min and max vma of any type, for use in selecting a nice gp. */ @@ -4423,6 +4450,8 @@ elfNN_ia64_final_link (bfd *abfd, struct bfd_link_info *info) asection *unwind_output_sec; ia64_info = elfNN_ia64_hash_table (info); + if (ia64_info == NULL) + return FALSE; /* Make sure we've got ourselves a nice fat __gp value. */ if (!info->relocatable) @@ -4505,6 +4534,8 @@ elfNN_ia64_relocate_section (bfd *output_bfd, symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; ia64_info = elfNN_ia64_hash_table (info); + if (ia64_info == NULL) + return FALSE; /* Infect various flags from the input section to the output section. */ if (info->relocatable) @@ -5233,6 +5264,9 @@ elfNN_ia64_finish_dynamic_symbol (bfd *output_bfd, struct elfNN_ia64_dyn_sym_info *dyn_i; ia64_info = elfNN_ia64_hash_table (info); + if (ia64_info == NULL) + return FALSE; + dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, FALSE); /* Fill in the PLT data, if required. */ @@ -5319,6 +5353,9 @@ elfNN_ia64_finish_dynamic_sections (bfd *abfd, bfd *dynobj; ia64_info = elfNN_ia64_hash_table (info); + if (ia64_info == NULL) + return FALSE; + dynobj = ia64_info->root.dynobj; if (elf_hash_table (info)->dynamic_sections_created) diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index 555f02114..6f686bbf8 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -1,6 +1,6 @@ /* MIPS-specific support for ELF Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, - 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. Most of the information added by Ian Lance Taylor, Cygnus Support, . @@ -247,7 +247,7 @@ struct _mips_elf_section_data #define is_mips_elf(bfd) \ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ && elf_tdata (bfd) != NULL \ - && elf_object_id (bfd) == MIPS_ELF_TDATA) + && elf_object_id (bfd) == MIPS_ELF_DATA) /* The ABI says that every symbol used by dynamic relocations must have a global GOT entry. Among other things, this provides the dynamic @@ -485,8 +485,15 @@ struct mips_elf_link_hash_table asection *(*add_stub_section) (const char *, asection *, asection *); }; +/* Get the MIPS ELF linker hash table from a link_info structure. */ + +#define mips_elf_hash_table(p) \ + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == MIPS_ELF_DATA ? ((struct mips_elf_link_hash_table *) ((p)->hash)) : NULL) + /* A structure used to communicate with htab_traverse callbacks. */ -struct mips_htab_traverse_info { +struct mips_htab_traverse_info +{ /* The usual link-wide information. */ struct bfd_link_info *info; bfd *output_bfd; @@ -1007,11 +1014,6 @@ static const bfd_vma mips_vxworks_shared_plt_entry[] = (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ (info))) -/* Get the MIPS ELF linker hash table from a link_info structure. */ - -#define mips_elf_hash_table(p) \ - ((struct mips_elf_link_hash_table *) ((p)->hash)) - /* Find the base offsets for thread-local storage in this object, for GD/LD and IE/LE respectively. */ @@ -1549,6 +1551,9 @@ _bfd_mips_elf_init_stubs (struct bfd_link_info *info, struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + if (htab == NULL) + return FALSE; + htab->add_stub_section = fn; htab->la25_stubs = htab_try_create (1, mips_elf_la25_stub_hash, mips_elf_la25_stub_eq, NULL); @@ -1589,6 +1594,8 @@ mips_elf_add_la25_intro (struct mips_elf_la25_stub *stub, unsigned int align; htab = mips_elf_hash_table (info); + if (htab == NULL) + return FALSE; /* Create a unique name for the new section. */ name = bfd_malloc (11 + sizeof (".text.stub.")); @@ -1632,6 +1639,8 @@ mips_elf_add_la25_trampoline (struct mips_elf_la25_stub *stub, asection *s; htab = mips_elf_hash_table (info); + if (htab == NULL) + return FALSE; /* Create a trampoline section, if we haven't already. */ s = htab->strampoline; @@ -1682,6 +1691,9 @@ mips_elf_add_la25_stub (struct bfd_link_info *info, /* See if we've already created an equivalent stub. */ htab = mips_elf_hash_table (info); + if (htab == NULL) + return FALSE; + slot = htab_find_slot (htab->la25_stubs, &search, INSERT); if (slot == NULL) return FALSE; @@ -2854,6 +2866,9 @@ mips_elf_initialize_tls_slots (bfd *abfd, bfd_vma got_offset, bfd_boolean need_relocs = FALSE; htab = mips_elf_hash_table (info); + if (htab == NULL) + return; + sgot = htab->sgot; indx = 0; @@ -3013,6 +3028,8 @@ mips_elf_gotplt_index (struct bfd_link_info *info, struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + BFD_ASSERT (h->plt.offset != (bfd_vma) -1); /* This function only works for VxWorks, because a non-VxWorks .got.plt @@ -3049,6 +3066,8 @@ mips_elf_local_got_index (bfd *abfd, bfd *ibfd, struct bfd_link_info *info, struct mips_got_entry *entry; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + entry = mips_elf_create_local_got_entry (abfd, info, ibfd, value, r_symndx, h, r_type); if (!entry) @@ -3081,6 +3100,8 @@ mips_elf_global_got_index (bfd *abfd, bfd *ibfd, struct elf_link_hash_entry *h, long global_got_dynindx = 0; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + gg = g = htab->got_info; if (g->bfd2got && ibfd) { @@ -3220,6 +3241,8 @@ mips_elf_got_offset_from_index (struct bfd_link_info *info, bfd *output_bfd, bfd_vma gp; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + sgot = htab->sgot; gp = _bfd_get_gp_value (output_bfd) + mips_elf_adjust_gp (output_bfd, htab->got_info, input_bfd); @@ -3244,6 +3267,7 @@ mips_elf_create_local_got_entry (bfd *abfd, struct bfd_link_info *info, struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); entry.abfd = NULL; entry.symndx = -1; @@ -3379,6 +3403,8 @@ mips_elf_sort_hash_table (bfd *abfd, struct bfd_link_info *info) return TRUE; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + g = htab->got_info; if (g == NULL) return TRUE; @@ -3465,6 +3491,8 @@ mips_elf_record_global_got_symbol (struct elf_link_hash_entry *h, struct mips_got_info *g; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + hmips = (struct mips_elf_link_hash_entry *) h; /* A global symbol in the GOT must also be in the dynamic symbol @@ -3531,6 +3559,8 @@ mips_elf_record_local_got_symbol (bfd *abfd, long symndx, bfd_vma addend, struct mips_got_entry entry, **loc; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + g = htab->got_info; BFD_ASSERT (g != NULL); @@ -3613,6 +3643,8 @@ mips_elf_record_got_page_entry (struct bfd_link_info *info, bfd *abfd, void **loc; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + g = htab->got_info; BFD_ASSERT (g != NULL); @@ -3704,6 +3736,8 @@ mips_elf_allocate_dynamic_relocations (bfd *abfd, struct bfd_link_info *info, struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + s = mips_elf_rel_dyn_section (info, FALSE); BFD_ASSERT (s != NULL); @@ -4243,6 +4277,8 @@ mips_elf_forbid_lazy_stubs (void **entryp, void *data) entry = (struct mips_got_entry *) *entryp; info = (struct bfd_link_info *) data; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + if (entry->abfd != NULL && entry->symndx == -1 && entry->d.h->needs_lazy_stub) @@ -4290,6 +4326,8 @@ mips_elf_multi_got (bfd *abfd, struct bfd_link_info *info, dynobj = elf_hash_table (info)->dynobj; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + g = htab->got_info; g->bfd2got = htab_try_create (1, mips_elf_bfd2got_entry_hash, mips_elf_bfd2got_entry_eq, NULL); @@ -4664,6 +4702,7 @@ mips_elf_create_got_section (bfd *abfd, struct bfd_link_info *info) struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); /* This function may be called more than once. */ if (htab->sgot) @@ -4845,6 +4884,7 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd, dynobj = elf_hash_table (info)->dynobj; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); /* Parse the relocation. */ r_symndx = ELF_R_SYM (input_bfd, relocation->r_info); @@ -5680,6 +5720,8 @@ mips_elf_create_dynamic_relocation (bfd *output_bfd, struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + r_type = ELF_R_TYPE (output_bfd, rel->r_info); dynobj = elf_hash_table (info)->dynobj; sreloc = mips_elf_rel_dyn_section (info, FALSE); @@ -6869,6 +6911,8 @@ _bfd_mips_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED | SEC_READONLY); @@ -7205,6 +7249,8 @@ _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, return TRUE; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + dynobj = elf_hash_table (info)->dynobj; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); @@ -8078,6 +8124,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + dynobj = elf_hash_table (info)->dynobj; hmips = (struct mips_elf_link_hash_entry *) h; @@ -8154,6 +8202,8 @@ _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info *info, struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + dynobj = elf_hash_table (info)->dynobj; hmips = (struct mips_elf_link_hash_entry *) h; @@ -8348,6 +8398,7 @@ _bfd_mips_elf_always_size_sections (bfd *output_bfd, struct mips_htab_traverse_info hti; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); /* The .reginfo section has a fixed size. */ ri = bfd_get_section_by_name (output_bfd, ".reginfo"); @@ -8380,6 +8431,8 @@ mips_elf_lay_out_got (bfd *output_bfd, struct bfd_link_info *info) struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + s = htab->sgot; if (s == NULL) return TRUE; @@ -8505,6 +8558,8 @@ mips_elf_estimate_stub_size (bfd *output_bfd, struct bfd_link_info *info) bfd_size_type dynsymcount; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + if (htab->lazy_stub_count == 0) return; @@ -8556,12 +8611,13 @@ mips_elf_lay_out_lazy_stubs (struct bfd_link_info *info) struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + if (htab->lazy_stub_count == 0) return; htab->sstubs->size = 0; - mips_elf_link_hash_traverse (mips_elf_hash_table (info), - mips_elf_allocate_lazy_stub, htab); + mips_elf_link_hash_traverse (htab, mips_elf_allocate_lazy_stub, htab); htab->sstubs->size += htab->function_stub_size; BFD_ASSERT (htab->sstubs->size == htab->lazy_stub_count * htab->function_stub_size); @@ -8579,6 +8635,7 @@ _bfd_mips_elf_size_dynamic_sections (bfd *output_bfd, struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); dynobj = elf_hash_table (info)->dynobj; BFD_ASSERT (dynobj != NULL); @@ -9138,6 +9195,7 @@ _bfd_mips_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); BFD_ASSERT (name != NULL); if (!htab->small_data_overflow_reported && (howto->type == R_MIPS_GPREL16 @@ -9243,6 +9301,7 @@ mips_elf_create_la25_stub (void **slot, void *data) stub = (struct mips_elf_la25_stub *) *slot; hti = (struct mips_htab_traverse_info *) data; htab = mips_elf_hash_table (hti->info); + BFD_ASSERT (htab != NULL); /* Create the section contents, if we haven't already. */ s = stub->stub_section; @@ -9357,6 +9416,7 @@ _bfd_mips_elf_finish_dynamic_symbol (bfd *output_bfd, struct mips_elf_link_hash_entry *hmips; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); dynobj = elf_hash_table (info)->dynobj; hmips = (struct mips_elf_link_hash_entry *) h; @@ -9696,6 +9756,7 @@ _bfd_mips_vxworks_finish_dynamic_symbol (bfd *output_bfd, struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); dynobj = elf_hash_table (info)->dynobj; if (h->plt.offset != (bfd_vma) -1) @@ -9863,6 +9924,8 @@ mips_finish_exec_plt (bfd *output_bfd, struct bfd_link_info *info) struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + if (ABI_64_P (output_bfd)) plt_entry = mips_n64_exec_plt0_entry; else if (ABI_N32_P (output_bfd)) @@ -9906,6 +9969,8 @@ mips_vxworks_finish_exec_plt (bfd *output_bfd, struct bfd_link_info *info) struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + plt_entry = mips_vxworks_exec_plt0_entry; /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */ @@ -9976,6 +10041,7 @@ mips_vxworks_finish_shared_plt (bfd *output_bfd, struct bfd_link_info *info) struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); /* We just need to copy the entry byte-by-byte. */ for (i = 0; i < ARRAY_SIZE (mips_vxworks_shared_plt0_entry); i++) @@ -9996,6 +10062,8 @@ _bfd_mips_elf_finish_dynamic_sections (bfd *output_bfd, struct mips_elf_link_hash_table *htab; htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + dynobj = elf_hash_table (info)->dynobj; sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); @@ -11460,7 +11528,7 @@ bfd_boolean _bfd_mips_elf_mkobject (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct elf_obj_tdata), - MIPS_ELF_TDATA); + MIPS_ELF_DATA); } /* Create a MIPS ELF linker hash table. */ @@ -11477,7 +11545,8 @@ _bfd_mips_elf_link_hash_table_create (bfd *abfd) if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, mips_elf_link_hash_newfunc, - sizeof (struct mips_elf_link_hash_entry))) + sizeof (struct mips_elf_link_hash_entry), + MIPS_ELF_DATA)) { free (ret); return NULL; @@ -11582,6 +11651,8 @@ _bfd_mips_elf_final_link (bfd *abfd, struct bfd_link_info *info) /* Sort the dynamic symbols so that those with GOT entries come after those without. */ htab = mips_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + if (!mips_elf_sort_hash_table (abfd, info)) return FALSE; @@ -12917,6 +12988,8 @@ _bfd_mips_post_process_headers (bfd *abfd, struct bfd_link_info *link_info) if (link_info) { htab = mips_elf_hash_table (link_info); + BFD_ASSERT (htab != NULL); + if (htab->use_plts_and_copy_relocs && !htab->is_vxworks) i_ehdrp->e_ident[EI_ABIVERSION] = 1; } diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c index 06ae25e3a..73284db64 100644 --- a/bfd/elfxx-sparc.c +++ b/bfd/elfxx-sparc.c @@ -1,5 +1,5 @@ /* SPARC-specific support for ELF - Copyright 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + Copyright 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -523,13 +523,13 @@ struct _bfd_sparc_elf_obj_tdata #define is_sparc_elf(bfd) \ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ && elf_tdata (bfd) != NULL \ - && elf_object_id (bfd) == SPARC_ELF_TDATA) + && elf_object_id (bfd) == SPARC_ELF_DATA) bfd_boolean _bfd_sparc_elf_mkobject (bfd *abfd) { return bfd_elf_allocate_object (abfd, sizeof (struct _bfd_sparc_elf_obj_tdata), - SPARC_ELF_TDATA); + SPARC_ELF_DATA); } static void @@ -875,7 +875,8 @@ _bfd_sparc_elf_link_hash_table_create (bfd *abfd) } if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc, - sizeof (struct _bfd_sparc_elf_link_hash_entry))) + sizeof (struct _bfd_sparc_elf_link_hash_entry), + SPARC_ELF_DATA)) { free (ret); return NULL; @@ -896,6 +897,8 @@ create_got_section (bfd *dynobj, struct bfd_link_info *info) return FALSE; htab = _bfd_sparc_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + htab->sgot = bfd_get_section_by_name (dynobj, ".got"); BFD_ASSERT (htab->sgot != NULL); @@ -926,6 +929,8 @@ _bfd_sparc_elf_create_dynamic_sections (bfd *dynobj, struct _bfd_sparc_elf_link_hash_table *htab; htab = _bfd_sparc_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + if (!htab->sgot && !create_got_section (dynobj, info)) return FALSE; @@ -1093,6 +1098,7 @@ _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, return TRUE; htab = _bfd_sparc_elf_hash_table (info); + BFD_ASSERT (htab != NULL); symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_offsets = elf_local_got_offsets (abfd); @@ -1565,6 +1571,7 @@ _bfd_sparc_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, elf_section_data (sec)->local_dynrel = NULL; htab = _bfd_sparc_elf_hash_table (info); + BFD_ASSERT (htab != NULL); symtab_hdr = &elf_symtab_hdr (abfd); sym_hashes = elf_sym_hashes (abfd); local_got_refcounts = elf_local_got_refcounts (abfd); @@ -1710,6 +1717,7 @@ _bfd_sparc_elf_adjust_dynamic_symbol (struct bfd_link_info *info, asection *s; htab = _bfd_sparc_elf_hash_table (info); + BFD_ASSERT (htab != NULL); /* Make sure we know what is going on here. */ BFD_ASSERT (htab->elf.dynobj != NULL @@ -1851,6 +1859,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, PTR inf) info = (struct bfd_link_info *) inf; htab = _bfd_sparc_elf_hash_table (info); + BFD_ASSERT (htab != NULL); if (htab->elf.dynamic_sections_created && h->plt.refcount > 0) @@ -2144,6 +2153,7 @@ _bfd_sparc_elf_size_dynamic_sections (bfd *output_bfd, bfd *ibfd; htab = _bfd_sparc_elf_hash_table (info); + BFD_ASSERT (htab != NULL); dynobj = htab->elf.dynobj; BFD_ASSERT (dynobj != NULL); @@ -2511,6 +2521,7 @@ _bfd_sparc_elf_relocate_section (bfd *output_bfd, bfd_boolean is_vxworks_tls; htab = _bfd_sparc_elf_hash_table (info); + BFD_ASSERT (htab != NULL); symtab_hdr = &elf_symtab_hdr (input_bfd); sym_hashes = elf_sym_hashes (input_bfd); local_got_offsets = elf_local_got_offsets (input_bfd); @@ -3606,6 +3617,8 @@ sparc_vxworks_build_plt_entry (bfd *output_bfd, struct bfd_link_info *info, Elf_Internal_Rela rela; htab = _bfd_sparc_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + if (info->shared) { plt_entry = sparc_vxworks_shared_plt_entry; @@ -3694,6 +3707,7 @@ _bfd_sparc_elf_finish_dynamic_symbol (bfd *output_bfd, const struct elf_backend_data *bed; htab = _bfd_sparc_elf_hash_table (info); + BFD_ASSERT (htab != NULL); dynobj = htab->elf.dynobj; bed = get_elf_backend_data (output_bfd); @@ -3872,6 +3886,7 @@ sparc_finish_dyn (bfd *output_bfd, struct bfd_link_info *info, bfd_boolean abi_64_p; htab = _bfd_sparc_elf_hash_table (info); + BFD_ASSERT (htab != NULL); bed = get_elf_backend_data (output_bfd); dynsize = bed->s->sizeof_dyn; dynconend = sdyn->contents + sdyn->size; @@ -3963,6 +3978,7 @@ sparc_vxworks_finish_exec_plt (bfd *output_bfd, struct bfd_link_info *info) bfd_byte *loc; htab = _bfd_sparc_elf_hash_table (info); + BFD_ASSERT (htab != NULL); /* Calculate the absolute value of _GLOBAL_OFFSET_TABLE_. */ got_base = (htab->elf.hgot->root.u.def.section->output_section->vma @@ -4038,6 +4054,8 @@ sparc_vxworks_finish_shared_plt (bfd *output_bfd, struct bfd_link_info *info) unsigned int i; htab = _bfd_sparc_elf_hash_table (info); + BFD_ASSERT (htab != NULL); + for (i = 0; i < ARRAY_SIZE (sparc_vxworks_shared_plt0_entry); i++) bfd_put_32 (output_bfd, sparc_vxworks_shared_plt0_entry[i], htab->splt->contents + i * 4); @@ -4051,6 +4069,7 @@ _bfd_sparc_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *i struct _bfd_sparc_elf_link_hash_table *htab; htab = _bfd_sparc_elf_hash_table (info); + BFD_ASSERT (htab != NULL); dynobj = htab->elf.dynobj; sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); diff --git a/bfd/elfxx-sparc.h b/bfd/elfxx-sparc.h index 2be037b1d..6f24ecd24 100644 --- a/bfd/elfxx-sparc.h +++ b/bfd/elfxx-sparc.h @@ -1,5 +1,5 @@ /* SPARC ELF specific backend routines. - Copyright 2005, 2006, 2007, 2009 Free Software Foundation, Inc. + Copyright 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -54,7 +54,8 @@ struct _bfd_sparc_elf_link_hash_table asection *sdynbss; asection *srelbss; - union { + union + { bfd_signed_vma refcount; bfd_vma offset; } tls_ldm_got; @@ -93,7 +94,8 @@ struct _bfd_sparc_elf_link_hash_table /* Get the SPARC ELF linker hash table from a link_info structure. */ #define _bfd_sparc_elf_hash_table(p) \ - ((struct _bfd_sparc_elf_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == SPARC_ELF_DATA ? ((struct _bfd_sparc_elf_link_hash_table *) ((p)->hash)) : NULL) extern reloc_howto_type *_bfd_sparc_elf_reloc_type_lookup (bfd *, bfd_reloc_code_real_type); diff --git a/ld/ChangeLog b/ld/ChangeLog index c40683bde..02aa8794b 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,11 @@ +2010-02-03 Nick Clifton + + * emultempl/alphaelf.em: Update value expected from elf_object_id. + * emultempl/hppaelf.em: Likewise. + * emultempl/mipself.em: Likewise. + * emultempl/ppc32elf.em: Likewise. + * emultempl/ppc64elf.em: Likewise. + 2010-02-03 Alan Modra * emultempl/ppc64elf.em (build_toc_list): Report errors from diff --git a/ld/emultempl/alphaelf.em b/ld/emultempl/alphaelf.em index 7b7c8d707..21064ad8f 100644 --- a/ld/emultempl/alphaelf.em +++ b/ld/emultempl/alphaelf.em @@ -41,7 +41,7 @@ static void alpha_after_open (void) { if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour - && elf_object_id (link_info.output_bfd) == ALPHA_ELF_TDATA) + && elf_object_id (link_info.output_bfd) == ALPHA_ELF_DATA) { unsigned int num_plt; lang_output_section_statement_type *os; diff --git a/ld/emultempl/hppaelf.em b/ld/emultempl/hppaelf.em index 3ce5d54af..1137ba2cd 100644 --- a/ld/emultempl/hppaelf.em +++ b/ld/emultempl/hppaelf.em @@ -70,7 +70,8 @@ static void hppaelf_create_output_section_statements (void) { if (!(bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour - && elf_object_id (link_info.output_bfd) == HPPA_ELF_TDATA)) + && (elf_object_id (link_info.output_bfd) == HPPA32_ELF_DATA + || elf_object_id (link_info.output_bfd) == HPPA64_ELF_DATA))) return; stub_file = lang_add_input_file ("linker stubs", diff --git a/ld/emultempl/mipself.em b/ld/emultempl/mipself.em index 65cb0731a..7a13d4da0 100644 --- a/ld/emultempl/mipself.em +++ b/ld/emultempl/mipself.em @@ -27,7 +27,7 @@ fragment <