X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=bfd%2Felf32-cr16.c;h=62906c83a500821dcedbcf367d0338ede5e47146;hb=bd920864f3dc2cad376989a642ab774aef6b2fce;hp=7bb67a72e79fe73b2a930f81da1170e32db270fb;hpb=219d1afa89d0d53ca93a684cac341f16470f3ca0;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c index 7bb67a72e7..62906c83a5 100644 --- a/bfd/elf32-cr16.c +++ b/bfd/elf32-cr16.c @@ -1,5 +1,5 @@ /* BFD back-end for National Semiconductor's CR16 ELF - Copyright (C) 2007-2018 Free Software Foundation, Inc. + Copyright (C) 2007-2020 Free Software Foundation, Inc. Written by M R Swami Reddy. This file is part of BFD, the Binary File Descriptor library. @@ -25,6 +25,7 @@ #include "libiberty.h" #include "elf-bfd.h" #include "elf/cr16.h" +#include "elf32-cr16.h" /* The cr16 linker needs to keep track of the number of relocs that it decides to copy in check_relocs for each symbol. This is so @@ -610,7 +611,7 @@ _bfd_cr16_elf_create_got_section (bfd * abfd, struct bfd_link_info * info) s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); htab->sgot= s; if (s == NULL - || ! bfd_set_section_alignment (abfd, s, ptralign)) + || !bfd_set_section_alignment (s, ptralign)) return FALSE; if (bed->want_got_plt) @@ -618,7 +619,7 @@ _bfd_cr16_elf_create_got_section (bfd * abfd, struct bfd_link_info * info) s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags); htab->sgotplt = s; if (s == NULL - || ! bfd_set_section_alignment (abfd, s, ptralign)) + || !bfd_set_section_alignment (s, ptralign)) return FALSE; } @@ -641,7 +642,7 @@ _bfd_cr16_elf_create_got_section (bfd * abfd, struct bfd_link_info * info) /* Retrieve a howto ptr using a BFD reloc_code. */ static reloc_howto_type * -elf_cr16_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, +elf_cr16_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code) { unsigned int i; @@ -650,7 +651,8 @@ elf_cr16_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, if (code == cr16_reloc_map[i].bfd_reloc_enum) return &cr16_elf_howto_table[cr16_reloc_map[i].cr16_reloc_type]; - _bfd_error_handler (_("Unsupported CR16 relocation type: 0x%x\n"), code); + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, code); return NULL; } @@ -670,8 +672,8 @@ elf_cr16_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Retrieve a howto ptr using an internal relocation entry. */ -static void -elf_cr16_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, +static bfd_boolean +elf_cr16_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type = ELF32_R_TYPE (dst->r_info); @@ -679,12 +681,13 @@ elf_cr16_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, if (r_type >= R_CR16_MAX) { /* xgettext:c-format */ - _bfd_error_handler (_("%B: unrecognised CR16 reloc number: %d"), + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); - r_type = R_CR16_NONE; + return FALSE; } cache_ptr->howto = cr16_elf_howto_table + r_type; + return TRUE; } /* Look through the relocs for a section during the first phase. @@ -821,10 +824,9 @@ cr16_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, } } - result = TRUE; - fail: - if (isymbuf != NULL) - free (isymbuf); + result = TRUE; + fail: + free (isymbuf); return result; } @@ -1442,7 +1444,7 @@ elf32_cr16_relocate_section (bfd *output_bfd, struct bfd_link_info *info, name = (bfd_elf_string_from_elf_section (input_bfd, symtab_hdr->sh_link, sym->st_name)); if (name == NULL || *name == '\0') - name = bfd_section_name (input_bfd, sec); + name = bfd_section_name (sec); } switch (r) @@ -1569,10 +1571,8 @@ elf32_cr16_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); @@ -1581,13 +1581,10 @@ elf32_cr16_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; } @@ -1638,7 +1635,7 @@ static struct bfd_link_hash_table * elf32_cr16_link_hash_table_create (bfd *abfd) { struct elf_link_hash_table *ret; - bfd_size_type amt = sizeof (struct elf_link_hash_table); + size_t amt = sizeof (struct elf_link_hash_table); ret = (struct elf_link_hash_table *) bfd_zmalloc (amt); if (ret == (struct elf_link_hash_table *) NULL) @@ -1671,9 +1668,8 @@ elf_cr16_mach (flagword flags) file. This gets the CR16 architecture right based on the machine number. */ -static void -_bfd_cr16_elf_final_write_processing (bfd *abfd, - bfd_boolean linker ATTRIBUTE_UNUSED) +static bfd_boolean +_bfd_cr16_elf_final_write_processing (bfd *abfd) { unsigned long val; switch (bfd_get_mach (abfd)) @@ -1683,9 +1679,8 @@ _bfd_cr16_elf_final_write_processing (bfd *abfd, val = EM_CR16; break; } - - - elf_elfheader (abfd)->e_flags |= val; + elf_elfheader (abfd)->e_flags |= val; + return _bfd_elf_final_write_processing (abfd); } @@ -2173,21 +2168,17 @@ elf32_cr16_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; @@ -2241,7 +2232,7 @@ _bfd_cr16_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) flags | SEC_READONLY); htab->srelplt = s; if (s == NULL - || ! bfd_set_section_alignment (abfd, s, ptralign)) + || !bfd_set_section_alignment (s, ptralign)) return FALSE; if (! _bfd_cr16_elf_create_got_section (abfd, info)) @@ -2278,7 +2269,7 @@ _bfd_cr16_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) ? ".rela.bss" : ".rel.bss"), flags | SEC_READONLY); if (s == NULL - || ! bfd_set_section_alignment (abfd, s, ptralign)) + || !bfd_set_section_alignment (s, ptralign)) return FALSE; } } @@ -2463,7 +2454,7 @@ _bfd_cr16_elf_size_dynamic_sections (bfd * output_bfd, /* It's OK to base decisions on the section name, because none of the dynobj section names depend upon the input files. */ - name = bfd_get_section_name (dynobj, s); + name = bfd_section_name (s); if (strcmp (name, ".plt") == 0) { @@ -2489,8 +2480,7 @@ _bfd_cr16_elf_size_dynamic_sections (bfd * output_bfd, entry. The entries in the .rela.plt section really apply to the .got section, which we created ourselves and so know is not readonly. */ - outname = bfd_get_section_name (output_bfd, - s->output_section); + outname = bfd_section_name (s->output_section); target = bfd_get_section_by_name (output_bfd, outname + 5); if (target != NULL && (target->flags & SEC_READONLY) != 0 @@ -2798,7 +2788,7 @@ bfd_cr16_elf32_create_embedded_relocs (bfd *abfd, if (!((ELF32_R_TYPE (irel->r_info) == (int) R_CR16_NUM32a) || (ELF32_R_TYPE (irel->r_info) == (int) R_CR16_NUM32))) { - *errmsg = _("unsupported reloc type"); + *errmsg = _("unsupported relocation type"); bfd_set_error (bfd_error_bad_value); goto error_return; } @@ -2847,18 +2837,16 @@ bfd_cr16_elf32_create_embedded_relocs (bfd *abfd, strncpy ((char *) p + 4, targetsec->output_section->name, 4); } - if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) + if (symtab_hdr->contents != (unsigned char *) isymbuf) free (isymbuf); - if (internal_relocs != NULL - && elf_section_data (datasec)->relocs != internal_relocs) + if (elf_section_data (datasec)->relocs != internal_relocs) free (internal_relocs); return TRUE; -error_return: - if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) + error_return: + if (symtab_hdr->contents != (unsigned char *) isymbuf) free (isymbuf); - if (internal_relocs != NULL - && elf_section_data (datasec)->relocs != internal_relocs) + if (elf_section_data (datasec)->relocs != internal_relocs) free (internal_relocs); return FALSE; } @@ -2894,7 +2882,7 @@ _bfd_cr16_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSE #define bfd_elf32_bfd_reloc_type_lookup elf_cr16_reloc_type_lookup #define bfd_elf32_bfd_reloc_name_lookup elf_cr16_reloc_name_lookup #define elf_info_to_howto elf_cr16_info_to_howto -#define elf_info_to_howto_rel 0 +#define elf_info_to_howto_rel NULL #define elf_backend_relocate_section elf32_cr16_relocate_section #define bfd_elf32_bfd_relax_section elf32_cr16_relax_section #define bfd_elf32_bfd_get_relocated_section_contents \ @@ -2921,8 +2909,7 @@ _bfd_cr16_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSE _bfd_cr16_elf_adjust_dynamic_symbol #define elf_backend_size_dynamic_sections \ _bfd_cr16_elf_size_dynamic_sections -#define elf_backend_omit_section_dynsym \ - ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true) +#define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all #define elf_backend_finish_dynamic_symbol \ _bfd_cr16_elf_finish_dynamic_symbol #define elf_backend_finish_dynamic_sections \