From ab96bf03fd98b6f68cd213ac81f52be3aca9c435 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 7 Mar 2007 08:54:35 +0000 Subject: PR 3958 bfd/ * elf-bfd.h (RELOC_FOR_GLOBAL_SYMBOL): No error on relocatable link. (elf_discarded_section): Move.. * bfd-in.h: ..to here. * bfd-in2.h: Regenerate. * elflink.c (elf_link_input_bfd): Don't zap relocs against symbols from discarded sections before relocate_section has done its job. * reloc.c (bfd_generic_get_relocated_section_contents): Handle relocs against symbols from discarded sections. * elf-hppa.h (elf_hppa_howto_table): Set size. Set dst_mask on SECREL32. (elf_hppa_relocate_section): Handle relocatable link after setting sec, sym, h etc. for final link. Squash error messages for relocatable link. Clear section contents for relocs against symbols in discarded sections, and zero reloc. Remove existing zero r_symndx code. * elf-m10200.c (mn10200_elf_relocate_section): Likewise. * elf-m10300.c (mn10300_elf_relocate_section): Likewise. * elf32-arm.c (elf32_arm_relocate_section): Likewise. * elf32-avr.c (elf32_avr_relocate_section): Likewise. * elf32-bfin.c (bfinfdpic_relocate_section): Likewise. (bfin_relocate_section): Likewise. * elf32-cr16c.c (elf32_cr16c_relocate_section): Likewise. * elf32-cris.c (cris_elf_relocate_section): Likewise. * elf32-crx.c (elf32_crx_relocate_section): Likewise. * elf32-d10v.c (elf32_d10v_relocate_section): Likewise. * elf32-fr30.c (fr30_elf_relocate_section): Likewise. * elf32-frv.c (elf32_frv_relocate_section): Likewise. * elf32-h8300.c (elf32_h8_relocate_section): Likewise. * elf32-hppa.c (elf32_hppa_relocate_section): Likewise. * elf32-i370.c (i370_elf_relocate_section): Likewise. * elf32-i386.c (elf_i386_relocate_section): Likewise. * elf32-i860.c (elf32_i860_relocate_section): Likewise. * elf32-ip2k.c (ip2k_elf_relocate_section): Likewise. * elf32-iq2000.c (iq2000_elf_relocate_section): Likewise. * elf32-m32c.c (m32c_elf_relocate_section): Likewise. * elf32-m32r.c (m32r_elf_relocate_section): Likewise. * elf32-m68hc1x.c (elf32_m68hc11_check_relocs): Likewise. * elf32-m68k.c (elf_m68k_relocate_section): Likewise. * elf32-mcore.c (mcore_elf_relocate_section): Likewise. * elf32-mep.c (mep_elf_relocate_section): Likewise. * elf32-msp430.c (elf32_msp430_relocate_section): Likewise. * elf32-mt.c (mt_elf_relocate_section): Likewise. * elf32-openrisc.c (openrisc_elf_relocate_section): Likewise. * elf32-ppc.c (ppc_elf_relocate_section): Likewise. * elf32-s390.c (elf_s390_relocate_section): Likewise. * elf32-score.c (_bfd_score_elf_relocate_section): Likewise. * elf32-sh.c (sh_elf_relocate_section): Likewise. * elf32-spu.c (spu_elf_relocate_section): Likewise. * elf32-v850.c (v850_elf_relocate_section): Likewise. * elf32-vax.c (elf_vax_relocate_section): Likewise. * elf32-xc16x.c (elf32_xc16x_relocate_section): Likewise. * elf32-xstormy16.c (xstormy16_elf_relocate_section): Likewise. * elf32-xtensa.c (elf_xtensa_relocate_section): Likewise. * elf64-alpha.c (elf64_alpha_relocate_section_r): Likewise. (elf64_alpha_relocate_section): Likewise. * elf64-mmix.c (mmix_elf_relocate_section): Likewise. * elf64-ppc.c (ppc64_elf_relocate_section): Likewise. * elf64-s390.c (elf_s390_relocate_section): Likewise. * elf64-sh64.c (sh_elf64_relocate_section): Likewise. * elf64-x86-64.c (elf64_x86_64_relocate_section): Likewise. * elfxx-ia64.c (elfNN_ia64_relocate_section): Likewise. * elfxx-mips.c (_bfd_mips_elf_relocate_section): Likewise. * elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Likewise. * elf32-arm.c (elf32_arm_relocate_section): Always adjust section symbols for relocatable link. Don't use always-zero st_value. (elf_backend_rela_normal): Don't define. * elf32-bfin.c (bfinfdpic_relocate_section): Use RELOC_FOR_GLOBAL_SYMBOL. * elf32-frv.c (elf32_frv_relocate_section): Likewise. * elf32-d10v.c (elf32_d10v_relocate_section): Combine SEC_MERGE section symbol adjustments with same for relocatable link. * elf32-i386.c (elf_i386_relocate_section): Likewise. * elf32-m68hc1x.c (m68hc11_get_relocation_value): Move.. (elf32_m68hc11_check_relocs): ..to here. * elf32-score.c (score_elf_final_link_relocate): Remove zero r_symndx code. * elfxx-mips.c (mips_elf_calculate_relocation): Likewise. ld/testsuite/ * ld-elf/linkonce1.d: New. * ld-elf/linkonce1a.s: New. * ld-elf/linkonce1b.s: New. * ld-elf/linkonce2.d: New. * ld-i386/pcrel16abs.d: New. * ld-i386/pcrel16abs.s: New. * ld-i386/i386.exp: Run it. --- bfd/elf32-m32r.c | 288 +++++++++++++++++++++++++++---------------------------- 1 file changed, 140 insertions(+), 148 deletions(-) (limited to 'bfd/elf32-m32r.c') diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c index 30674f3..915405d 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 Free Software Foundation, Inc. + 2006, 2007 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -2477,6 +2477,7 @@ m32r_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, `r_addend'. */ bfd_vma addend = rel->r_addend; bfd_vma offset = rel->r_offset; + bfd_vma relocation; Elf_Internal_Sym *sym; asection *sec; const char *sym_name; @@ -2509,27 +2510,152 @@ m32r_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, howto = m32r_elf_howto_table + r_type; r_symndx = ELF32_R_SYM (rel->r_info); - if (info->relocatable && use_rel) + sym = NULL; + sec = NULL; + h = NULL; + + if (r_symndx < symtab_hdr->sh_info) + { + /* Local symbol. */ + sym = local_syms + r_symndx; + sec = local_sections[r_symndx]; + sym_name = ""; + + if (!use_rel) + { + relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); + addend = rel->r_addend; + } + else + { + relocation = (sec->output_section->vma + + sec->output_offset + + sym->st_value); + } + } + else + { + /* External symbol. */ + relocation = 0; + + h = sym_hashes[r_symndx - symtab_hdr->sh_info]; + while (h->root.type == bfd_link_hash_indirect + || h->root.type == bfd_link_hash_warning) + h = (struct elf_link_hash_entry *) h->root.u.i.link; + sym_name = h->root.root.string; + + if (h->root.type == bfd_link_hash_defined + || h->root.type == bfd_link_hash_defweak) + { + bfd_boolean dyn; + sec = h->root.u.def.section; + + dyn = htab->root.dynamic_sections_created; + sec = h->root.u.def.section; + if (r_type == R_M32R_GOTPC24 + || (r_type == R_M32R_GOTPC_HI_ULO + || r_type == R_M32R_GOTPC_HI_SLO + || r_type == R_M32R_GOTPC_LO) + || (r_type == R_M32R_26_PLTREL + && h->plt.offset != (bfd_vma) -1) + || ((r_type == R_M32R_GOT24 + || r_type == R_M32R_GOT16_HI_ULO + || r_type == R_M32R_GOT16_HI_SLO + || r_type == R_M32R_GOT16_LO) + && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, + info->shared, h) + && (! info->shared + || (! info->symbolic && h->dynindx != -1) + || !h->def_regular)) + || (info->shared + && ((! info->symbolic && h->dynindx != -1) + || !h->def_regular) + && (((r_type == R_M32R_16_RELA + || r_type == R_M32R_32_RELA + || r_type == R_M32R_24_RELA + || r_type == R_M32R_HI16_ULO_RELA + || r_type == R_M32R_HI16_SLO_RELA + || r_type == R_M32R_LO16_RELA) + && !h->forced_local) + || r_type == R_M32R_REL32 + || r_type == R_M32R_10_PCREL_RELA + || r_type == R_M32R_18_PCREL_RELA + || r_type == R_M32R_26_PCREL_RELA) + && ((input_section->flags & SEC_ALLOC) != 0 + /* DWARF will emit R_M32R_16(24,32) relocations + in its sections against symbols defined + externally in shared libraries. We can't do + anything with them here. */ + || ((input_section->flags & SEC_DEBUGGING) != 0 + && h->def_dynamic)))) + { + /* In these cases, we don't need the relocation + value. We check specially because in some + obscure cases sec->output_section will be NULL. */ + } + else if (sec->output_section != NULL) + relocation = (h->root.u.def.value + + sec->output_section->vma + + sec->output_offset); + else if (!info->relocatable) + { + (*_bfd_error_handler) + (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), + input_bfd, + input_section, + (long) rel->r_offset, + howto->name, + h->root.root.string); + } + } + else if (h->root.type == bfd_link_hash_undefweak) + ; + else if (info->unresolved_syms_in_objects == RM_IGNORE + && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) + ; + else if (!info->relocatable) + { + if (! ((*info->callbacks->undefined_symbol) + (info, h->root.root.string, input_bfd, + input_section, offset, + (info->unresolved_syms_in_objects == RM_GENERATE_ERROR + || ELF_ST_VISIBILITY (h->other))))) + return FALSE; + } + } + + if (sec != NULL && elf_discarded_section (sec)) + { + /* For relocs against symbols from removed linkonce sections, + or sections discarded by a linker script, we just want the + section contents zeroed. Avoid any special processing. */ + _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); + rel->r_info = 0; + rel->r_addend = 0; + continue; + } + + if (info->relocatable && !use_rel) { /* This is a relocatable link. We don't have to change anything, unless the reloc is against a section symbol, in which case we have to adjust according to where the section symbol winds up in the output section. */ - sec = NULL; - if (r_symndx >= symtab_hdr->sh_info) - /* External symbol. */ - continue; + if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION) + rel->r_addend += sec->output_offset; + continue; + } - /* Local symbol. */ - sym = local_syms + r_symndx; - sym_name = ""; - /* STT_SECTION: symbol is associated with a section. */ - if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) - /* Symbol isn't associated with a section. Nothing to do. */ + if (info->relocatable && use_rel) + { + /* This is a relocatable link. We don't have to change + anything, unless the reloc is against a section symbol, + in which case we have to adjust according to where the + section symbol winds up in the output section. */ + if (sym == NULL || ELF_ST_TYPE (sym->st_info) != STT_SECTION) continue; - sec = local_sections[r_symndx]; - addend += sec->output_offset + sym->st_value; + addend += sec->output_offset; /* If partial_inplace, we need to store any additional addend back in the section. */ @@ -2567,140 +2693,6 @@ m32r_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, } else { - bfd_vma relocation; - - /* This is a final link. */ - sym = NULL; - sec = NULL; - h = NULL; - - if (r_symndx < symtab_hdr->sh_info) - { - /* Local symbol. */ - sym = local_syms + r_symndx; - sec = local_sections[r_symndx]; - sym_name = ""; - - if (!use_rel) - { - relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); - addend = rel->r_addend; - - if (info->relocatable) - { - /* This is a relocatable link. We don't have to change - anything, unless the reloc is against a section symbol, - in which case we have to adjust according to where the - section symbol winds up in the output section. */ - if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) - rel->r_addend += sec->output_offset + sym->st_value; - - continue; - } - } - else - { - relocation = (sec->output_section->vma - + sec->output_offset - + sym->st_value); - } - } - else - { - /* External symbol. */ - if (info->relocatable && !use_rel) - continue; - - h = sym_hashes[r_symndx - symtab_hdr->sh_info]; - while (h->root.type == bfd_link_hash_indirect - || h->root.type == bfd_link_hash_warning) - h = (struct elf_link_hash_entry *) h->root.u.i.link; - sym_name = h->root.root.string; - - if (h->root.type == bfd_link_hash_defined - || h->root.type == bfd_link_hash_defweak) - { - bfd_boolean dyn; - sec = h->root.u.def.section; - - dyn = htab->root.dynamic_sections_created; - sec = h->root.u.def.section; - if (r_type == R_M32R_GOTPC24 - || (r_type == R_M32R_GOTPC_HI_ULO - || r_type == R_M32R_GOTPC_HI_SLO - || r_type == R_M32R_GOTPC_LO) - || (r_type == R_M32R_26_PLTREL - && h->plt.offset != (bfd_vma) -1) - || ((r_type == R_M32R_GOT24 - || r_type == R_M32R_GOT16_HI_ULO - || r_type == R_M32R_GOT16_HI_SLO - || r_type == R_M32R_GOT16_LO) - && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, - info->shared, h) - && (! info->shared - || (! info->symbolic && h->dynindx != -1) - || !h->def_regular)) - || (info->shared - && ((! info->symbolic && h->dynindx != -1) - || !h->def_regular) - && (((r_type == R_M32R_16_RELA - || r_type == R_M32R_32_RELA - || r_type == R_M32R_24_RELA - || r_type == R_M32R_HI16_ULO_RELA - || r_type == R_M32R_HI16_SLO_RELA - || r_type == R_M32R_LO16_RELA) - && !h->forced_local) - || r_type == R_M32R_REL32 - || r_type == R_M32R_10_PCREL_RELA - || r_type == R_M32R_18_PCREL_RELA - || r_type == R_M32R_26_PCREL_RELA) - && ((input_section->flags & SEC_ALLOC) != 0 - /* DWARF will emit R_M32R_16(24,32) relocations - in its sections against symbols defined - externally in shared libraries. We can't do - anything with them here. */ - || ((input_section->flags & SEC_DEBUGGING) != 0 - && h->def_dynamic)))) - { - /* In these cases, we don't need the relocation - value. We check specially because in some - obscure cases sec->output_section will be NULL. */ - relocation = 0; - } - else if (sec->output_section == NULL) - { - (*_bfd_error_handler) - (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), - input_bfd, - input_section, - (long) rel->r_offset, - howto->name, - h->root.root.string); - - relocation = 0; - } - else - relocation = (h->root.u.def.value - + sec->output_section->vma - + sec->output_offset); - } - else if (h->root.type == bfd_link_hash_undefweak) - relocation = 0; - else if (info->unresolved_syms_in_objects == RM_IGNORE - && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) - relocation = 0; - else - { - if (! ((*info->callbacks->undefined_symbol) - (info, h->root.root.string, input_bfd, - input_section, offset, - (info->unresolved_syms_in_objects == RM_GENERATE_ERROR - || ELF_ST_VISIBILITY (h->other))))) - return FALSE; - relocation = 0; - } - } - /* Sanity check the address. */ if (offset > high_address) { -- cgit v1.1