X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=bfd%2Fcoff-sh.c;h=04ef99b777c7134ab51458d1df1450df8e3f71d3;hb=1201fda61b3bcf0028a57e622aebb16ec614f7dc;hp=3a921fd0228d3dd0a37af295daa2d1e621c0fb5c;hpb=219d1afa89d0d53ca93a684cac341f16470f3ca0;p=binutils-gdb.git diff --git a/bfd/coff-sh.c b/bfd/coff-sh.c index 3a921fd0228..04ef99b777c 100644 --- a/bfd/coff-sh.c +++ b/bfd/coff-sh.c @@ -1,5 +1,5 @@ /* BFD back-end for Renesas Super-H COFF binaries. - Copyright (C) 1993-2018 Free Software Foundation, Inc. + Copyright (C) 1993-2021 Free Software Foundation, Inc. Contributed by Cygnus Support. Written by Steve Chamberlain, . Relaxing code written by Ian Lance Taylor, . @@ -492,7 +492,7 @@ static const struct shcoff_reloc_map sh_reloc_map[] = #define coff_bfd_reloc_name_lookup sh_coff_reloc_name_lookup static reloc_howto_type * -sh_coff_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, +sh_coff_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code) { unsigned int i; @@ -501,7 +501,8 @@ sh_coff_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, if (sh_reloc_map[i].bfd_reloc_val == code) return &sh_coff_howtos[(int) sh_reloc_map[i].shcoff_reloc_val]; - _bfd_error_handler (_("SH Error: unknown reloc type %d"), code); + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, (unsigned int) code); return NULL; } @@ -566,7 +567,7 @@ sh_reloc (bfd * abfd, bfd * output_bfd, char ** error_message ATTRIBUTE_UNUSED) { - unsigned long insn; + bfd_vma insn; bfd_vma sym_value; unsigned short r_type; bfd_vma addr = reloc_entry->address; @@ -609,14 +610,14 @@ sh_reloc (bfd * abfd, #endif 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; #ifdef COFF_WITH_PE case R_SH_IMAGEBASE: insn = bfd_get_32 (abfd, hit_data); insn += sym_value + reloc_entry->addend; insn -= pe_data (input_section->output_section->owner)->pe_opthdr.ImageBase; - bfd_put_32 (abfd, (bfd_vma) insn, hit_data); + bfd_put_32 (abfd, insn, hit_data); break; #endif case R_SH_PCDISP: @@ -626,12 +627,10 @@ sh_reloc (bfd * abfd, + 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: @@ -723,7 +722,7 @@ sh_relax_section (bfd *abfd, if (coff_section_data (abfd, sec) == NULL) { - bfd_size_type amt = sizeof (struct coff_section_tdata); + size_t amt = sizeof (struct coff_section_tdata); sec->used_by_bfd = bfd_zalloc (abfd, amt); if (sec->used_by_bfd == NULL) return FALSE; @@ -775,8 +774,9 @@ sh_relax_section (bfd *abfd, if (laddr >= sec->size) { /* xgettext: c-format */ - _bfd_error_handler (_("%B: %#Lx: warning: bad R_SH_USES offset"), - abfd, irel->r_vaddr); + _bfd_error_handler + (_("%pB: %#" PRIx64 ": warning: bad R_SH_USES offset"), + abfd, (uint64_t) irel->r_vaddr); continue; } insn = bfd_get_16 (abfd, contents + laddr); @@ -786,8 +786,8 @@ sh_relax_section (bfd *abfd, { _bfd_error_handler /* xgettext: c-format */ - (_("%B: %#Lx: warning: R_SH_USES points to unrecognized insn %#x"), - abfd, irel->r_vaddr, insn); + (_("%pB: %#" PRIx64 ": warning: R_SH_USES points to unrecognized insn %#x"), + abfd, (uint64_t) irel->r_vaddr, insn); continue; } @@ -804,8 +804,8 @@ sh_relax_section (bfd *abfd, { _bfd_error_handler /* xgettext: c-format */ - (_("%B: %#Lx: warning: bad R_SH_USES load offset"), - abfd, irel->r_vaddr); + (_("%pB: %#" PRIx64 ": warning: bad R_SH_USES load offset"), + abfd, (uint64_t) irel->r_vaddr); continue; } @@ -829,8 +829,8 @@ sh_relax_section (bfd *abfd, { _bfd_error_handler /* xgettext: c-format */ - (_("%B: %#Lx: warning: could not find expected reloc"), - abfd, paddr); + (_("%pB: %#" PRIx64 ": warning: could not find expected reloc"), + abfd, (uint64_t) paddr); continue; } @@ -846,8 +846,8 @@ sh_relax_section (bfd *abfd, { _bfd_error_handler /* xgettext: c-format */ - (_("%B: %#Lx: warning: symbol in unexpected section"), - abfd, paddr); + (_("%pB: %#" PRIx64 ": warning: symbol in unexpected section"), + abfd, (uint64_t) paddr); continue; } @@ -972,8 +972,8 @@ sh_relax_section (bfd *abfd, { _bfd_error_handler /* xgettext: c-format */ - (_("%B: %#Lx: warning: could not find expected COUNT reloc"), - abfd, paddr); + (_("%pB: %#" PRIx64 ": warning: could not find expected COUNT reloc"), + abfd, (uint64_t) paddr); continue; } @@ -982,8 +982,8 @@ sh_relax_section (bfd *abfd, if (irelcount->r_offset == 0) { /* xgettext: c-format */ - _bfd_error_handler (_("%B: %#Lx: warning: bad count"), - abfd, paddr); + _bfd_error_handler (_("%pB: %#" PRIx64 ": warning: bad count"), + abfd, (uint64_t) paddr); continue; } @@ -1056,10 +1056,9 @@ sh_relax_section (bfd *abfd, return TRUE; error_return: - if (internal_relocs != NULL - && internal_relocs != coff_section_data (abfd, sec)->relocs) + if (internal_relocs != coff_section_data (abfd, sec)->relocs) free (internal_relocs); - if (contents != NULL && contents != coff_section_data (abfd, sec)->contents) + if (contents != coff_section_data (abfd, sec)->contents) free (contents); return FALSE; } @@ -1354,8 +1353,8 @@ sh_relax_delete_bytes (bfd *abfd, { _bfd_error_handler /* xgettext: c-format */ - (_("%B: %#Lx: fatal: reloc overflow while relaxing"), - abfd, irel->r_vaddr); + (_("%pB: %#" PRIx64 ": fatal: reloc overflow while relaxing"), + abfd, (uint64_t) irel->r_vaddr); bfd_set_error (bfd_error_bad_value); return FALSE; } @@ -1449,7 +1448,7 @@ sh_relax_delete_bytes (bfd *abfd, || obj_raw_syments (abfd) != NULL) { _bfd_error_handler - (_("%B: fatal: generic symbols retrieved before relaxing"), abfd); + (_("%pB: fatal: generic symbols retrieved before relaxing"), abfd); bfd_set_error (bfd_error_invalid_operation); return FALSE; } @@ -2642,8 +2641,8 @@ sh_swap_insns (bfd * abfd, { _bfd_error_handler /* xgettext: c-format */ - (_("%B: %#Lx: fatal: reloc overflow while relaxing"), - abfd, irel->r_vaddr); + (_("%pB: %#" PRIx64 ": fatal: reloc overflow while relaxing"), + abfd, (uint64_t) irel->r_vaddr); bfd_set_error (bfd_error_bad_value); return FALSE; } @@ -2723,8 +2722,7 @@ sh_align_loads (bfd *abfd, return TRUE; error_return: - if (labels != NULL) - free (labels); + free (labels); return FALSE; } @@ -2780,7 +2778,7 @@ sh_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, { _bfd_error_handler /* xgettext: c-format */ - (_("%B: illegal symbol index %ld in relocs"), + (_("%pB: illegal symbol index %ld in relocs"), input_bfd, symndx); bfd_set_error (bfd_error_bad_value); return FALSE; @@ -2995,12 +2993,9 @@ sh_coff_get_relocated_section_contents (bfd *output_bfd, return data; error_return: - if (internal_relocs != NULL) - free (internal_relocs); - if (internal_syms != NULL) - free (internal_syms); - if (sections != NULL) - free (sections); + free (internal_relocs); + free (internal_syms); + free (sections); return NULL; } @@ -3044,7 +3039,7 @@ CREATE_LITTLE_COFF_TARGET_VEC (TARGET_SYM, TARGET_SHL_NAME, BFD_IS_RELAXABLE, /* Only recognize the small versions if the target was not defaulted. Otherwise we won't recognize the non default endianness. */ -static const bfd_target * +static bfd_cleanup coff_small_object_p (bfd *abfd) { if (abfd->target_defaulted) @@ -3130,15 +3125,16 @@ const bfd_target sh_coff_small_vec = BFD_ENDIAN_BIG, /* data byte order is big */ BFD_ENDIAN_BIG, /* header byte order is big */ - (HAS_RELOC | EXEC_P | /* object flags */ - HAS_LINENO | HAS_DEBUG | - HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE), + (HAS_RELOC | EXEC_P /* object flags */ + | HAS_LINENO | HAS_DEBUG + | HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE), (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), '_', /* leading symbol underscore */ '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getb64, bfd_getb_signed_64, bfd_putb64, bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ @@ -3146,12 +3142,24 @@ const bfd_target sh_coff_small_vec = bfd_getb32, bfd_getb_signed_32, bfd_putb32, bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */ - {_bfd_dummy_target, coff_small_object_p, /* bfd_check_format */ - bfd_generic_archive_p, _bfd_dummy_target}, - {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */ - bfd_false}, - {bfd_false, coff_write_object_contents, /* bfd_write_contents */ - _bfd_write_archive_contents, bfd_false}, + { /* bfd_check_format */ + _bfd_dummy_target, + coff_small_object_p, + bfd_generic_archive_p, + _bfd_dummy_target + }, + { /* bfd_set_format */ + _bfd_bool_bfd_false_error, + coff_mkobject, + _bfd_generic_mkarchive, + _bfd_bool_bfd_false_error + }, + { /* bfd_write_contents */ + _bfd_bool_bfd_false_error, + coff_write_object_contents, + _bfd_write_archive_contents, + _bfd_bool_bfd_false_error + }, BFD_JUMP_TABLE_GENERIC (coff_small), BFD_JUMP_TABLE_COPY (coff), @@ -3163,9 +3171,9 @@ const bfd_target sh_coff_small_vec = BFD_JUMP_TABLE_LINK (coff), BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), - & sh_coff_small_le_vec, + &sh_coff_small_le_vec, - & bfd_coff_small_swap_table + &bfd_coff_small_swap_table }; const bfd_target sh_coff_small_le_vec = @@ -3175,15 +3183,16 @@ const bfd_target sh_coff_small_le_vec = BFD_ENDIAN_LITTLE, /* data byte order is little */ BFD_ENDIAN_LITTLE, /* header byte order is little endian too*/ - (HAS_RELOC | EXEC_P | /* object flags */ - HAS_LINENO | HAS_DEBUG | - HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE), + (HAS_RELOC | EXEC_P /* object flags */ + | HAS_LINENO | HAS_DEBUG + | HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE), (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), '_', /* leading symbol underscore */ '/', /* ar_pad_char */ 15, /* ar_max_namelen */ 0, /* match priority. */ + TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ bfd_getl64, bfd_getl_signed_64, bfd_putl64, bfd_getl32, bfd_getl_signed_32, bfd_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ @@ -3191,12 +3200,24 @@ const bfd_target sh_coff_small_le_vec = bfd_getl32, bfd_getl_signed_32, bfd_putl32, bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */ - {_bfd_dummy_target, coff_small_object_p, /* bfd_check_format */ - bfd_generic_archive_p, _bfd_dummy_target}, - {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */ - bfd_false}, - {bfd_false, coff_write_object_contents, /* bfd_write_contents */ - _bfd_write_archive_contents, bfd_false}, + { /* bfd_check_format */ + _bfd_dummy_target, + coff_small_object_p, + bfd_generic_archive_p, + _bfd_dummy_target + }, + { /* bfd_set_format */ + _bfd_bool_bfd_false_error, + coff_mkobject, + _bfd_generic_mkarchive, + _bfd_bool_bfd_false_error + }, + { /* bfd_write_contents */ + _bfd_bool_bfd_false_error, + coff_write_object_contents, + _bfd_write_archive_contents, + _bfd_bool_bfd_false_error + }, BFD_JUMP_TABLE_GENERIC (coff_small), BFD_JUMP_TABLE_COPY (coff), @@ -3208,8 +3229,8 @@ const bfd_target sh_coff_small_le_vec = BFD_JUMP_TABLE_LINK (coff), BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), - & sh_coff_small_vec, + &sh_coff_small_vec, - & bfd_coff_small_swap_table + &bfd_coff_small_swap_table }; #endif