X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Felf32-sh.c;h=7daf8516c4b1cc494aa5ec731f88ce3067a5bbff;hb=c892b44730bb1a66d614fd47fabe47555ca83b3b;hp=3dc25eefe5937a4433db9c15c81caca7dbf9e90a;hpb=618265039f697eab9e72bb58b95fc2d32925df58;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c index 3dc25eefe5..7daf8516c4 100644 --- a/bfd/elf32-sh.c +++ b/bfd/elf32-sh.c @@ -1,5 +1,5 @@ /* Renesas / SuperH SH specific support for 32-bit ELF - Copyright (C) 1996-2019 Free Software Foundation, Inc. + Copyright (C) 1996-2020 Free Software Foundation, Inc. Contributed by Ian Lance Taylor, Cygnus Support. This file is part of BFD, the Binary File Descriptor library. @@ -30,6 +30,9 @@ #include "libiberty.h" #include "../opcodes/sh-opc.h" +/* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */ +#define OCTETS_PER_BYTE(ABFD, SEC) 1 + static bfd_reloc_status_type sh_elf_reloc (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); static bfd_reloc_status_type sh_elf_ignore_reloc @@ -164,8 +167,7 @@ sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED, bfd *input_bfd, if (!bfd_malloc_and_get_section (input_bfd, symbol_section, &contents)) { - if (contents != NULL) - free (contents); + free (contents); return bfd_reloc_outofrange; } } @@ -200,8 +202,7 @@ sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED, bfd *input_bfd, end = start0; } - if (contents != NULL - && elf_section_data (symbol_section)->this_hdr.contents != contents) + if (elf_section_data (symbol_section)->this_hdr.contents != contents) free (contents); insn = bfd_get_16 (input_bfd, contents + addr); @@ -229,11 +230,12 @@ sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in, void *data, asection *input_section, bfd *output_bfd, char **error_message ATTRIBUTE_UNUSED) { - unsigned long insn; + bfd_vma insn; bfd_vma sym_value; enum elf_sh_reloc_type r_type; bfd_vma addr = reloc_entry->address; - bfd_byte *hit_data = addr + (bfd_byte *) data; + bfd_size_type octets = addr * OCTETS_PER_BYTE (abfd, input_section); + bfd_byte *hit_data = (bfd_byte *) data + octets; r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type; @@ -254,8 +256,7 @@ sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in, return bfd_reloc_undefined; /* PR 17512: file: 9891ca98. */ - if ((addr * bfd_octets_per_byte (abfd, NULL) - + bfd_get_reloc_size (reloc_entry->howto)) + if (octets + bfd_get_reloc_size (reloc_entry->howto) > bfd_get_section_limit_octets (abfd, input_section)) return bfd_reloc_outofrange; @@ -271,7 +272,7 @@ sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in, case R_SH_DIR32: insn = bfd_get_32 (abfd, hit_data); insn += sym_value + reloc_entry->addend; - bfd_put_32 (abfd, (bfd_vma) insn, hit_data); + bfd_put_32 (abfd, insn, hit_data); break; case R_SH_IND12W: insn = bfd_get_16 (abfd, hit_data); @@ -280,12 +281,10 @@ sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in, + input_section->output_offset + addr + 4); - sym_value += (insn & 0xfff) << 1; - if (insn & 0x800) - sym_value -= 0x1000; - insn = (insn & 0xf000) | (sym_value & 0xfff); - bfd_put_16 (abfd, (bfd_vma) insn, hit_data); - if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000) + sym_value += (((insn & 0xfff) ^ 0x800) - 0x800) << 1; + insn = (insn & 0xf000) | ((sym_value >> 1) & 0xfff); + bfd_put_16 (abfd, insn, hit_data); + if (sym_value + 0x1000 >= 0x2000 || (sym_value & 1) != 0) return bfd_reloc_overflow; break; default: @@ -810,21 +809,17 @@ sh_elf_relax_section (bfd *abfd, asection *sec, } } - if (internal_relocs != NULL - && elf_section_data (sec)->relocs != internal_relocs) + if (elf_section_data (sec)->relocs != internal_relocs) free (internal_relocs); return TRUE; error_return: - if (isymbuf != NULL - && symtab_hdr->contents != (unsigned char *) isymbuf) + if (symtab_hdr->contents != (unsigned char *) isymbuf) free (isymbuf); - if (contents != NULL - && elf_section_data (sec)->this_hdr.contents != contents) + if (elf_section_data (sec)->this_hdr.contents != contents) free (contents); - if (internal_relocs != NULL - && elf_section_data (sec)->relocs != internal_relocs) + if (elf_section_data (sec)->relocs != internal_relocs) free (internal_relocs); return FALSE; @@ -1194,8 +1189,7 @@ sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr, when we leave sh_coff_relax_section. */ if (!bfd_malloc_and_get_section (abfd, o, &ocontents)) { - if (ocontents != NULL) - free (ocontents); + free (ocontents); return FALSE; } @@ -1252,8 +1246,7 @@ sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr, when we leave sh_coff_relax_section. */ if (!bfd_malloc_and_get_section (abfd, o, &ocontents)) { - if (ocontents != NULL) - free (ocontents); + free (ocontents); return FALSE; } @@ -1386,8 +1379,7 @@ sh_elf_align_loads (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, return TRUE; error_return: - if (labels != NULL) - free (labels); + free (labels); return FALSE; } @@ -2255,7 +2247,7 @@ static struct bfd_link_hash_table * sh_elf_link_hash_table_create (bfd *abfd) { struct elf_sh_link_hash_table *ret; - bfd_size_type amt = sizeof (struct elf_sh_link_hash_table); + size_t amt = sizeof (struct elf_sh_link_hash_table); ret = (struct elf_sh_link_hash_table *) bfd_zmalloc (amt); if (ret == (struct elf_sh_link_hash_table *) NULL) @@ -3562,7 +3554,6 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, bfd_vma relocation; bfd_vma addend = (bfd_vma) 0; bfd_reloc_status_type r; - int seen_stt_datalabel = 0; bfd_vma off; enum got_type got_type; const char *symname = NULL; @@ -3625,14 +3616,6 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, relocation = (sec->output_section->vma + sec->output_offset + sym->st_value); - /* A local symbol never has STO_SH5_ISA32, so we don't need - datalabel processing here. Make sure this does not change - without notice. */ - if ((sym->st_other & STO_SH5_ISA32) != 0) - (*info->callbacks->reloc_dangerous) - (info, - _("unexpected STO_SH5_ISA32 on local symbol is not handled"), - input_bfd, input_section, rel->r_offset); if (sec != NULL && discarded_section (sec)) /* Handled below. */ @@ -3782,14 +3765,9 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, || sh_elf_hash_entry (h)->got_type == GOT_TLS_GD))) ; else if (sec->output_section != NULL) - relocation = ((h->root.u.def.value + relocation = (h->root.u.def.value + sec->output_section->vma - + sec->output_offset) - /* A STO_SH5_ISA32 causes a "bitor 1" to the - symbol value, unless we've seen - STT_DATALABEL on the way to it. */ - | ((h->other & STO_SH5_ISA32) != 0 - && ! seen_stt_datalabel)); + + sec->output_offset); else if (!bfd_link_relocatable (info) && (_bfd_elf_section_offset (output_bfd, info, input_section, @@ -3814,12 +3792,13 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) ; else if (!bfd_link_relocatable (info)) - (*info->callbacks->undefined_symbol) - (info, h->root.root.string, input_bfd, - input_section, rel->r_offset, - (info->unresolved_syms_in_objects == RM_GENERATE_ERROR - || ELF_ST_VISIBILITY (h->other))); - } + info->callbacks->undefined_symbol + (info, h->root.root.string, input_bfd, input_section, + rel->r_offset, + (info->unresolved_syms_in_objects == RM_DIAGNOSE + && !info->warn_unresolved_syms) + || ELF_ST_VISIBILITY (h->other)); + } if (sec != NULL && discarded_section (sec)) RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, @@ -5269,10 +5248,8 @@ sh_elf_get_relocated_section_contents (bfd *output_bfd, isymbuf, sections)) goto error_return; - if (sections != NULL) - free (sections); - if (isymbuf != NULL - && symtab_hdr->contents != (unsigned char *) isymbuf) + free (sections); + if (symtab_hdr->contents != (unsigned char *) isymbuf) free (isymbuf); if (elf_section_data (input_section)->relocs != internal_relocs) free (internal_relocs); @@ -5281,13 +5258,10 @@ sh_elf_get_relocated_section_contents (bfd *output_bfd, return data; error_return: - if (sections != NULL) - free (sections); - if (isymbuf != NULL - && symtab_hdr->contents != (unsigned char *) isymbuf) + free (sections); + if (symtab_hdr->contents != (unsigned char *) isymbuf) free (isymbuf); - if (internal_relocs != NULL - && elf_section_data (input_section)->relocs != internal_relocs) + if (elf_section_data (input_section)->relocs != internal_relocs) free (internal_relocs); return NULL; } @@ -5862,7 +5836,7 @@ sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, p = *head; if (p == NULL || p->sec != sec) { - bfd_size_type amt = sizeof (*p); + size_t amt = sizeof (*p); p = bfd_alloc (htab->root.dynobj, amt); if (p == NULL) return FALSE; @@ -6040,6 +6014,10 @@ sh_elf_merge_private_data (bfd *ibfd, struct bfd_link_info *info) { bfd *obfd = info->output_bfd; + /* FIXME: What should be checked when linking shared libraries? */ + if ((ibfd->flags & DYNAMIC) != 0) + return TRUE; + if (! is_sh_elf (ibfd) || ! is_sh_elf (obfd)) return TRUE;