From mboxrd@z Thu Jan 1 00:00:00 1970 From: "H . J . Lu" To: binutils@sourceware.cygnus.com Subject: PATCH: Fix the mips dynamic relocation for weak definiton. Date: Sun, 26 Aug 2001 17:49:00 -0000 Message-id: <20010826174901.A2794@lucon.org> X-SW-Source: 2001-08/msg00618.html I cannot believe that we didn't catch this bug much earlier. I copied the same logic in elf_i386_check_relocs (). I also added the missing prototype. Is that ok to check in? H.J. ---- 2001-08-26 H.J. Lu * elf32-mips.c (mips_elf_create_dynamic_relocation): Add the sanity check. (mips_elf_calculate_relocation): Create dynamic relocation for symbols with weak definition or the ELF_LINK_HASH_DEF_REGULAR bit is not set. (_bfd_mips_elf_hide_symbol): Add prototype. (_bfd_mips_elf_copy_indirect_symbol): Likewise. (_bfd_elf32_mips_grok_prstatus): Likewise. (_bfd_elf32_mips_grok_psinfo): Likewise. (_bfd_mips_elf_hide_symbol): Make it static and cast to `struct mips_elf_link_hash_entry *'. (_bfd_mips_elf_copy_indirect_symbol): Make it static. --- bfd/elf32-mips.c.assert Sun Aug 26 16:05:28 2001 +++ bfd/elf32-mips.c Sun Aug 26 17:26:50 2001 @@ -210,6 +210,15 @@ static boolean mips_elf_stub_section_p PARAMS ((bfd *, asection *)); static int sort_dynamic_relocs PARAMS ((const void *, const void *)); +static void _bfd_mips_elf_hide_symbol + PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); +static void _bfd_mips_elf_copy_indirect_symbol + PARAMS ((struct elf_link_hash_entry *, + struct elf_link_hash_entry *)); +static boolean _bfd_elf32_mips_grok_prstatus + PARAMS ((bfd *, Elf_Internal_Note *)); +static boolean _bfd_elf32_mips_grok_psinfo + PARAMS ((bfd *, Elf_Internal_Note *)); extern const bfd_target bfd_elf32_tradbigmips_vec; extern const bfd_target bfd_elf32_tradlittlemips_vec; @@ -3999,14 +4008,16 @@ mips_elf_link_hash_newfunc (entry, table return (struct bfd_hash_entry *) ret; } -void -_bfd_mips_elf_hide_symbol (info, h) +static void +_bfd_mips_elf_hide_symbol (info, entry) struct bfd_link_info *info; - struct mips_elf_link_hash_entry *h; + struct elf_link_hash_entry *entry; { bfd *dynobj; asection *got; struct mips_got_info *g; + struct mips_elf_link_hash_entry *h; + h = (struct mips_elf_link_hash_entry *) entry; dynobj = elf_hash_table (info)->dynobj; got = bfd_get_section_by_name (dynobj, ".got"); g = (struct mips_got_info *) elf_section_data (got)->tdata; @@ -5937,6 +5948,10 @@ mips_elf_create_dynamic_relocation (outp /* We've now added another relocation. */ ++sreloc->reloc_count; + /* Sanity check. */ + BFD_ASSERT (sreloc->reloc_count * MIPS_ELF_REL_SIZE (output_bfd) + <= sreloc->_raw_size); + /* Make sure the output section is writable. The dynamic linker will be writing to it. */ elf_section_data (input_section->output_section)->this_hdr.sh_flags @@ -6319,8 +6334,9 @@ mips_elf_calculate_relocation (abfd, if ((info->shared || (elf_hash_table (info)->dynamic_sections_created && h != NULL - && ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) - != 0))) + && (h->root.type == bfd_link_hash_defweak + || (h->root.elf_link_hash_flags + & ELF_LINK_HASH_DEF_REGULAR) == 0))) && (input_section->flags & SEC_ALLOC) != 0) { /* If we're creating a shared library, or this relocation is @@ -8065,7 +8081,7 @@ _bfd_mips_elf_gc_sweep_hook (abfd, info, hiding the old indirect symbol. Process additional relocation information. */ -void +static void _bfd_mips_elf_copy_indirect_symbol (dir, ind) struct elf_link_hash_entry *dir, *ind; { @@ -9170,7 +9186,8 @@ _bfd_elf32_mips_grok_prstatus (abfd, not raw_size, note->descpos + offset); } -static boolean _bfd_elf32_mips_grok_psinfo (abfd, note) +static boolean +_bfd_elf32_mips_grok_psinfo (abfd, note) bfd *abfd; Elf_Internal_Note *note; {