diff options
author | Nick Clifton <nickc@redhat.com> | 2018-02-27 10:15:13 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2018-02-27 10:15:13 +0000 |
commit | f3185997ac0951edac802e29df03dfc0844fda34 (patch) | |
tree | 8bbb4a9dbe5d0e3c40a1218308df4f9ac3a22c0c | |
parent | b643315decd3e566e68ef374a0794371a4bddab3 (diff) | |
download | fsf-binutils-gdb-f3185997ac0951edac802e29df03dfc0844fda34.zip fsf-binutils-gdb-f3185997ac0951edac802e29df03dfc0844fda34.tar.gz fsf-binutils-gdb-f3185997ac0951edac802e29df03dfc0844fda34.tar.bz2 |
Have info_to_howto functions return a success/fail status. Check this result. Stop strip from completeing if one of these functions fails.
bfd PR 22875
* elf-bfd.h (struct elf_backend_data): Change the return type of
the elf_info_to_howto and elf_info_to_howto_rel function pointers
to bfd_boolean.
* elfcode.h (elf_slurp_reloc_table_from_section): Check the return value from the info_to_howto function and fail if that function failed.
* elf32-h8300.c (elf32_h8_relocate_section): Check return value from the info_to_howto function.
(elf32_h8_relax_section): Likewise.
* elf32-lm32.c (lm32_elf_relocate_section): Likewise.
* elf32-m68hc1x.c (elf32_m68hc11_relocate_section): Likewise.
* elf32-score.c (s3_bfd_score_elf_relocate_section): Likewise.
* elf32-score7.c (s7_bfd_score_elf_relocate_section): Likewise.
* elf32-tic6x.c (elf32_tic6x_relocate_section): Likewise.
* elf64-ia64-vms.c (elf64_ia64_relocate_section): Likewise.
* elf64-sparc.c (elf64_sparc_slurp_one_reloc_table): Likewise.
* elf64-x86-64.c (elf_x86_64_tls_transition): Likewise.
* elfnn-ia64.c (elfNN_ia64_relocate_section): Likewise.
* elfnn-riscv.c (riscv_elf_check_relocs): Likewise.
(riscv_elf_relocate_section): Likewise.
* elf-hppa.h (elf_hppa_info_to_howto): Change return type to
bfd_boolean. Issue an error message, set an error value and
return FALSE if the reloc is not recognized.
(elf_hppa_info_to_howto_rel): Likewise.
* elf-m10200.c (mn10200_info_to_howto): Likewise.
* elf-m10300.c (mn10300_info_to_howto): Likewise.
* elf.c (_bfd_elf_no_info_to_howto): Likewise.
* elf32-arc.c (arc_info_to_howto_rel): Likewise.
* elf32-arm.c (elf32_arm_info_to_howto): Likewise.
* elf32-avr.c (avr_info_to_howto_rela): Likewise.
* elf32-bfin.c (bfin_info_to_howto): Likewise.
* elf32-cr16.c (elf_cr16_info_to_howto): Likewise.
* elf32-cr16c.c (elf_cr16c_info_to_howto): Likewise.
* elf32-cris.c (elf_cr16c_info_to_howto_rel, cris_info_to_howto_rela): Likewise.
* elf32-crx.c (elf_crx_info_to_howto): Likewise.
* elf32-d10v.c (d10v_info_to_howto_rel): Likewise.
* elf32-d30v.c (d30v_info_to_howto_rel, d30v_info_to_howto_rela): Likewise.
* elf32-dlx.c (dlx_rtype_to_howto, elf32_dlx_info_to_howto, elf32_dlx_info_to_howto_rel): Likewise.
* elf32-epiphany.c (epiphany_info_to_howto_rela): Likewise.
* elf32-fr30.c (fr30_info_to_howto_rela): Likewise.
* elf32-frv.c (frv_info_to_howto_rela, frvfdpic_info_to_howto_rel): Likewise.
* elf32-ft32.c (ft32_info_to_howto_rela): Likewise.
* elf32-gen.c (elf_generic_info_to_howto, elf_generic_info_to_howto_rel): Likewise.
* elf32-h8300.c (elf32_h8_info_to_howto, elf32_h8_info_to_howto_rel): Likewise.
* elf32-i370.c (i370_elf_info_to_howto): Likewise.
* elf32-i386.c (elf_i386_reloc_type_lookup, elf_i386_rtype_to_howto, elf_i386_info_to_howto_rel): Likewise.
* elf32-i860.c (lookup_howto, elf32_i860_info_to_howto_rela): Likewise.
* elf32-i960.c (elf32_i960_info_to_howto_rel): Likewise.
* elf32-ip2k.c (ip2k_info_to_howto_rela): Likewise.
* elf32-iq2000.c (iq2000_info_to_howto_rela): Likewise.
* elf32-lm32.c (lm32_info_to_howto_rela): Likewise.
* elf32-m32c.c (m32c_info_to_howto_rela): Likewise.
* elf32-m32r.c (m32r_info_to_howto_rel, m32r_info_to_howto): Likewise.
* elf32-m68hc11.c (m68hc11_info_to_howto_rel): Likewise.
* elf32-m68hc12.c (m68hc11_info_to_howto_rel): Likewise.
* elf32-m68k.c (rtype_to_howto): Likewise.
* elf32-mcore.c (mcore_elf_info_to_howto): Likewise.
* elf32-mep.c (mep_info_to_howto_rela): Likewise.
* elf32-metag.c (metag_info_to_howto_rela): Likewise.
* elf32-microblaze.c (microblaze_elf_info_to_howto): Likewise.
* elf32-mips.c (mips_info_to_howto_rel, mips_info_to_howto_rela): Likewise.
* elf32-moxie.c (moxie_info_to_howto_rela): Likewise.
* elf32-msp430.c (msp430_info_to_howto_rela): Likewise.
* elf32-mt.c (mt_info_to_howto_rela): Likewise.
* elf32-nds32.c (nds32_info_to_howto_rel, nds32_info_to_howto): Likewise.
* elf32-nios2.c (nios2_elf32_info_to_howto): Likewise.
* elf32-or1k.c (or1k_info_to_howto_rela): Likewise.
* elf32-pj.c (pj_elf_info_to_howto): Likewise.
* elf32-ppc.c (ppc_elf_info_to_howto): Likewise.
* elf32-pru.c (pru_elf32_info_to_howto): Likewise.
* elf32-rl78.c (rl78_info_to_howto_rela): Likewise.
* elf32-rx.c (rx_info_to_howto_rela): Likewise.
* elf32-s390.c (elf_s390_info_to_howto): Likewise.
* elf32-score.c (s3_bfd_score_info_to_howto, _bfd_score_info_to_howto): Likewise.
* elf32-score7.c (s7_bfd_score_info_to_howto): Likewise.
* elf32-sh.c (sh_elf_info_to_howto): Likewise.
* elf32-spu.c (spu_elf_info_to_howto): Likewise.
* elf32-tic6x.c (elf32_tic6x_info_to_howto, elf32_tic6x_info_to_howto_rel): Likewise.
* elf32-tilepro.c (tilepro_info_to_howto_rela): Likewise.
* elf32-v850.c (v850_elf_info_to_howto_rel, v850_elf_info_to_howto_rela, v800_elf_info_to_howto): Likewise.
* elf32-vax.c (rtype_to_howto): Likewise.
* elf32-visium.c (visium_info_to_howto_rela): Likewise.
* elf32-wasm32.c (elf32_wasm32_rtype_to_howto, elf32_wasm32_info_to_howto_rela): Likewise.
* elf32-xc16x.c (elf32_xc16x_info_to_howto): Likewise.
* elf32-xgate.c (xgate_info_to_howto_rel): Likewise.
* elf32-xstormy16.c (xstormy16_info_to_howto_rela): Likewise.
* elf32-xtensa.c (elf_xtensa_info_to_howto_rela): Likewise.
* elf64-alpha.c (elf64_alpha_info_to_howto): Likewise.
* elf64-gen.c (elf_generic_info_to_howto, elf_generic_info_to_howto_rel): Likewise.
* elf64-ia64-vms.c (elf64_ia64_info_to_howto): Likewise.
* elf64-mips.c (mips_elf64_info_to_howto_rela): Likewise.
* elf64-mmix.c (mmix_info_to_howto_rela): Likewise.
* elf64-ppc.c (ppc64_elf_info_to_howto): Likewise.
* elf64-s390.c (elf_s390_reloc_type_lookup): Likewise.
* elf64-sh64.c (elf_s390_info_to_howto, sh_elf64_info_to_howto): Likewise.
* elf64-x86-64.c (elf_x86_64_info_to_howto): Likewise.
* elfn32-mips.c (mips_info_to_howto_rel, mips_info_to_howto_rela): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_info_to_howto): Likewise.
* elfnn-ia64.c (elfNN_ia64_info_to_howto): Likewise.
* elfnn-riscv.c (riscv_info_to_howto_rela): Likewise.
* elfxx-ia64.c (ia64_elf_reloc_type_lookup): Likewise.
* elfxx-sparc.c (_bfd_sparc_elf_info_to_howto): Likewise.
* elfxx-tilegx.c (tilegx_info_to_howto_rela): Likewise.
* elf32-score.h (s7_bfd_score_info_to_howto): Update prototype.
* elfxx-sparc.h (_bfd_sparc_elf_info_to_howto): Update prototype.
* elfxx-tilegx.h (tilegx_info_to_howto_rela): Update prototype.
* elfxx-target.h (elf_info_to_howto, elf_info_to_howto_rel): Default to NULL.
binutils PR 22875
* objcopy.c (copy_object): Check the error status after marking symbols used in relocations.
* testsuite/binutils-all/strip-13.s: New test source file.
* testsuite/binutils-all/strip-13.s: New test driver file.
* testsuite/binutils-all/objcopy.exp: Run the new test.
95 files changed, 996 insertions, 415 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 3df1591..42dfaed 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,133 @@ +2018-02-27 Nick Clifton <nickc@redhat.com> + + PR 22875 + * elf-bfd.h (struct elf_backend_data): Change the return type of + the elf_info_to_howto and elf_info_to_howto_rel function pointers + to bfd_boolean. + * elfcode.h (elf_slurp_reloc_table_from_section): Check the return + value from the info_to_howto function and fail if that function + failed. + * elf32-h8300.c (elf32_h8_relocate_section): Check return value + from the info_to_howto function. + (elf32_h8_relax_section): Likewise. + * elf32-lm32.c (lm32_elf_relocate_section): Likewise. + * elf32-m68hc1x.c (elf32_m68hc11_relocate_section): Likewise. + * elf32-score.c (s3_bfd_score_elf_relocate_section): Likewise. + * elf32-score7.c (s7_bfd_score_elf_relocate_section): Likewise. + * elf32-tic6x.c (elf32_tic6x_relocate_section): Likewise. + * elf64-ia64-vms.c (elf64_ia64_relocate_section): Likewise. + * elf64-sparc.c (elf64_sparc_slurp_one_reloc_table): Likewise. + * elf64-x86-64.c (elf_x86_64_tls_transition): Likewise. + * elfnn-ia64.c (elfNN_ia64_relocate_section): Likewise. + * elfnn-riscv.c (riscv_elf_check_relocs): Likewise. + (riscv_elf_relocate_section): Likewise. + * elf-hppa.h (elf_hppa_info_to_howto): Change return type to + bfd_boolean. Issue an error message, set an error value and + return FALSE if the reloc is not recognized. + (elf_hppa_info_to_howto_rel): Likewise. + * elf-m10200.c (mn10200_info_to_howto): Likewise. + * elf-m10300.c (mn10300_info_to_howto): Likewise. + * elf.c (_bfd_elf_no_info_to_howto): Likewise. + * elf32-arc.c (arc_info_to_howto_rel): Likewise. + * elf32-arm.c (elf32_arm_info_to_howto): Likewise. + * elf32-avr.c (avr_info_to_howto_rela): Likewise. + * elf32-bfin.c (bfin_info_to_howto): Likewise. + * elf32-cr16.c (elf_cr16_info_to_howto): Likewise. + * elf32-cr16c.c (elf_cr16c_info_to_howto): Likewise. + * elf32-cris.c (elf_cr16c_info_to_howto_rel) + (cris_info_to_howto_rela): Likewise. + * elf32-crx.c (elf_crx_info_to_howto): Likewise. + * elf32-d10v.c (d10v_info_to_howto_rel): Likewise. + * elf32-d30v.c (d30v_info_to_howto_rel, d30v_info_to_howto_rela): + Likewise. + * elf32-dlx.c (dlx_rtype_to_howto, elf32_dlx_info_to_howto) + (elf32_dlx_info_to_howto_rel): Likewise. + * elf32-epiphany.c (epiphany_info_to_howto_rela): Likewise. + * elf32-fr30.c (fr30_info_to_howto_rela): Likewise. + * elf32-frv.c (frv_info_to_howto_rela) + (frvfdpic_info_to_howto_rel): Likewise. + * elf32-ft32.c (ft32_info_to_howto_rela): Likewise. + * elf32-gen.c (elf_generic_info_to_howto) + (elf_generic_info_to_howto_rel): Likewise. + * elf32-h8300.c (elf32_h8_info_to_howto) + (elf32_h8_info_to_howto_rel): Likewise. + * elf32-i370.c (i370_elf_info_to_howto): Likewise. + * elf32-i386.c (elf_i386_reloc_type_lookup) + (elf_i386_rtype_to_howto, elf_i386_info_to_howto_rel): Likewise. + * elf32-i860.c (lookup_howto, elf32_i860_info_to_howto_rela): + Likewise. + * elf32-i960.c (elf32_i960_info_to_howto_rel): Likewise. + * elf32-ip2k.c (ip2k_info_to_howto_rela): Likewise. + * elf32-iq2000.c (iq2000_info_to_howto_rela): Likewise. + * elf32-lm32.c (lm32_info_to_howto_rela): Likewise. + * elf32-m32c.c (m32c_info_to_howto_rela): Likewise. + * elf32-m32r.c (m32r_info_to_howto_rel, m32r_info_to_howto): + Likewise. + * elf32-m68hc11.c (m68hc11_info_to_howto_rel): Likewise. + * elf32-m68hc12.c (m68hc11_info_to_howto_rel): Likewise. + * elf32-m68k.c (rtype_to_howto): Likewise. + * elf32-mcore.c (mcore_elf_info_to_howto): Likewise. + * elf32-mep.c (mep_info_to_howto_rela): Likewise. + * elf32-metag.c (metag_info_to_howto_rela): Likewise. + * elf32-microblaze.c (microblaze_elf_info_to_howto): Likewise. + * elf32-mips.c (mips_info_to_howto_rel, mips_info_to_howto_rela): + Likewise. + * elf32-moxie.c (moxie_info_to_howto_rela): Likewise. + * elf32-msp430.c (msp430_info_to_howto_rela): Likewise. + * elf32-mt.c (mt_info_to_howto_rela): Likewise. + * elf32-nds32.c (nds32_info_to_howto_rel, nds32_info_to_howto): + Likewise. + * elf32-nios2.c (nios2_elf32_info_to_howto): Likewise. + * elf32-or1k.c (or1k_info_to_howto_rela): Likewise. + * elf32-pj.c (pj_elf_info_to_howto): Likewise. + * elf32-ppc.c (ppc_elf_info_to_howto): Likewise. + * elf32-pru.c (pru_elf32_info_to_howto): Likewise. + * elf32-rl78.c (rl78_info_to_howto_rela): Likewise. + * elf32-rx.c (rx_info_to_howto_rela): Likewise. + * elf32-s390.c (elf_s390_info_to_howto): Likewise. + * elf32-score.c (s3_bfd_score_info_to_howto) + (_bfd_score_info_to_howto): Likewise. + * elf32-score7.c (s7_bfd_score_info_to_howto): Likewise. + * elf32-sh.c (sh_elf_info_to_howto): Likewise. + * elf32-spu.c (spu_elf_info_to_howto): Likewise. + * elf32-tic6x.c (elf32_tic6x_info_to_howto) + (elf32_tic6x_info_to_howto_rel): Likewise. + * elf32-tilepro.c (tilepro_info_to_howto_rela): Likewise. + * elf32-v850.c (v850_elf_info_to_howto_rel) + (v850_elf_info_to_howto_rela, v800_elf_info_to_howto): Likewise. + * elf32-vax.c (rtype_to_howto): Likewise. + * elf32-visium.c (visium_info_to_howto_rela): Likewise. + * elf32-wasm32.c (elf32_wasm32_rtype_to_howto) + (elf32_wasm32_info_to_howto_rela): Likewise. + * elf32-xc16x.c (elf32_xc16x_info_to_howto): Likewise. + * elf32-xgate.c (xgate_info_to_howto_rel): Likewise. + * elf32-xstormy16.c (xstormy16_info_to_howto_rela): Likewise. + * elf32-xtensa.c (elf_xtensa_info_to_howto_rela): Likewise. + * elf64-alpha.c (elf64_alpha_info_to_howto): Likewise. + * elf64-gen.c (elf_generic_info_to_howto) + (elf_generic_info_to_howto_rel): Likewise. + * elf64-ia64-vms.c (elf64_ia64_info_to_howto): Likewise. + * elf64-mips.c (mips_elf64_info_to_howto_rela): Likewise. + * elf64-mmix.c (mmix_info_to_howto_rela): Likewise. + * elf64-ppc.c (ppc64_elf_info_to_howto): Likewise. + * elf64-s390.c (elf_s390_reloc_type_lookup): Likewise. + * elf64-sh64.c (elf_s390_info_to_howto, sh_elf64_info_to_howto): + Likewise. + * elf64-x86-64.c (elf_x86_64_info_to_howto): Likewise. + * elfn32-mips.c (mips_info_to_howto_rel, mips_info_to_howto_rela): + Likewise. + * elfnn-aarch64.c (elfNN_aarch64_info_to_howto): Likewise. + * elfnn-ia64.c (elfNN_ia64_info_to_howto): Likewise. + * elfnn-riscv.c (riscv_info_to_howto_rela): Likewise. + * elfxx-ia64.c (ia64_elf_reloc_type_lookup): Likewise. + * elfxx-sparc.c (_bfd_sparc_elf_info_to_howto): Likewise. + * elfxx-tilegx.c (tilegx_info_to_howto_rela): Likewise. + * elf32-score.h (s7_bfd_score_info_to_howto): Update prototype. + * elfxx-sparc.h (_bfd_sparc_elf_info_to_howto): Update prototype. + * elfxx-tilegx.h (tilegx_info_to_howto_rela): Update prototype. + * elfxx-target.h (elf_info_to_howto, elf_info_to_howto_rel): + Default to NULL. + 2018-02-26 Jim Wilson <jimw@sifive.com> Stephan Schreiber <info@fs-driver.org> diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 1edb31e..afd6982 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -872,13 +872,13 @@ struct elf_backend_data const void *arch_data; /* A function to translate an ELF RELA relocation to a BFD arelent - structure. */ - void (*elf_info_to_howto) + structure. Returns TRUE upon success, FALSE otherwise. */ + bfd_boolean (*elf_info_to_howto) (bfd *, arelent *, Elf_Internal_Rela *); /* A function to translate an ELF REL relocation to a BFD arelent - structure. */ - void (*elf_info_to_howto_rel) + structure. Returns TRUE upon success, FALSE otherwise. */ + bfd_boolean (*elf_info_to_howto_rel) (bfd *, arelent *, Elf_Internal_Rela *); /* A function to determine whether a symbol is global when @@ -2181,7 +2181,7 @@ extern const struct bfd_elf_special_section *_bfd_elf_get_sec_type_attr (bfd *, asection *); /* If the target doesn't have reloc handling written yet: */ -extern void _bfd_elf_no_info_to_howto +extern bfd_boolean _bfd_elf_no_info_to_howto (bfd *, arelent *, Elf_Internal_Rela *); extern bfd_boolean bfd_section_from_shdr diff --git a/bfd/elf-hppa.h b/bfd/elf-hppa.h index b87ee83..75b4e26 100644 --- a/bfd/elf-hppa.h +++ b/bfd/elf-hppa.h @@ -1020,26 +1020,44 @@ _bfd_elf_hppa_gen_reloc_type (bfd *abfd, /* Translate from an elf into field into a howto relocation pointer. */ -static void +static bfd_boolean elf_hppa_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc) { - BFD_ASSERT (ELF_R_TYPE (elf_reloc->r_info) - < (unsigned int) R_PARISC_UNIMPLEMENTED); - bfd_reloc->howto = &elf_hppa_howto_table[ELF_R_TYPE (elf_reloc->r_info)]; + unsigned int r_type = ELF32_R_TYPE (elf_reloc->r_info); + + if (r_type >= (unsigned int) R_PARISC_UNIMPLEMENTED) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + bfd_reloc->howto = &elf_hppa_howto_table[r_type]; + return TRUE; } /* Translate from an elf into field into a howto relocation pointer. */ -static void -elf_hppa_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, +static bfd_boolean +elf_hppa_info_to_howto_rel (bfd *abfd, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc) { - BFD_ASSERT (ELF_R_TYPE (elf_reloc->r_info) - < (unsigned int) R_PARISC_UNIMPLEMENTED); - bfd_reloc->howto = &elf_hppa_howto_table[ELF_R_TYPE (elf_reloc->r_info)]; + unsigned int r_type = ELF_R_TYPE (elf_reloc->r_info); + + if (r_type >= (unsigned int) R_PARISC_UNIMPLEMENTED) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: invalid relocation type %d"), abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + + bfd_reloc->howto = &elf_hppa_howto_table[r_type]; + return TRUE; } /* Return the address of the howto table entry to perform the CODE diff --git a/bfd/elf-m10200.c b/bfd/elf-m10200.c index 82c4ee7..cc71c1e 100644 --- a/bfd/elf-m10200.c +++ b/bfd/elf-m10200.c @@ -212,16 +212,25 @@ bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an MN10200 ELF reloc. */ -static void -mn10200_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, +static bfd_boolean +mn10200_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type; r_type = ELF32_R_TYPE (dst->r_info); - BFD_ASSERT (r_type < (unsigned int) R_MN10200_MAX); + if (r_type >= (unsigned int) R_MN10200_MAX) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + cache_ptr->howto = &elf_mn10200_howto_table[r_type]; + return cache_ptr->howto != NULL; } /* Perform a relocation as part of a final link. */ @@ -1378,7 +1387,7 @@ mn10200_elf_get_relocated_section_contents (bfd *output_bfd, #define elf_backend_rela_normal 1 #define elf_info_to_howto mn10200_info_to_howto -#define elf_info_to_howto_rel 0 +#define elf_info_to_howto_rel NULL #define elf_backend_relocate_section mn10200_elf_relocate_section #define bfd_elf32_bfd_relax_section mn10200_elf_relax_section #define bfd_elf32_bfd_get_relocated_section_contents \ diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c index d578416..f86346e 100644 --- a/bfd/elf-m10300.c +++ b/bfd/elf-m10300.c @@ -798,7 +798,7 @@ bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an MN10300 ELF reloc. */ -static void +static bfd_boolean mn10300_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -812,9 +812,10 @@ mn10300_info_to_howto (bfd *abfd, _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); - r_type = R_MN10300_NONE; + return FALSE; } cache_ptr->howto = elf_mn10300_howto_table + r_type; + return TRUE; } static int @@ -5544,7 +5545,7 @@ mn10300_elf_mkobject (bfd *abfd) #endif #define elf_info_to_howto mn10300_info_to_howto -#define elf_info_to_howto_rel 0 +#define elf_info_to_howto_rel NULL #define elf_backend_can_gc_sections 1 #define elf_backend_rela_normal 1 #define elf_backend_check_relocs mn10300_elf_check_relocs @@ -8870,12 +8870,13 @@ _bfd_elf_set_section_contents (bfd *abfd, return TRUE; } -void +bfd_boolean _bfd_elf_no_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr ATTRIBUTE_UNUSED, Elf_Internal_Rela *dst ATTRIBUTE_UNUSED) { abort (); + return FALSE; } /* Try to convert a non-ELF reloc into an ELF one. */ diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c index 3bee87d..33fff58 100644 --- a/bfd/elf32-arc.c +++ b/bfd/elf32-arc.c @@ -505,16 +505,25 @@ bfd_elf32_bfd_reloc_name_lookup (bfd * abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an ARC ELF reloc. */ -static void -arc_info_to_howto_rel (bfd * abfd ATTRIBUTE_UNUSED, +static bfd_boolean +arc_info_to_howto_rel (bfd * abfd, arelent * cache_ptr, Elf_Internal_Rela * dst) { unsigned int r_type; r_type = ELF32_R_TYPE (dst->r_info); - BFD_ASSERT (r_type < (unsigned int) R_ARC_max); + if (r_type >= (unsigned int) R_ARC_max) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + cache_ptr->howto = arc_elf_howto (r_type); + return TRUE; } /* Extract CPU features from an NTBS. */ diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index 881f2cf..ce9c2f2 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -56,7 +56,7 @@ ? bfd_elf32_swap_reloc_out \ : bfd_elf32_swap_reloca_out) -#define elf_info_to_howto 0 +#define elf_info_to_howto NULL #define elf_info_to_howto_rel elf32_arm_info_to_howto #define ARM_ELF_ABI_VERSION 0 @@ -1839,14 +1839,22 @@ elf32_arm_howto_from_type (unsigned int r_type) return NULL; } -static void -elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc, +static bfd_boolean +elf32_arm_info_to_howto (bfd * abfd, arelent * bfd_reloc, Elf_Internal_Rela * elf_reloc) { unsigned int r_type; r_type = ELF32_R_TYPE (elf_reloc->r_info); - bfd_reloc->howto = elf32_arm_howto_from_type (r_type); + if ((bfd_reloc->howto = elf32_arm_howto_from_type (r_type)) == NULL) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + return TRUE; } struct elf32_arm_reloc_map @@ -3142,7 +3150,7 @@ struct elf32_arm_link_hash_table int nacl_p; /* True if the target uses REL relocations. */ - int use_rel; + bfd_boolean use_rel; /* Nonzero if import library must be a secure gateway import library as per ARMv8-M Security Extensions. */ @@ -3796,7 +3804,7 @@ elf32_arm_link_hash_table_create (bfd *abfd) ret->plt_header_size = 20; ret->plt_entry_size = elf32_arm_use_long_plt_entry ? 16 : 12; #endif - ret->use_rel = 1; + ret->use_rel = TRUE; ret->obfd = abfd; if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc, diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c index 74934de..7087606 100644 --- a/bfd/elf32-avr.c +++ b/bfd/elf32-avr.c @@ -945,7 +945,7 @@ bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an AVR ELF reloc. */ -static void +static bfd_boolean avr_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -958,9 +958,11 @@ avr_info_to_howto_rela (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &elf_avr_howto_table[r_type]; + return TRUE; } static bfd_boolean diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c index 8f15f9a..ae83771 100644 --- a/bfd/elf32-bfin.c +++ b/bfd/elf32-bfin.c @@ -1040,8 +1040,8 @@ static const struct bfin_reloc_map bfin_reloc_map [] = }; -static void -bfin_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, +static bfd_boolean +bfin_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { @@ -1056,7 +1056,15 @@ bfin_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, cache_ptr->howto = &bfin_gnuext_howto_table [r_type - BFIN_GNUEXT_RELOC_MIN]; else - cache_ptr->howto = (reloc_howto_type *) NULL; + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + + return TRUE; } /* Given a BFD reloc type, return the howto. */ @@ -5424,7 +5432,7 @@ struct bfd_elf_special_section const elf32_bfin_special_sections[] = #define bfd_elf32_bfd_reloc_name_lookup \ bfin_bfd_reloc_name_lookup #define elf_info_to_howto bfin_info_to_howto -#define elf_info_to_howto_rel 0 +#define elf_info_to_howto_rel NULL #define elf_backend_object_p elf32_bfin_object_p #define bfd_elf32_bfd_is_local_label_name \ diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c index 46d9fe2..7756ef5 100644 --- a/bfd/elf32-cr16.c +++ b/bfd/elf32-cr16.c @@ -671,7 +671,7 @@ elf_cr16_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Retrieve a howto ptr using an internal relocation entry. */ -static void +static bfd_boolean elf_cr16_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { @@ -683,9 +683,10 @@ elf_cr16_info_to_howto (bfd *abfd, arelent *cache_ptr, _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. @@ -2895,7 +2896,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 \ diff --git a/bfd/elf32-cr16c.c b/bfd/elf32-cr16c.c index f2793a9..40ec759 100644 --- a/bfd/elf32-cr16c.c +++ b/bfd/elf32-cr16c.c @@ -165,15 +165,15 @@ elf_cr16c_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, return NULL; } -static void +static bfd_boolean elf_cr16c_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr ATTRIBUTE_UNUSED, Elf_Internal_Rela *dst ATTRIBUTE_UNUSED) { - abort (); + return FALSE; } -static void +static bfd_boolean elf_cr16c_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -185,9 +185,11 @@ elf_cr16c_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &elf_howto_table[r_type]; + return TRUE; } /* Perform a relocation as part of a final link. */ diff --git a/bfd/elf32-cris.c b/bfd/elf32-cris.c index f47deb0..1c367c4 100644 --- a/bfd/elf32-cris.c +++ b/bfd/elf32-cris.c @@ -453,7 +453,7 @@ cris_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) /* Set the howto pointer for an CRIS ELF reloc. */ -static void +static bfd_boolean cris_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED, arelent * cache_ptr, Elf_Internal_Rela * dst) @@ -466,9 +466,11 @@ cris_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = & cris_elf_howto_table [r_type]; + return TRUE; } bfd_reloc_status_type diff --git a/bfd/elf32-crx.c b/bfd/elf32-crx.c index 90857c8..fde3a58 100644 --- a/bfd/elf32-crx.c +++ b/bfd/elf32-crx.c @@ -28,7 +28,7 @@ static reloc_howto_type *elf_crx_reloc_type_lookup (bfd *, bfd_reloc_code_real_type); -static void elf_crx_info_to_howto +static bfd_boolean elf_crx_info_to_howto (bfd *, arelent *, Elf_Internal_Rela *); static bfd_boolean elf32_crx_relax_delete_bytes (struct bfd_link_info *, bfd *, asection *, bfd_vma, int); @@ -418,7 +418,7 @@ elf_crx_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Retrieve a howto ptr using an internal relocation entry. */ -static void +static bfd_boolean elf_crx_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { @@ -429,9 +429,10 @@ elf_crx_info_to_howto (bfd *abfd, arelent *cache_ptr, _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); - r_type = R_CRX_NONE; + return FALSE; } cache_ptr->howto = &crx_elf_howto_table[r_type]; + return TRUE; } /* Perform a relocation as part of a final link. */ @@ -1320,7 +1321,7 @@ elf32_crx_relax_section (bfd *abfd, asection *sec, #define bfd_elf32_bfd_reloc_name_lookup \ elf_crx_reloc_name_lookup #define elf_info_to_howto elf_crx_info_to_howto -#define elf_info_to_howto_rel 0 +#define elf_info_to_howto_rel NULL #define elf_backend_relocate_section elf32_crx_relocate_section #define bfd_elf32_bfd_relax_section elf32_crx_relax_section #define bfd_elf32_bfd_get_relocated_section_contents \ diff --git a/bfd/elf32-d10v.c b/bfd/elf32-d10v.c index 8dac777..c901595 100644 --- a/bfd/elf32-d10v.c +++ b/bfd/elf32-d10v.c @@ -220,7 +220,7 @@ bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an D10V ELF reloc. */ -static void +static bfd_boolean d10v_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -233,9 +233,11 @@ d10v_info_to_howto_rel (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &elf_d10v_howto_table[r_type]; + return TRUE; } static asection * @@ -540,7 +542,7 @@ elf32_d10v_relocate_section (bfd *output_bfd, #define TARGET_BIG_SYM d10v_elf32_vec #define TARGET_BIG_NAME "elf32-d10v" -#define elf_info_to_howto 0 +#define elf_info_to_howto NULL #define elf_info_to_howto_rel d10v_info_to_howto_rel #define elf_backend_object_p 0 #define elf_backend_final_write_processing 0 diff --git a/bfd/elf32-d30v.c b/bfd/elf32-d30v.c index 984b4c4..7620a73 100644 --- a/bfd/elf32-d30v.c +++ b/bfd/elf32-d30v.c @@ -508,7 +508,7 @@ bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an D30V ELF reloc (type REL). */ -static void +static bfd_boolean d30v_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -521,14 +521,16 @@ d30v_info_to_howto_rel (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &elf_d30v_howto_table[r_type]; + return TRUE; } /* Set the howto pointer for an D30V ELF reloc (type RELA). */ -static void +static bfd_boolean d30v_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -541,9 +543,11 @@ d30v_info_to_howto_rela (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &elf_d30v_howto_table[r_type]; + return TRUE; } #define ELF_ARCH bfd_arch_d30v diff --git a/bfd/elf32-dlx.c b/bfd/elf32-dlx.c index 907eddd..d82d3ea 100644 --- a/bfd/elf32-dlx.c +++ b/bfd/elf32-dlx.c @@ -547,21 +547,22 @@ dlx_rtype_to_howto (bfd *abfd, unsigned int r_type) { _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return NULL; } return & dlx_elf_howto_table[r_type]; } } -static void +static bfd_boolean elf32_dlx_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * cache_ptr ATTRIBUTE_UNUSED, Elf_Internal_Rela * dst ATTRIBUTE_UNUSED) { - abort (); + return FALSE; } -static void +static bfd_boolean elf32_dlx_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -570,7 +571,7 @@ elf32_dlx_info_to_howto_rel (bfd *abfd, r_type = ELF32_R_TYPE (dst->r_info); cache_ptr->howto = dlx_rtype_to_howto (abfd, r_type); - return; + return cache_ptr->howto != NULL; } #define TARGET_BIG_SYM dlx_elf32_be_vec diff --git a/bfd/elf32-epiphany.c b/bfd/elf32-epiphany.c index 8c24541..efbd67b 100644 --- a/bfd/elf32-epiphany.c +++ b/bfd/elf32-epiphany.c @@ -362,7 +362,7 @@ epiphany_elf_relax_section (bfd *abfd, asection *sec, /* Set the howto pointer for a EPIPHANY ELF reloc. */ -static void +static bfd_boolean epiphany_info_to_howto_rela (bfd * abfd, arelent * cache_ptr, Elf_Internal_Rela * dst) @@ -375,9 +375,11 @@ epiphany_info_to_howto_rela (bfd * abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = & epiphany_elf_howto_table [r_type]; + return TRUE; } /* Perform a single relocation. diff --git a/bfd/elf32-fr30.c b/bfd/elf32-fr30.c index 6d8a040..7b0fc88 100644 --- a/bfd/elf32-fr30.c +++ b/bfd/elf32-fr30.c @@ -367,7 +367,7 @@ fr30_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) /* Set the howto pointer for an FR30 ELF reloc. */ -static void +static bfd_boolean fr30_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -380,9 +380,11 @@ fr30_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = & fr30_elf_howto_table [r_type]; + return TRUE; } /* Perform a single relocation. By default we use the standard BFD diff --git a/bfd/elf32-frv.c b/bfd/elf32-frv.c index 91815df..7831aff 100644 --- a/bfd/elf32-frv.c +++ b/bfd/elf32-frv.c @@ -2532,7 +2532,7 @@ frv_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) /* Set the howto pointer for an FRV ELF reloc. */ -static void +static bfd_boolean frv_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -2556,15 +2556,18 @@ frv_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = & elf32_frv_howto_table [r_type]; break; } + return TRUE; } /* Set the howto pointer for an FRV ELF REL reloc. */ -static void + +static bfd_boolean frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, Elf_Internal_Rela *dst) { @@ -2595,8 +2598,9 @@ frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, default: cache_ptr->howto = NULL; - break; + return FALSE; } + return TRUE; } /* Perform a single relocation. By default we use the standard BFD diff --git a/bfd/elf32-ft32.c b/bfd/elf32-ft32.c index 86157d8..b981a34 100644 --- a/bfd/elf32-ft32.c +++ b/bfd/elf32-ft32.c @@ -292,16 +292,25 @@ ft32_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) /* Set the howto pointer for an FT32 ELF reloc. */ -static void -ft32_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, +static bfd_boolean +ft32_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type; r_type = ELF32_R_TYPE (dst->r_info); - BFD_ASSERT (r_type < (unsigned int) R_FT32_max); + if (r_type < (unsigned int) R_FT32_max) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + cache_ptr->howto = & ft32_elf_howto_table [r_type]; + return cache_ptr->howto != NULL; } /* Relocate an FT32 ELF section. diff --git a/bfd/elf32-gen.c b/bfd/elf32-gen.c index 8f9e338..1d907a0 100644 --- a/bfd/elf32-gen.c +++ b/bfd/elf32-gen.c @@ -41,20 +41,22 @@ static reloc_howto_type dummy = 0, /* dst_mask */ FALSE); /* pcrel_offset */ -static void +static bfd_boolean elf_generic_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc ATTRIBUTE_UNUSED) { bfd_reloc->howto = &dummy; + return TRUE; } -static void +static bfd_boolean elf_generic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc ATTRIBUTE_UNUSED) { bfd_reloc->howto = &dummy; + return TRUE; } static void diff --git a/bfd/elf32-h8300.c b/bfd/elf32-h8300.c index 0412424..a41ae63 100644 --- a/bfd/elf32-h8300.c +++ b/bfd/elf32-h8300.c @@ -26,9 +26,9 @@ static reloc_howto_type *elf32_h8_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code); -static void elf32_h8_info_to_howto +static bfd_boolean elf32_h8_info_to_howto (bfd *, arelent *, Elf_Internal_Rela *); -static void elf32_h8_info_to_howto_rel +static bfd_boolean elf32_h8_info_to_howto_rel (bfd *, arelent *, Elf_Internal_Rela *); static unsigned long elf32_h8_mach (flagword); static void elf32_h8_final_write_processing (bfd *, bfd_boolean); @@ -284,7 +284,7 @@ elf32_h8_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, return NULL; } -static void +static bfd_boolean elf32_h8_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc) { @@ -296,20 +296,20 @@ elf32_h8_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, if (h8_elf_howto_table[i].type == r) { bfd_reloc->howto = &h8_elf_howto_table[i]; - return; + return TRUE; } - abort (); + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r); + bfd_set_error (bfd_error_bad_value); + return FALSE; } -static void -elf32_h8_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, +static bfd_boolean +elf32_h8_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, + arelent *bfd_reloc ATTRIBUTE_UNUSED, Elf_Internal_Rela *elf_reloc ATTRIBUTE_UNUSED) { - unsigned int r; - - abort (); - r = ELF32_R_TYPE (elf_reloc->r_info); - bfd_reloc->howto = &h8_elf_howto_table[r]; + return FALSE; } /* Special handling for H8/300 relocs. @@ -453,7 +453,8 @@ elf32_h8_relocate_section (bfd *output_bfd, struct bfd_link_info *info, arelent bfd_reloc; reloc_howto_type *howto; - elf32_h8_info_to_howto (input_bfd, &bfd_reloc, rel); + if (! elf32_h8_info_to_howto (input_bfd, &bfd_reloc, rel)) + continue; howto = bfd_reloc.howto; r_symndx = ELF32_R_SYM (rel->r_info); @@ -733,7 +734,8 @@ elf32_h8_relax_section (bfd *abfd, asection *sec, { arelent bfd_reloc; - elf32_h8_info_to_howto (abfd, &bfd_reloc, irel); + if (! elf32_h8_info_to_howto (abfd, &bfd_reloc, irel)) + continue; } /* Keep track of the previous reloc so that we can delete some long jumps created by the compiler. */ @@ -1249,7 +1251,8 @@ elf32_h8_relax_section (bfd *abfd, asection *sec, reloc_howto_type *h; bfd_vma last_reloc_size; - elf32_h8_info_to_howto (abfd, &bfd_reloc, last_reloc); + if (! elf32_h8_info_to_howto (abfd, &bfd_reloc, last_reloc)) + break; h = bfd_reloc.howto; last_reloc_size = 1 << h->size; if (last_reloc->r_offset + last_reloc_size @@ -1267,7 +1270,8 @@ elf32_h8_relax_section (bfd *abfd, asection *sec, reloc_howto_type *h; bfd_vma next_reloc_size; - elf32_h8_info_to_howto (abfd, &bfd_reloc, next_reloc); + if (! elf32_h8_info_to_howto (abfd, &bfd_reloc, next_reloc)) + break; h = bfd_reloc.howto; next_reloc_size = 1 << h->size; if (next_reloc->r_offset + next_reloc_size diff --git a/bfd/elf32-i370.c b/bfd/elf32-i370.c index 79ec159..2c6a30d 100644 --- a/bfd/elf32-i370.c +++ b/bfd/elf32-i370.c @@ -289,7 +289,7 @@ i370_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an i370 ELF reloc. */ -static void +static bfd_boolean i370_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -307,9 +307,10 @@ i370_elf_info_to_howto (bfd *abfd, _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); - r_type = R_I370_NONE; + return FALSE; } cache_ptr->howto = i370_elf_howto_table[r_type]; + return TRUE; } /* Hack alert -- the following several routines look generic to me ... diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 32b84e6..5163e24 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -194,7 +194,7 @@ static reloc_howto_type elf_howto_table[]= #endif static reloc_howto_type * -elf_i386_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, +elf_i386_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code) { switch (code) @@ -346,11 +346,13 @@ elf_i386_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, return &elf_howto_table[R_386_GNU_VTENTRY - R_386_vt_offset]; default: - break; + TRACE ("Unknown"); + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: invalid Alpha reloc number: %d"), + abfd, (int) code); + bfd_set_error (bfd_error_bad_value); + return NULL; } - - TRACE ("Unknown"); - return 0; } static reloc_howto_type * @@ -368,7 +370,7 @@ elf_i386_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, } static reloc_howto_type * -elf_i386_rtype_to_howto (bfd *abfd, unsigned r_type) +elf_i386_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED, unsigned r_type) { unsigned int indx; @@ -379,25 +381,30 @@ elf_i386_rtype_to_howto (bfd *abfd, unsigned r_type) >= R_386_ext2 - R_386_ext) && ((indx = r_type - R_386_vt_offset) - R_386_ext2 >= R_386_vt - R_386_ext2)) - { - /* xgettext:c-format */ - _bfd_error_handler (_("%pB: unsupported relocation type %#x"), - abfd, r_type); - indx = R_386_NONE; - } + return NULL; /* PR 17512: file: 0f67f69d. */ if (elf_howto_table [indx].type != r_type) return NULL; return &elf_howto_table[indx]; } -static void -elf_i386_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, +static bfd_boolean +elf_i386_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type = ELF32_R_TYPE (dst->r_info); - cache_ptr->howto = elf_i386_rtype_to_howto (abfd, r_type); + + if ((cache_ptr->howto = elf_i386_rtype_to_howto (abfd, r_type)) == NULL) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + + return TRUE; } /* Return whether a symbol name implies a local label. The UnixWare diff --git a/bfd/elf32-i860.c b/bfd/elf32-i860.c index e34965c..737e7f5 100644 --- a/bfd/elf32-i860.c +++ b/bfd/elf32-i860.c @@ -761,10 +761,11 @@ lookup_howto (unsigned int rtype) elf_code_to_howto_index[elf32_i860_howto_table[i].type] = i; } - BFD_ASSERT (rtype <= R_860_max); + if (rtype > R_860_max) + return NULL; i = elf_code_to_howto_index[rtype]; if (i >= howto_tbl_size) - return 0; + return NULL; return elf32_i860_howto_table + i; } @@ -880,8 +881,7 @@ elf32_i860_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, rtype = R_860_HIGOTOFF; break; default: - rtype = 0; - break; + return NULL; } return lookup_howto (rtype); } @@ -904,13 +904,15 @@ elf32_i860_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, } /* Given a ELF reloc, return the matching HOWTO structure. */ -static void + +static bfd_boolean elf32_i860_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc) { bfd_reloc->howto = lookup_howto ((unsigned) ELF32_R_TYPE (elf_reloc->r_info)); + return bfd_reloc->howto != NULL; } /* Specialized relocation handler for R_860_SPLITn. These relocations diff --git a/bfd/elf32-i960.c b/bfd/elf32-i960.c index dbfb1bb..244e4ea 100644 --- a/bfd/elf32-i960.c +++ b/bfd/elf32-i960.c @@ -29,7 +29,7 @@ #define bfd_elf32_bfd_reloc_type_lookup elf32_i960_reloc_type_lookup #define bfd_elf32_bfd_reloc_name_lookup \ elf32_i960_reloc_name_lookup -#define elf_info_to_howto elf32_i960_info_to_howto +#define elf_info_to_howto NULL #define elf_info_to_howto_rel elf32_i960_info_to_howto_rel /* ELF relocs are against symbols. If we are producing relocatable @@ -116,15 +116,7 @@ elf32_i960_bfd_to_reloc_type (bfd_reloc_code_real_type code) } } -static void -elf32_i960_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, - arelent * cache_ptr ATTRIBUTE_UNUSED, - Elf_Internal_Rela * dst ATTRIBUTE_UNUSED) -{ - abort (); -} - -static void +static bfd_boolean elf32_i960_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -139,10 +131,12 @@ elf32_i960_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, type); - type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &elf_howto_table[(int) type]; + return TRUE; } static reloc_howto_type * diff --git a/bfd/elf32-ip2k.c b/bfd/elf32-ip2k.c index aa93524..1432f18 100644 --- a/bfd/elf32-ip2k.c +++ b/bfd/elf32-ip2k.c @@ -1231,7 +1231,7 @@ ip2k_elf_relax_section (bfd *abfd, /* Set the howto pointer for a IP2K ELF reloc. */ -static void +static bfd_boolean ip2k_info_to_howto_rela (bfd * abfd, arelent * cache_ptr, Elf_Internal_Rela * dst) @@ -1244,9 +1244,11 @@ ip2k_info_to_howto_rela (bfd * abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = & ip2k_elf_howto_table [r_type]; + return TRUE; } /* Perform a single relocation. diff --git a/bfd/elf32-iq2000.c b/bfd/elf32-iq2000.c index 14cd167..d1ce3c8 100644 --- a/bfd/elf32-iq2000.c +++ b/bfd/elf32-iq2000.c @@ -416,7 +416,7 @@ iq2000_final_link_relocate (reloc_howto_type * howto, /* Set the howto pointer for a IQ2000 ELF reloc. */ -static void +static bfd_boolean iq2000_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED, arelent * cache_ptr, Elf_Internal_Rela * dst) @@ -440,11 +440,13 @@ iq2000_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = & iq2000_elf_howto_table [r_type]; break; } + return TRUE; } /* Look through the relocs for a section during the first phase. diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c index 0cd67b4..027830b 100644 --- a/bfd/elf32-lm32.c +++ b/bfd/elf32-lm32.c @@ -525,7 +525,7 @@ lm32_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an Lattice Mico32 ELF reloc. */ -static void +static bfd_boolean lm32_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -538,9 +538,11 @@ lm32_info_to_howto_rela (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &lm32_elf_howto_table[r_type]; + return TRUE; } /* Set the right machine number for an Lattice Mico32 ELF file. */ @@ -1076,7 +1078,8 @@ lm32_elf_relocate_section (bfd *output_bfd, const char *msg = NULL; arelent bfd_reloc; - lm32_info_to_howto_rela (input_bfd, &bfd_reloc, rel); + if (! lm32_info_to_howto_rela (input_bfd, &bfd_reloc, rel)) + continue; howto = bfd_reloc.howto; if (h != NULL) @@ -2568,7 +2571,7 @@ lm32_elf_fdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd) #define bfd_elf32_bfd_reloc_type_lookup lm32_reloc_type_lookup #define bfd_elf32_bfd_reloc_name_lookup lm32_reloc_name_lookup #define elf_info_to_howto lm32_info_to_howto_rela -#define elf_info_to_howto_rel 0 +#define elf_info_to_howto_rel NULL #define elf_backend_rela_normal 1 #define elf_backend_object_p lm32_elf_object_p #define elf_backend_final_write_processing lm32_elf_final_write_processing diff --git a/bfd/elf32-m32c.c b/bfd/elf32-m32c.c index 6e7e71c..613844a 100644 --- a/bfd/elf32-m32c.c +++ b/bfd/elf32-m32c.c @@ -28,7 +28,7 @@ /* Forward declarations. */ static reloc_howto_type * m32c_reloc_type_lookup (bfd *, bfd_reloc_code_real_type); -static void m32c_info_to_howto_rela +static bfd_boolean m32c_info_to_howto_rela (bfd *, arelent *, Elf_Internal_Rela *); static bfd_boolean m32c_elf_relocate_section (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *, asection **); @@ -291,10 +291,10 @@ m32c_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) /* Set the howto pointer for an M32C ELF reloc. */ -static void -m32c_info_to_howto_rela (bfd *abfd, - arelent *cache_ptr, - Elf_Internal_Rela *dst) +static bfd_boolean +m32c_info_to_howto_rela (bfd * abfd, + arelent * cache_ptr, + Elf_Internal_Rela * dst) { unsigned int r_type; @@ -304,9 +304,11 @@ m32c_info_to_howto_rela (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = & m32c_elf_howto_table [r_type]; + return TRUE; } diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c index 0129c29..94a4bc9 100644 --- a/bfd/elf32-m32r.c +++ b/bfd/elf32-m32r.c @@ -1272,7 +1272,7 @@ bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an M32R ELF reloc. */ -static void +static bfd_boolean m32r_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -1285,20 +1285,32 @@ m32r_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &m32r_elf_howto_table[r_type]; + return TRUE; } -static void +static bfd_boolean m32r_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, Elf_Internal_Rela *dst) { - BFD_ASSERT ((ELF32_R_TYPE(dst->r_info) == (unsigned int) R_M32R_NONE) - || ((ELF32_R_TYPE(dst->r_info) > (unsigned int) R_M32R_GNU_VTENTRY) - && (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_M32R_max))); - cache_ptr->howto = &m32r_elf_howto_table[ELF32_R_TYPE(dst->r_info)]; + unsigned int r_type = ELF32_R_TYPE (dst->r_info); + + if (r_type == (unsigned int) R_M32R_NONE + || ((r_type > (unsigned int) R_M32R_GNU_VTENTRY) + && (r_type < (unsigned int) R_M32R_max))) + { + cache_ptr->howto = &m32r_elf_howto_table[r_type]; + return TRUE; + } + + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; } diff --git a/bfd/elf32-m68hc11.c b/bfd/elf32-m68hc11.c index 4c57fe8..95d271f 100644 --- a/bfd/elf32-m68hc11.c +++ b/bfd/elf32-m68hc11.c @@ -32,7 +32,7 @@ /* Relocation functions. */ static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup (bfd *, bfd_reloc_code_real_type); -static void m68hc11_info_to_howto_rel +static bfd_boolean m68hc11_info_to_howto_rel (bfd *, arelent *, Elf_Internal_Rela *); /* Trampoline generation. */ @@ -377,7 +377,7 @@ bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an M68HC11 ELF reloc. */ -static void +static bfd_boolean m68hc11_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { @@ -389,9 +389,11 @@ m68hc11_info_to_howto_rel (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &elf_m68hc11_howto_table[r_type]; + return TRUE; } @@ -1297,7 +1299,7 @@ static const struct bfd_elf_special_section elf32_m68hc11_special_sections[] = #define TARGET_BIG_SYM m68hc11_elf32_vec #define TARGET_BIG_NAME "elf32-m68hc11" -#define elf_info_to_howto 0 +#define elf_info_to_howto NULL #define elf_info_to_howto_rel m68hc11_info_to_howto_rel #define bfd_elf32_bfd_relax_section m68hc11_elf_relax_section #define elf_backend_check_relocs elf32_m68hc11_check_relocs diff --git a/bfd/elf32-m68hc12.c b/bfd/elf32-m68hc12.c index d2300c4..0b53674 100644 --- a/bfd/elf32-m68hc12.c +++ b/bfd/elf32-m68hc12.c @@ -32,7 +32,7 @@ /* Relocation functions. */ static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup (bfd *, bfd_reloc_code_real_type); -static void m68hc11_info_to_howto_rel +static bfd_boolean m68hc11_info_to_howto_rel (bfd *, arelent *, Elf_Internal_Rela *); /* Trampoline generation. */ @@ -497,7 +497,7 @@ bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an M68HC11 ELF reloc. */ -static void +static bfd_boolean m68hc11_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { @@ -509,9 +509,11 @@ m68hc11_info_to_howto_rel (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &elf_m68hc11_howto_table[r_type]; + return TRUE; } @@ -647,7 +649,7 @@ static const struct bfd_elf_special_section elf32_m68hc12_special_sections[] = #define TARGET_BIG_SYM m68hc12_elf32_vec #define TARGET_BIG_NAME "elf32-m68hc12" -#define elf_info_to_howto 0 +#define elf_info_to_howto NULL #define elf_info_to_howto_rel m68hc11_info_to_howto_rel #define elf_backend_check_relocs elf32_m68hc11_check_relocs #define elf_backend_relocate_section elf32_m68hc11_relocate_section diff --git a/bfd/elf32-m68hc1x.c b/bfd/elf32-m68hc1x.c index 794663a..35152ee 100644 --- a/bfd/elf32-m68hc1x.c +++ b/bfd/elf32-m68hc1x.c @@ -963,7 +963,8 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, || r_type == R_M68HC11_GNU_VTINHERIT) continue; - (*ebd->elf_info_to_howto_rel) (input_bfd, &arel, rel); + if (! (*ebd->elf_info_to_howto_rel) (input_bfd, &arel, rel)) + continue; howto = arel.howto; h = NULL; diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c index 2718564..8680504 100644 --- a/bfd/elf32-m68k.c +++ b/bfd/elf32-m68k.c @@ -341,7 +341,7 @@ static reloc_howto_type howto_table[] = FALSE), /* pcrel_offset */ }; -static void +static bfd_boolean rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int indx = ELF32_R_TYPE (dst->r_info); @@ -351,9 +351,11 @@ rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, indx); - indx = R_68K_NONE; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &howto_table[indx]; + return TRUE; } #define elf_info_to_howto rtype_to_howto diff --git a/bfd/elf32-mcore.c b/bfd/elf32-mcore.c index 2e4d5c2..a88acae 100644 --- a/bfd/elf32-mcore.c +++ b/bfd/elf32-mcore.c @@ -336,7 +336,7 @@ mcore_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for a RCE ELF reloc. */ -static void +static bfd_boolean mcore_elf_info_to_howto (bfd * abfd, arelent * cache_ptr, Elf_Internal_Rela * dst) @@ -354,10 +354,11 @@ mcore_elf_info_to_howto (bfd * abfd, _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); - r_type = R_MCORE_NONE; + return FALSE; } cache_ptr->howto = mcore_elf_howto_table [r_type]; + return TRUE; } /* The RELOCATE_SECTION function is called by the ELF backend linker diff --git a/bfd/elf32-mep.c b/bfd/elf32-mep.c index e03fe50..5224d9a 100644 --- a/bfd/elf32-mep.c +++ b/bfd/elf32-mep.c @@ -375,10 +375,10 @@ mep_final_link_relocate /* Set the howto pointer for a MEP ELF reloc. */ -static void -mep_info_to_howto_rela (bfd *abfd, - arelent *cache_ptr, - Elf_Internal_Rela *dst) +static bfd_boolean +mep_info_to_howto_rela (bfd * abfd, + arelent * cache_ptr, + Elf_Internal_Rela * dst) { unsigned int r_type; @@ -388,9 +388,11 @@ mep_info_to_howto_rela (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = & mep_elf_howto_table [r_type]; + return TRUE; } /* Relocate a MEP ELF section. diff --git a/bfd/elf32-metag.c b/bfd/elf32-metag.c index c4b2c48..efe95bd 100644 --- a/bfd/elf32-metag.c +++ b/bfd/elf32-metag.c @@ -864,7 +864,7 @@ tpoff (struct bfd_link_info *info, bfd_vma address) elf_hash_table (info)->tls_sec->alignment_power)); } -static void +static bfd_boolean metag_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -877,9 +877,11 @@ metag_info_to_howto_rela (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = & elf_metag_howto_table [r_type]; + return TRUE; } static reloc_howto_type * diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c index 29fffb4..3acf93a 100644 --- a/bfd/elf32-microblaze.c +++ b/bfd/elf32-microblaze.c @@ -638,7 +638,7 @@ microblaze_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for a RCE ELF reloc. */ -static void +static bfd_boolean microblaze_elf_info_to_howto (bfd * abfd, arelent * cache_ptr, Elf_Internal_Rela * dst) @@ -656,10 +656,11 @@ microblaze_elf_info_to_howto (bfd * abfd, _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); - r_type = R_MICROBLAZE_NONE; + return FALSE; } cache_ptr->howto = microblaze_elf_howto_table [r_type]; + return TRUE; } /* Microblaze ELF local labels start with 'L.' or '$L', not '.L'. */ diff --git a/bfd/elf32-mips.c b/bfd/elf32-mips.c index be462a1..d6005ff 100644 --- a/bfd/elf32-mips.c +++ b/bfd/elf32-mips.c @@ -57,9 +57,9 @@ static bfd_reloc_status_type mips32_64bit_reloc (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup (bfd *, bfd_reloc_code_real_type); -static void mips_info_to_howto_rel +static bfd_boolean mips_info_to_howto_rel (bfd *, arelent *, Elf_Internal_Rela *); -static void mips_info_to_howto_rela +static bfd_boolean mips_info_to_howto_rela (bfd *, arelent *, Elf_Internal_Rela *); static bfd_boolean mips_elf_sym_is_global (bfd *, asymbol *); @@ -2224,7 +2224,7 @@ mips_elf32_rtype_to_howto (bfd *abfd, _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); - r_type = R_MIPS_NONE; + return NULL; } return &elf_mips_howto_table_rel[r_type]; } @@ -2232,7 +2232,7 @@ mips_elf32_rtype_to_howto (bfd *abfd, /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */ -static void +static bfd_boolean mips_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { const struct elf_backend_data *bed; @@ -2241,6 +2241,13 @@ mips_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) r_type = ELF32_R_TYPE (dst->r_info); bed = get_elf_backend_data (abfd); cache_ptr->howto = bed->elf_backend_mips_rtype_to_howto (abfd, r_type, FALSE); + if (cache_ptr->howto == NULL) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } /* The addend for a GPREL16 or LITERAL relocation comes from the GP value for the object file. We get the addend now, rather than @@ -2249,14 +2256,16 @@ mips_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0 && (gprel16_reloc_p (r_type) || literal_reloc_p (r_type))) cache_ptr->addend = elf_gp (abfd); + + return TRUE; } /* Given a MIPS Elf_Internal_Rela, fill in an arelent structure. */ -static void +static bfd_boolean mips_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { - mips_info_to_howto_rel (abfd, cache_ptr, dst); + return mips_info_to_howto_rel (abfd, cache_ptr, dst); /* If we ever need to do any extra processing with dst->r_addend (the field omitted in an Elf_Internal_Rel) we can do it here. */ diff --git a/bfd/elf32-moxie.c b/bfd/elf32-moxie.c index 7a617a8..d8b549d 100644 --- a/bfd/elf32-moxie.c +++ b/bfd/elf32-moxie.c @@ -123,7 +123,7 @@ moxie_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) /* Set the howto pointer for an MOXIE ELF reloc. */ -static void +static bfd_boolean moxie_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -136,9 +136,11 @@ moxie_info_to_howto_rela (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = & moxie_elf_howto_table [r_type]; + return TRUE; } /* Perform a single relocation. By default we use the standard BFD diff --git a/bfd/elf32-msp430.c b/bfd/elf32-msp430.c index 9f2a3d0..2d351d3 100644 --- a/bfd/elf32-msp430.c +++ b/bfd/elf32-msp430.c @@ -631,7 +631,7 @@ bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an MSP430 ELF reloc. */ -static void +static bfd_boolean msp430_info_to_howto_rela (bfd * abfd, arelent * cache_ptr, Elf_Internal_Rela * dst) @@ -647,20 +647,23 @@ msp430_info_to_howto_rela (bfd * abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = elf_msp430x_howto_table + r_type; - return; } - - if (r_type >= (unsigned int) R_MSP430_max) + else if (r_type >= (unsigned int) R_MSP430_max) { /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } - cache_ptr->howto = &elf_msp430_howto_table[r_type]; + else + cache_ptr->howto = &elf_msp430_howto_table[r_type]; + + return TRUE; } /* Look through the relocs for a section during the first phase. diff --git a/bfd/elf32-mt.c b/bfd/elf32-mt.c index efaaf68..94c2fac 100644 --- a/bfd/elf32-mt.c +++ b/bfd/elf32-mt.c @@ -28,7 +28,7 @@ static reloc_howto_type * mt_reloc_type_lookup (bfd *, bfd_reloc_code_real_type); -static void mt_info_to_howto_rela +static bfd_boolean mt_info_to_howto_rela (bfd *, arelent *, Elf_Internal_Rela *); static bfd_reloc_status_type mt_elf_relocate_hi16 @@ -227,10 +227,10 @@ mt_elf_relocate_hi16 /* Set the howto pointer for a MT ELF reloc. */ -static void -mt_info_to_howto_rela (bfd *abfd, - arelent *cache_ptr, - Elf_Internal_Rela *dst) +static bfd_boolean +mt_info_to_howto_rela (bfd * abfd, + arelent * cache_ptr, + Elf_Internal_Rela * dst) { unsigned int r_type; @@ -240,9 +240,11 @@ mt_info_to_howto_rela (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = & mt_elf_howto_table [r_type]; + return TRUE; } /* Perform a single relocation. By default we use the standard BFD diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c index 62e8572..e240d31 100644 --- a/bfd/elf32-nds32.c +++ b/bfd/elf32-nds32.c @@ -2884,8 +2884,8 @@ bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an NDS32 ELF reloc. */ -static void -nds32_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, +static bfd_boolean +nds32_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { enum elf_nds32_reloc_type r_type; @@ -2896,19 +2896,31 @@ nds32_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = bfd_elf32_bfd_reloc_type_table_lookup (r_type); + return TRUE; } -static void +static bfd_boolean nds32_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, Elf_Internal_Rela *dst) { - BFD_ASSERT ((ELF32_R_TYPE (dst->r_info) == R_NDS32_NONE) - || ((ELF32_R_TYPE (dst->r_info) > R_NDS32_GNU_VTENTRY) - && (ELF32_R_TYPE (dst->r_info) < R_NDS32_max))); - cache_ptr->howto = bfd_elf32_bfd_reloc_type_table_lookup (ELF32_R_TYPE (dst->r_info)); + unsigned int r_type = ELF32_R_TYPE (dst->r_info); + + if ((r_type == R_NDS32_NONE) + || ((r_type > R_NDS32_GNU_VTENTRY) + && (r_type < R_NDS32_max))) + { + cache_ptr->howto = bfd_elf32_bfd_reloc_type_table_lookup (r_type); + return TRUE; + } + + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; } /* Support for core dump NOTE sections. diff --git a/bfd/elf32-nios2.c b/bfd/elf32-nios2.c index 29e1e5a..e160054 100644 --- a/bfd/elf32-nios2.c +++ b/bfd/elf32-nios2.c @@ -31,6 +31,7 @@ #include "elf/nios2.h" #include "opcode/nios2.h" #include "elf32-nios2.h" +#include "libiberty.h" /* Use RELA relocations. */ #ifndef USE_RELA @@ -1578,10 +1579,8 @@ lookup_howto (unsigned int rtype, bfd *abfd) int i; /* R2 relocations are a superset of R1, so use that for the lookup table. */ - int r1_howto_tbl_size = (int) (sizeof (elf_nios2_r1_howto_table_rel) - / sizeof (elf_nios2_r1_howto_table_rel[0])); - int r2_howto_tbl_size = (int) (sizeof (elf_nios2_r2_howto_table_rel) - / sizeof (elf_nios2_r2_howto_table_rel[0])); + int r1_howto_tbl_size = (int) ARRAY_SIZE (elf_nios2_r1_howto_table_rel); + int r2_howto_tbl_size = (int) ARRAY_SIZE (elf_nios2_r2_howto_table_rel); if (!initialized) { @@ -1597,18 +1596,19 @@ lookup_howto (unsigned int rtype, bfd *abfd) } } - BFD_ASSERT (rtype <= R_NIOS2_ILLEGAL); + if (rtype > R_NIOS2_ILLEGAL) + return NULL; i = elf_code_to_howto_index[rtype]; if (BFD_IS_R2 (abfd)) { if (i >= r2_howto_tbl_size) - return 0; + return NULL; return elf_nios2_r2_howto_table_rel + i; } else { if (i >= r1_howto_tbl_size) - return 0; + return NULL; return elf_nios2_r1_howto_table_rel + i; } } @@ -1620,7 +1620,8 @@ struct elf_reloc_map enum elf_nios2_reloc_type elf_val; }; -static const struct elf_reloc_map nios2_reloc_map[] = { +static const struct elf_reloc_map nios2_reloc_map[] = +{ {BFD_RELOC_NONE, R_NIOS2_NONE}, {BFD_RELOC_NIOS2_S16, R_NIOS2_S16}, {BFD_RELOC_NIOS2_U16, R_NIOS2_U16}, @@ -2954,18 +2955,16 @@ nios2_elf32_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) return TRUE; } - /* Implement bfd_elf32_bfd_reloc_type_lookup: Given a BFD reloc type, return a howto structure. */ + static reloc_howto_type * nios2_elf32_bfd_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code) { int i; - for (i = 0; - i < (int) (sizeof (nios2_reloc_map) / sizeof (struct elf_reloc_map)); - ++i) + for (i = 0; i < (int) ARRAY_SIZE (nios2_reloc_map); ++i) if (nios2_reloc_map[i].bfd_val == code) return lookup_howto (nios2_reloc_map[i].elf_val, abfd); return NULL; @@ -2973,6 +2972,7 @@ nios2_elf32_bfd_reloc_type_lookup (bfd *abfd, /* Implement bfd_elf32_bfd_reloc_name_lookup: Given a reloc name, return a howto structure. */ + static reloc_howto_type * nios2_elf32_bfd_reloc_name_lookup (bfd *abfd, const char *r_name) @@ -2984,32 +2984,40 @@ nios2_elf32_bfd_reloc_name_lookup (bfd *abfd, if (BFD_IS_R2 (abfd)) { howto_tbl = elf_nios2_r2_howto_table_rel; - howto_tbl_size = (int) (sizeof (elf_nios2_r2_howto_table_rel) - / sizeof (elf_nios2_r2_howto_table_rel[0])); + howto_tbl_size = (int) ARRAY_SIZE (elf_nios2_r2_howto_table_rel); } else { howto_tbl = elf_nios2_r1_howto_table_rel; - howto_tbl_size = (int) (sizeof (elf_nios2_r1_howto_table_rel) - / sizeof (elf_nios2_r1_howto_table_rel[0])); + howto_tbl_size = (int) ARRAY_SIZE (elf_nios2_r1_howto_table_rel); } for (i = 0; i < howto_tbl_size; i++) if (howto_tbl[i].name && strcasecmp (howto_tbl[i].name, r_name) == 0) return howto_tbl + i; + return NULL; } /* Implement elf_info_to_howto: Given a ELF32 relocation, fill in a arelent structure. */ -static void + +static bfd_boolean nios2_elf32_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type; r_type = ELF32_R_TYPE (dst->r_info); - cache_ptr->howto = lookup_howto (r_type, abfd); + if ((cache_ptr->howto = lookup_howto (r_type, abfd)) == NULL) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + return TRUE; } /* Return the base VMA address which should be subtracted from real addresses diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c index 3818df9b..91b780f 100644 --- a/bfd/elf32-or1k.c +++ b/bfd/elf32-or1k.c @@ -701,7 +701,7 @@ or1k_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an Or1k ELF reloc. */ -static void +static bfd_boolean or1k_info_to_howto_rela (bfd * abfd, arelent * cache_ptr, Elf_Internal_Rela * dst) @@ -714,9 +714,11 @@ or1k_info_to_howto_rela (bfd * abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = & or1k_elf_howto_table[r_type]; + return TRUE; } diff --git a/bfd/elf32-pj.c b/bfd/elf32-pj.c index 1c75523..470d20a 100644 --- a/bfd/elf32-pj.c +++ b/bfd/elf32-pj.c @@ -310,7 +310,7 @@ pj_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Given an ELF reloc, fill in the howto field of a relent. */ -static void +static bfd_boolean pj_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -325,10 +325,11 @@ pj_elf_info_to_howto (bfd *abfd, _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r); bfd_set_error (bfd_error_bad_value); - r = R_PJ_NONE; + return FALSE; } cache_ptr->howto = &pj_elf_howto_table[r]; + return TRUE; } /* Take this moment to fill in the special picoJava bits in the diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index be95498..66bbf0d 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -2014,7 +2014,7 @@ ppc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for a PowerPC ELF reloc. */ -static void +static bfd_boolean ppc_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -2032,21 +2032,24 @@ ppc_elf_info_to_howto (bfd *abfd, _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); - r_type = R_PPC_NONE; + return FALSE; } + cache_ptr->howto = ppc_elf_howto_table[r_type]; /* Just because the above assert didn't trigger doesn't mean that ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */ - if (!cache_ptr->howto) + if (cache_ptr->howto == NULL) { /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); - cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE]; + return FALSE; } + + return TRUE; } /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */ diff --git a/bfd/elf32-pru.c b/bfd/elf32-pru.c index 71bb0a0..a3c431b 100644 --- a/bfd/elf32-pru.c +++ b/bfd/elf32-pru.c @@ -30,6 +30,7 @@ #include "elf-bfd.h" #include "elf/pru.h" #include "opcode/pru.h" +#include "libiberty.h" #define SWAP_VALS(A,B) \ do { \ @@ -291,38 +292,42 @@ static reloc_howto_type elf_pru_howto_table_rel[] = { static unsigned char elf_code_to_howto_index[R_PRU_ILLEGAL + 1]; /* Return the howto for relocation RTYPE. */ + static reloc_howto_type * lookup_howto (unsigned int rtype) { - static int initialized = 0; + static bfd_boolean initialized = FALSE; int i; int howto_tbl_size = (int) (sizeof (elf_pru_howto_table_rel) / sizeof (elf_pru_howto_table_rel[0])); - if (!initialized) + if (! initialized) { - initialized = 1; + initialized = TRUE; memset (elf_code_to_howto_index, 0xff, sizeof (elf_code_to_howto_index)); for (i = 0; i < howto_tbl_size; i++) elf_code_to_howto_index[elf_pru_howto_table_rel[i].type] = i; } - BFD_ASSERT (rtype <= R_PRU_ILLEGAL); + if (rtype > R_PRU_ILLEGAL) + return NULL; i = elf_code_to_howto_index[rtype]; if (i >= howto_tbl_size) - return 0; + return NULL; return elf_pru_howto_table_rel + i; } /* Map for converting BFD reloc types to PRU reloc types. */ + struct elf_reloc_map { bfd_reloc_code_real_type bfd_val; enum elf_pru_reloc_type elf_val; }; -static const struct elf_reloc_map pru_reloc_map[] = { +static const struct elf_reloc_map pru_reloc_map[] = +{ {BFD_RELOC_NONE, R_PRU_NONE}, {BFD_RELOC_PRU_16_PMEM, R_PRU_16_PMEM}, {BFD_RELOC_PRU_U16_PMEMIMM, R_PRU_U16_PMEMIMM}, @@ -346,6 +351,7 @@ static const struct elf_reloc_map pru_reloc_map[] = { /* Assorted hash table functions. */ /* Create an entry in a PRU ELF linker hash table. */ + static struct bfd_hash_entry * link_hash_newfunc (struct bfd_hash_entry *entry, struct bfd_hash_table *table, const char *string) @@ -368,14 +374,14 @@ link_hash_newfunc (struct bfd_hash_entry *entry, /* Implement bfd_elf32_bfd_reloc_type_lookup: Given a BFD reloc type, return a howto structure. */ + static reloc_howto_type * pru_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code) { - int i; - for (i = 0; - i < (int) (sizeof (pru_reloc_map) / sizeof (struct elf_reloc_map)); - ++i) + unsigned int i; + + for (i = 0; i < ARRAY_SIZE (pru_reloc_map); ++i) if (pru_reloc_map[i].bfd_val == code) return lookup_howto ((unsigned int) pru_reloc_map[i].elf_val); return NULL; @@ -383,15 +389,14 @@ pru_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Implement bfd_elf32_bfd_reloc_name_lookup: Given a reloc name, return a howto structure. */ + static reloc_howto_type * pru_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) { unsigned int i; - for (i = 0; - i < (sizeof (elf_pru_howto_table_rel) - / sizeof (elf_pru_howto_table_rel[0])); - i++) + + for (i = 0; i < ARRAY_SIZE (elf_pru_howto_table_rel); i++) if (elf_pru_howto_table_rel[i].name && strcasecmp (elf_pru_howto_table_rel[i].name, r_name) == 0) return &elf_pru_howto_table_rel[i]; @@ -401,15 +406,24 @@ pru_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Implement elf_info_to_howto: Given a ELF32 relocation, fill in a arelent structure. */ -static void -pru_elf32_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, + +static bfd_boolean +pru_elf32_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type; r_type = ELF32_R_TYPE (dst->r_info); - BFD_ASSERT (r_type < R_PRU_ILLEGAL); + if (r_type >= R_PRU_ILLEGAL) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + cache_ptr->howto = lookup_howto (r_type); + return cache_ptr->howto != NULL; } /* Do the relocations that require special handling. */ diff --git a/bfd/elf32-rl78.c b/bfd/elf32-rl78.c index 7cfe312..e072b1a 100644 --- a/bfd/elf32-rl78.c +++ b/bfd/elf32-rl78.c @@ -278,8 +278,8 @@ rl78_reloc_name_lookup (bfd * abfd ATTRIBUTE_UNUSED, const char * r_name) /* Set the howto pointer for an RL78 ELF reloc. */ -static void -rl78_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED, +static bfd_boolean +rl78_info_to_howto_rela (bfd * abfd, arelent * cache_ptr, Elf_Internal_Rela * dst) { @@ -291,9 +291,11 @@ rl78_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = rl78_elf_howto_table + r_type; + return TRUE; } static bfd_vma diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c index 42f5fc2..1f70b97 100644 --- a/bfd/elf32-rx.c +++ b/bfd/elf32-rx.c @@ -300,10 +300,10 @@ rx_reloc_name_lookup (bfd * abfd ATTRIBUTE_UNUSED, const char * r_name) /* Set the howto pointer for an RX ELF reloc. */ -static void -rx_info_to_howto_rela (bfd *abfd, - arelent *cache_ptr, - Elf_Internal_Rela *dst) +static bfd_boolean +rx_info_to_howto_rela (bfd * abfd, + arelent * cache_ptr, + Elf_Internal_Rela * dst) { unsigned int r_type; @@ -313,9 +313,19 @@ rx_info_to_howto_rela (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = rx_elf_howto_table + r_type; + if (cache_ptr->howto->name == NULL) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + return TRUE; } static bfd_vma diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c index ce9c25f..d077104 100644 --- a/bfd/elf32-s390.c +++ b/bfd/elf32-s390.c @@ -323,12 +323,13 @@ elf_s390_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* We need to use ELF32_R_TYPE so we have our own copy of this function, and elf32-s390.c has its own copy. */ -static void -elf_s390_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, +static bfd_boolean +elf_s390_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type = ELF32_R_TYPE(dst->r_info); + switch (r_type) { case R_390_GNU_VTINHERIT: @@ -345,10 +346,13 @@ elf_s390_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = R_390_NONE; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &elf_howto_table[r_type]; } + + return TRUE; } /* A relocation function which doesn't do anything. */ diff --git a/bfd/elf32-score.c b/bfd/elf32-score.c index 91d92cc..42ef221 100644 --- a/bfd/elf32-score.c +++ b/bfd/elf32-score.c @@ -2375,7 +2375,7 @@ score_elf_final_link_relocate (reloc_howto_type *howto, } /* Score backend functions. */ -static void +static bfd_boolean s3_bfd_score_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc) @@ -2384,9 +2384,10 @@ s3_bfd_score_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, r_type = ELF32_R_TYPE (elf_reloc->r_info); if (r_type >= ARRAY_SIZE (elf32_score_howto_table)) - bfd_reloc->howto = NULL; - else - bfd_reloc->howto = &elf32_score_howto_table[r_type]; + return FALSE; + + bfd_reloc->howto = &elf32_score_howto_table[r_type]; + return TRUE; } /* Relocate an score ELF section. */ @@ -2448,7 +2449,8 @@ s3_bfd_score_elf_relocate_section (bfd *output_bfd, r_symndx = ELF32_R_SYM (rel->r_info); r_type = ELF32_R_TYPE (rel->r_info); - s3_bfd_score_info_to_howto (input_bfd, &bfd_reloc, (Elf_Internal_Rela *) rel); + if (! s3_bfd_score_info_to_howto (input_bfd, &bfd_reloc, (Elf_Internal_Rela *) rel)) + continue; howto = bfd_reloc.howto; h = NULL; @@ -4069,7 +4071,7 @@ s3_elf32_score_new_section_hook (bfd *abfd, asection *sec) /*****************************************************************************/ /* s3_s7: backend hooks. */ -static void +static bfd_boolean _bfd_score_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc) @@ -4450,7 +4452,7 @@ _bfd_score_elf_common_definition (Elf_Internal_Sym *sym) #define ELF_MACHINE_ALT1 EM_SCORE_OLD #define ELF_MAXPAGESIZE 0x8000 -#define elf_info_to_howto 0 +#define elf_info_to_howto NULL #define elf_info_to_howto_rel _bfd_score_info_to_howto #define elf_backend_relocate_section _bfd_score_elf_relocate_section #define elf_backend_check_relocs _bfd_score_elf_check_relocs diff --git a/bfd/elf32-score.h b/bfd/elf32-score.h index dc9fd1e..ed5c9fc 100644 --- a/bfd/elf32-score.h +++ b/bfd/elf32-score.h @@ -30,7 +30,7 @@ s7_bfd_score_elf_hide_symbol (struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean); -extern void +extern bfd_boolean s7_bfd_score_info_to_howto (bfd *, arelent *, Elf_Internal_Rela *); extern bfd_boolean diff --git a/bfd/elf32-score7.c b/bfd/elf32-score7.c index b36c95e..3c022e6 100644 --- a/bfd/elf32-score7.c +++ b/bfd/elf32-score7.c @@ -2214,7 +2214,7 @@ score_elf_final_link_relocate (reloc_howto_type *howto, /* Score backend functions. */ -void +bfd_boolean s7_bfd_score_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc) @@ -2223,9 +2223,10 @@ s7_bfd_score_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, r_type = ELF32_R_TYPE (elf_reloc->r_info); if (r_type >= ARRAY_SIZE (elf32_score_howto_table)) - bfd_reloc->howto = NULL; - else - bfd_reloc->howto = &elf32_score_howto_table[r_type]; + return FALSE; + + bfd_reloc->howto = &elf32_score_howto_table[r_type]; + return TRUE; } /* Relocate an score ELF section. */ @@ -2288,7 +2289,8 @@ s7_bfd_score_elf_relocate_section (bfd *output_bfd, r_symndx = ELF32_R_SYM (rel->r_info); r_type = ELF32_R_TYPE (rel->r_info); - s7_bfd_score_info_to_howto (input_bfd, &bfd_reloc, (Elf_Internal_Rela *) rel); + if (! s7_bfd_score_info_to_howto (input_bfd, &bfd_reloc, (Elf_Internal_Rela *) rel)) + continue; howto = bfd_reloc.howto; h = NULL; diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c index a13d60b..d0f5ac8 100644 --- a/bfd/elf32-sh.c +++ b/bfd/elf32-sh.c @@ -472,7 +472,7 @@ sh_elf_reloc_name_lookup (bfd *abfd, const char *r_name) /* Given an ELF reloc, fill in the howto field of a relent. */ -static void +static bfd_boolean sh_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r; @@ -491,10 +491,11 @@ sh_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r); bfd_set_error (bfd_error_bad_value); - r = R_SH_NONE; + return FALSE; } cache_ptr->howto = get_howto_table (abfd) + r; + return TRUE; } /* This function handles relaxing for SH ELF. See the corresponding diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c index d682de2..c3bfbbd 100644 --- a/bfd/elf32-spu.c +++ b/bfd/elf32-spu.c @@ -145,7 +145,7 @@ spu_elf_bfd_to_reloc_type (bfd_reloc_code_real_type code) } } -static void +static bfd_boolean spu_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -160,9 +160,10 @@ spu_elf_info_to_howto (bfd *abfd, _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); - r_type = R_SPU_NONE; + return FALSE; } cache_ptr->howto = &elf_howto_table[(int) r_type]; + return TRUE; } static reloc_howto_type * diff --git a/bfd/elf32-tic6x.c b/bfd/elf32-tic6x.c index 0199c2c..96965b3 100644 --- a/bfd/elf32-tic6x.c +++ b/bfd/elf32-tic6x.c @@ -1495,7 +1495,7 @@ elf32_tic6x_reloc_name_lookup (bfd *abfd, const char *r_name) return NULL; } -static void +static bfd_boolean elf32_tic6x_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc) { @@ -1503,12 +1503,28 @@ elf32_tic6x_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, r_type = ELF32_R_TYPE (elf_reloc->r_info); if (r_type >= ARRAY_SIZE (elf32_tic6x_howto_table)) - bfd_reloc->howto = NULL; - else - bfd_reloc->howto = &elf32_tic6x_howto_table[r_type]; + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + + bfd_reloc->howto = &elf32_tic6x_howto_table[r_type]; + if (bfd_reloc->howto == NULL || bfd_reloc->howto->name == NULL) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + + return TRUE; } -static void +static bfd_boolean elf32_tic6x_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc) { @@ -1516,9 +1532,25 @@ elf32_tic6x_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, r_type = ELF32_R_TYPE (elf_reloc->r_info); if (r_type >= ARRAY_SIZE (elf32_tic6x_howto_table_rel)) - bfd_reloc->howto = NULL; - else - bfd_reloc->howto = &elf32_tic6x_howto_table_rel[r_type]; + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + + bfd_reloc->howto = &elf32_tic6x_howto_table_rel[r_type]; + if (bfd_reloc->howto == NULL || bfd_reloc->howto->name == NULL) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + + return TRUE; } void @@ -2213,6 +2245,7 @@ elf32_tic6x_relocate_section (bfd *output_bfd, bfd_reloc_status_type r; struct bfd_link_hash_entry *sbh; bfd_boolean is_rel; + bfd_boolean res; r_type = ELF32_R_TYPE (rel->r_info); r_symndx = ELF32_R_SYM (rel->r_info); @@ -2221,11 +2254,11 @@ elf32_tic6x_relocate_section (bfd *output_bfd, relocs, rel); if (is_rel) - elf32_tic6x_info_to_howto_rel (input_bfd, &bfd_reloc, rel); + res = elf32_tic6x_info_to_howto_rel (input_bfd, &bfd_reloc, rel); else - elf32_tic6x_info_to_howto (input_bfd, &bfd_reloc, rel); - howto = bfd_reloc.howto; - if (howto == NULL) + res = elf32_tic6x_info_to_howto (input_bfd, &bfd_reloc, rel); + + if (!res || (howto = bfd_reloc.howto) == NULL) { bfd_set_error (bfd_error_bad_value); return FALSE; @@ -2608,6 +2641,7 @@ elf32_tic6x_relocate_section (bfd *output_bfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), input_bfd, r_type); + bfd_set_error (bfd_error_bad_value); ok = FALSE; continue; } diff --git a/bfd/elf32-tilepro.c b/bfd/elf32-tilepro.c index 24fc64e..55b19f8 100644 --- a/bfd/elf32-tilepro.c +++ b/bfd/elf32-tilepro.c @@ -783,7 +783,7 @@ tilepro_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an TILEPro ELF reloc. */ -static void +static bfd_boolean tilepro_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED, arelent * cache_ptr, Elf_Internal_Rela * dst) @@ -793,11 +793,19 @@ tilepro_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED, if (r_type <= (unsigned int) R_TILEPRO_IMM16_X1_TLS_LE_HA) cache_ptr->howto = &tilepro_elf_howto_table [r_type]; else if (r_type - R_TILEPRO_GNU_VTINHERIT - <= (unsigned int) R_TILEPRO_GNU_VTENTRY) + <= ((unsigned int) R_TILEPRO_GNU_VTENTRY + - (unsigned int) R_TILEPRO_GNU_VTINHERIT)) cache_ptr->howto = &tilepro_elf_howto_table2 [r_type - R_TILEPRO_GNU_VTINHERIT]; else - abort (); + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + return TRUE; } typedef tilepro_bundle_bits (*tilepro_create_func)(int); diff --git a/bfd/elf32-v850.c b/bfd/elf32-v850.c index fa041e9..430153a 100644 --- a/bfd/elf32-v850.c +++ b/bfd/elf32-v850.c @@ -1885,7 +1885,7 @@ v850_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an V850 ELF reloc. */ -static void +static bfd_boolean v850_elf_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -1898,16 +1898,18 @@ v850_elf_info_to_howto_rel (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &v850_elf_howto_table[r_type]; + return TRUE; } /* Set the howto pointer for a V850 ELF reloc (type RELA). */ -static void +static bfd_boolean v850_elf_info_to_howto_rela (bfd *abfd, - arelent *cache_ptr, + arelent * cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type; @@ -1918,9 +1920,11 @@ v850_elf_info_to_howto_rela (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &v850_elf_howto_table[r_type]; + return TRUE; } static bfd_boolean @@ -4247,25 +4251,30 @@ v800_elf_reloc_name_lookup (bfd * abfd, const char * r_name) /* Set the howto pointer in CACHE_PTR for a V800 ELF reloc. */ -static void +static bfd_boolean v800_elf_info_to_howto (bfd * abfd, arelent * cache_ptr, Elf_Internal_Rela * dst) { unsigned int r_type = ELF32_R_TYPE (dst->r_info); - BFD_ASSERT (bfd_get_arch (abfd) == bfd_arch_v850_rh850); - - BFD_ASSERT (r_type < (unsigned int) R_V800_max); - if (r_type == R_V800_NONE) r_type = R_V810_NONE; - BFD_ASSERT (r_type >= (unsigned int) R_V810_NONE); - r_type -= R_V810_NONE; - BFD_ASSERT (r_type < ARRAY_SIZE (v800_elf_howto_table)); + if (bfd_get_arch (abfd) != bfd_arch_v850_rh850 + || r_type >= (unsigned int) R_V800_max + || r_type < (unsigned int) R_V810_NONE + || (r_type - R_V810_NONE) >= ARRAY_SIZE (v800_elf_howto_table)) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } - cache_ptr->howto = v800_elf_howto_table + r_type; + cache_ptr->howto = v800_elf_howto_table + (r_type - R_V810_NONE); + return TRUE; } #undef TARGET_LITTLE_SYM diff --git a/bfd/elf32-vax.c b/bfd/elf32-vax.c index 61310b6..0236180 100644 --- a/bfd/elf32-vax.c +++ b/bfd/elf32-vax.c @@ -27,7 +27,7 @@ #include "elf/vax.h" static reloc_howto_type *reloc_type_lookup (bfd *, bfd_reloc_code_real_type); -static void rtype_to_howto (bfd *, arelent *, Elf_Internal_Rela *); +static bfd_boolean rtype_to_howto (bfd *, arelent *, Elf_Internal_Rela *); static struct bfd_hash_entry *elf_vax_link_hash_newfunc (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); @@ -278,7 +278,7 @@ static reloc_howto_type howto_table[] = { FALSE), /* pcrel_offset */ }; -static void +static bfd_boolean rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type; @@ -290,9 +290,10 @@ rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); - r_type = R_VAX_NONE; + return FALSE; } cache_ptr->howto = &howto_table[r_type]; + return TRUE; } #define elf_info_to_howto rtype_to_howto diff --git a/bfd/elf32-visium.c b/bfd/elf32-visium.c index 9310d42..3f8d16a 100644 --- a/bfd/elf32-visium.c +++ b/bfd/elf32-visium.c @@ -458,7 +458,7 @@ visium_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) /* Set the howto pointer for a VISIUM ELF reloc. */ -static void +static bfd_boolean visium_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { @@ -480,11 +480,13 @@ visium_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &visium_elf_howto_table[r_type]; break; } + return TRUE; } /* Look through the relocs for a section during the first phase. diff --git a/bfd/elf32-wasm32.c b/bfd/elf32-wasm32.c index b9f3cb2..9fc48de 100644 --- a/bfd/elf32-wasm32.c +++ b/bfd/elf32-wasm32.c @@ -105,24 +105,27 @@ elf32_wasm32_rtype_to_howto (bfd *abfd, unsigned r_type) /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - i = R_WASM32_NONE; + bfd_set_error (bfd_error_bad_value); + return NULL; } if (elf32_wasm32_howto_table[i].type != r_type) return NULL; - return &elf32_wasm32_howto_table[i]; + return elf32_wasm32_howto_table + i; } /* Translate the ELF-internal relocation RELA into CACHE_PTR. */ -static void +static bfd_boolean elf32_wasm32_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type = ELF32_R_TYPE (dst->r_info); + cache_ptr->howto = elf32_wasm32_rtype_to_howto (abfd, r_type); + return cache_ptr->howto != NULL; } #define ELF_ARCH bfd_arch_wasm32 diff --git a/bfd/elf32-xc16x.c b/bfd/elf32-xc16x.c index 42a3dca..66fe33d 100644 --- a/bfd/elf32-xc16x.c +++ b/bfd/elf32-xc16x.c @@ -212,9 +212,7 @@ xc16x_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, { unsigned int i; - for (i = 0; - i < sizeof (xc16x_elf_howto_table) / sizeof (xc16x_elf_howto_table[0]); - i++) + for (i = 0; i < ARRAY_SIZE (xc16x_elf_howto_table); i++) if (xc16x_elf_howto_table[i].name != NULL && strcasecmp (xc16x_elf_howto_table[i].name, r_name) == 0) return &xc16x_elf_howto_table[i]; @@ -225,8 +223,8 @@ xc16x_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* For a particular operand this function is called to finalise the type of relocation. */ -static void -elf32_xc16x_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, +static bfd_boolean +elf32_xc16x_info_to_howto (bfd *abfd, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc) { unsigned int r; @@ -237,9 +235,12 @@ elf32_xc16x_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, if (xc16x_elf_howto_table[i].type == r) { bfd_reloc->howto = &xc16x_elf_howto_table[i]; - return; + return TRUE; } - abort (); + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r); + bfd_set_error (bfd_error_bad_value); + return FALSE; } static bfd_reloc_status_type diff --git a/bfd/elf32-xgate.c b/bfd/elf32-xgate.c index 3e2669c..a367526 100644 --- a/bfd/elf32-xgate.c +++ b/bfd/elf32-xgate.c @@ -34,7 +34,7 @@ static reloc_howto_type * bfd_elf32_bfd_reloc_type_lookup (bfd *, bfd_reloc_code_real_type); static reloc_howto_type * bfd_elf32_bfd_reloc_name_lookup (bfd *, const char *); -static void +static bfd_boolean xgate_info_to_howto_rel (bfd *, arelent *, Elf_Internal_Rela *); static bfd_boolean xgate_elf_set_mach_from_flags (bfd *); @@ -395,7 +395,7 @@ bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, for (i = 0; i < ARRAY_SIZE (xgate_reloc_map); i++) if (xgate_reloc_map[i].bfd_reloc_val == code) return &elf_xgate_howto_table[xgate_reloc_map[i].elf_reloc_val]; - + return NULL; } @@ -414,7 +414,7 @@ bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) /* Set the howto pointer for an XGATE ELF reloc. */ -static void +static bfd_boolean xgate_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -427,9 +427,11 @@ xgate_info_to_howto_rel (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &elf_xgate_howto_table[r_type]; + return TRUE; } /* Destroy an XGATE ELF linker hash table. */ @@ -702,12 +704,12 @@ elf32_xgate_post_process_headers (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_in #define TARGET_BIG_SYM xgate_elf32_vec #define TARGET_BIG_NAME "elf32-xgate" -#define elf_info_to_howto 0 +#define elf_info_to_howto NULL #define elf_info_to_howto_rel xgate_info_to_howto_rel #define elf_backend_check_relocs elf32_xgate_check_relocs #define elf_backend_relocate_section elf32_xgate_relocate_section #define elf_backend_object_p xgate_elf_set_mach_from_flags -#define elf_backend_final_write_processing 0 +#define elf_backend_final_write_processing NULL #define elf_backend_can_gc_sections 1 #define elf_backend_special_sections elf32_xgate_special_sections #define elf_backend_post_process_headers elf32_xgate_post_process_headers diff --git a/bfd/elf32-xstormy16.c b/bfd/elf32-xstormy16.c index 6e38219..4cd7e62 100644 --- a/bfd/elf32-xstormy16.c +++ b/bfd/elf32-xstormy16.c @@ -375,8 +375,8 @@ xstormy16_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Set the howto pointer for an XSTORMY16 ELF reloc. */ -static void -xstormy16_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED, +static bfd_boolean +xstormy16_info_to_howto_rela (bfd * abfd, arelent * cache_ptr, Elf_Internal_Rela * dst) { @@ -385,11 +385,19 @@ xstormy16_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED, if (r_type <= (unsigned int) R_XSTORMY16_12) cache_ptr->howto = &xstormy16_elf_howto_table [r_type]; else if (r_type - R_XSTORMY16_GNU_VTINHERIT - <= (unsigned int) R_XSTORMY16_GNU_VTENTRY) + <= ((unsigned int) R_XSTORMY16_GNU_VTENTRY + - (unsigned int) R_XSTORMY16_GNU_VTINHERIT)) cache_ptr->howto = &xstormy16_elf_howto_table2 [r_type - R_XSTORMY16_GNU_VTINHERIT]; else - abort (); + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + return TRUE; } /* We support 16-bit pointers to code above 64k by generating a thunk diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c index 1d7a1d8..02effe7 100644 --- a/bfd/elf32-xtensa.c +++ b/bfd/elf32-xtensa.c @@ -450,6 +450,9 @@ elf_xtensa_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, break; } + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: invalid relocation type %d"), abfd, (int) code); + bfd_set_error (bfd_error_bad_value); TRACE ("Unknown"); return NULL; } @@ -472,7 +475,7 @@ elf_xtensa_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Given an ELF "rela" relocation, find the corresponding howto and record it in the BFD internal arelent representation of the relocation. */ -static void +static bfd_boolean elf_xtensa_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -484,9 +487,11 @@ elf_xtensa_info_to_howto_rela (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &elf_howto_table[r_type]; + return TRUE; } diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c index e302605..d59c596 100644 --- a/bfd/elf64-alpha.c +++ b/bfd/elf64-alpha.c @@ -1100,7 +1100,7 @@ elf64_alpha_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* Given an Alpha ELF reloc type, fill in an arelent structure. */ -static void +static bfd_boolean elf64_alpha_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { @@ -1112,9 +1112,10 @@ elf64_alpha_info_to_howto (bfd *abfd, arelent *cache_ptr, _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); - r_type = R_ALPHA_NONE; + return FALSE; } cache_ptr->howto = &elf64_alpha_howto_table[r_type]; + return TRUE; } /* These two relocations create a two-word entry in the got. */ diff --git a/bfd/elf64-gen.c b/bfd/elf64-gen.c index 2dbc1dd..fef6277 100644 --- a/bfd/elf64-gen.c +++ b/bfd/elf64-gen.c @@ -41,20 +41,22 @@ static reloc_howto_type dummy = 0, /* dst_mask */ FALSE); /* pcrel_offset */ -static void +static bfd_boolean elf_generic_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc ATTRIBUTE_UNUSED) { bfd_reloc->howto = &dummy; + return TRUE; } -static void +static bfd_boolean elf_generic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc ATTRIBUTE_UNUSED) { bfd_reloc->howto = &dummy; + return TRUE; } static void diff --git a/bfd/elf64-ia64-vms.c b/bfd/elf64-ia64-vms.c index 07597ba..bc66b17 100644 --- a/bfd/elf64-ia64-vms.c +++ b/bfd/elf64-ia64-vms.c @@ -240,13 +240,24 @@ static asection *get_got /* Given a ELF reloc, return the matching HOWTO structure. */ -static void +static bfd_boolean elf64_ia64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc) { - bfd_reloc->howto - = ia64_elf_lookup_howto ((unsigned int) ELF64_R_TYPE (elf_reloc->r_info)); + unsigned int r_type = ELF32_R_TYPE (elf_reloc->r_info); + + bfd_reloc->howto = ia64_elf_lookup_howto (r_type); + if (bfd_reloc->howto == NULL) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + + return TRUE; } @@ -3434,6 +3445,11 @@ elf64_ia64_relocate_section (bfd *output_bfd, } howto = ia64_elf_lookup_howto (r_type); + if (howto == NULL) + { + ret_val = FALSE; + continue; + } r_symndx = ELF64_R_SYM (rel->r_info); h = NULL; sym = NULL; diff --git a/bfd/elf64-mips.c b/bfd/elf64-mips.c index 4e798ad..ea2e921 100644 --- a/bfd/elf64-mips.c +++ b/bfd/elf64-mips.c @@ -80,9 +80,7 @@ static void mips_elf64_be_swap_reloca_out (bfd *, const Elf_Internal_Rela *, bfd_byte *); static reloc_howto_type *bfd_elf64_bfd_reloc_type_lookup (bfd *, bfd_reloc_code_real_type); -static void mips_elf64_info_to_howto_rel - (bfd *, arelent *, Elf_Internal_Rela *); -static void mips_elf64_info_to_howto_rela +static bfd_boolean mips_elf64_info_to_howto_rela (bfd *, arelent *, Elf_Internal_Rela *); static long mips_elf64_get_dynamic_reloc_upper_bound (bfd *); @@ -3625,20 +3623,17 @@ mips_elf64_rtype_to_howto (bfd *abfd, unsigned int r_type, bfd_boolean rela_p) /* Prevent relocation handling by bfd for MIPS ELF64. */ -static void -mips_elf64_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, - arelent *cache_ptr ATTRIBUTE_UNUSED, - Elf_Internal_Rela *dst ATTRIBUTE_UNUSED) -{ - BFD_ASSERT (0); -} - -static void -mips_elf64_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, +static bfd_boolean +mips_elf64_info_to_howto_rela (bfd *abfd, arelent *cache_ptr ATTRIBUTE_UNUSED, - Elf_Internal_Rela *dst ATTRIBUTE_UNUSED) + Elf_Internal_Rela *dst) { - BFD_ASSERT (0); + unsigned int r_type = ELF32_R_TYPE (dst->r_info); + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; } /* Since each entry in an SHT_REL or SHT_RELA section can represent up @@ -4378,7 +4373,7 @@ const struct elf_size_info mips_elf64_size_info = #define elf_backend_gc_mark_extra_sections \ _bfd_mips_elf_gc_mark_extra_sections #define elf_info_to_howto mips_elf64_info_to_howto_rela -#define elf_info_to_howto_rel mips_elf64_info_to_howto_rel +#define elf_info_to_howto_rel mips_elf64_info_to_howto_rela #define elf_backend_object_p mips_elf64_object_p #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing #define elf_backend_section_processing _bfd_mips_elf_section_processing diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c index ecef6c9..6f56b31 100644 --- a/bfd/elf64-mmix.c +++ b/bfd/elf64-mmix.c @@ -1250,7 +1250,7 @@ mmix_elf_perform_relocation (asection *isec, reloc_howto_type *howto, /* Set the howto pointer for an MMIX ELF reloc (type RELA). */ -static void +static bfd_boolean mmix_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -1263,9 +1263,11 @@ mmix_info_to_howto_rela (bfd *abfd, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = 0; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &elf_mmix_howto_table[r_type]; + return TRUE; } /* Any MMIX-specific relocation gets here at assembly time or when linking diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index 0c10a7e..a79a6b6 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -270,7 +270,8 @@ set_abiversion (bfd *abfd, int ver) /* Relocation HOWTO's. */ static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max]; -static reloc_howto_type ppc64_elf_howto_raw[] = { +static reloc_howto_type ppc64_elf_howto_raw[] = +{ /* This reloc does nothing. */ HOWTO (R_PPC64_NONE, /* type */ 0, /* rightshift */ @@ -2231,7 +2232,7 @@ ppc_howto_init (void) } static reloc_howto_type * -ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, +ppc64_elf_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code) { enum elf_ppc64_reloc_type r = R_PPC64_NONE; @@ -2243,6 +2244,9 @@ ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, switch (code) { default: + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: invalid relocation type %d"), abfd, (int) code); + bfd_set_error (bfd_error_bad_value); return NULL; case BFD_RELOC_NONE: r = R_PPC64_NONE; @@ -2495,12 +2499,13 @@ ppc64_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, && strcasecmp (ppc64_elf_howto_raw[i].name, r_name) == 0) return &ppc64_elf_howto_raw[i]; + return NULL; } /* Set the howto pointer for a PowerPC ELF reloc. */ -static void +static bfd_boolean ppc64_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { @@ -2516,9 +2521,20 @@ ppc64_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, type); - type = R_PPC64_NONE; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = ppc64_elf_howto_table[type]; + if (cache_ptr->howto == NULL || cache_ptr->howto->name == NULL) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + + return TRUE; } /* Handle the R_PPC64_ADDR16_HA and similar relocs. */ diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c index aeb1ced..5c320a5 100644 --- a/bfd/elf64-s390.c +++ b/bfd/elf64-s390.c @@ -189,7 +189,7 @@ static reloc_howto_type elf64_s390_vtentry_howto = HOWTO (R_390_GNU_VTENTRY, 0,4,0,FALSE,0,complain_overflow_dont, _bfd_elf_rel_vtable_reloc_fn,"R_390_GNU_VTENTRY", FALSE,0,0, FALSE); static reloc_howto_type * -elf_s390_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, +elf_s390_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code) { switch (code) @@ -323,7 +323,11 @@ elf_s390_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, default: break; } - return 0; + + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: invalid relocation type %d"), abfd, (int) code); + bfd_set_error (bfd_error_bad_value); + return NULL; } static reloc_howto_type * @@ -350,12 +354,13 @@ elf_s390_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, /* We need to use ELF64_R_TYPE so we have our own copy of this function, and elf64-s390.c has its own copy. */ -static void +static bfd_boolean elf_s390_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type = ELF64_R_TYPE(dst->r_info); + switch (r_type) { case R_390_GNU_VTINHERIT: @@ -372,10 +377,12 @@ elf_s390_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = R_390_NONE; + bfd_set_error (bfd_error_bad_value); + return FALSE; } cache_ptr->howto = &elf_howto_table[r_type]; } + return TRUE; } /* A relocation function which doesn't do anything. */ diff --git a/bfd/elf64-sh64.c b/bfd/elf64-sh64.c index cb0e0ff..d8dca7f 100644 --- a/bfd/elf64-sh64.c +++ b/bfd/elf64-sh64.c @@ -1400,7 +1400,7 @@ sh_elf64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, See sh_elf_info_to_howto in elf32-sh.c for the original. */ -static void +static bfd_boolean sh_elf64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, Elf_Internal_Rela *dst) { @@ -1408,13 +1408,21 @@ sh_elf64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, r = ELF64_R_TYPE (dst->r_info); - BFD_ASSERT (r <= (unsigned int) R_SH_64_PCREL); + if (r > (unsigned int) R_SH_64_PCREL) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: invalid relocation type %d"), abfd, r); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC); BFD_ASSERT (r < R_SH_DIR8WPN || r > R_SH_LAST_INVALID_RELOC_2); BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_GOTPLT32); BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4); cache_ptr->howto = &sh_elf64_howto_table[r]; + return cache_ptr->howto != NULL; } /* Relocate an SH ELF section. diff --git a/bfd/elf64-sparc.c b/bfd/elf64-sparc.c index 8018f6a..b4c0475 100644 --- a/bfd/elf64-sparc.c +++ b/bfd/elf64-sparc.c @@ -130,7 +130,11 @@ elf64_sparc_slurp_one_reloc_table (bfd *abfd, asection *asect, relent->howto = _bfd_sparc_elf_info_to_howto_ptr (abfd, R_SPARC_13); } else - relent->howto = _bfd_sparc_elf_info_to_howto_ptr (abfd, r_type); + { + relent->howto = _bfd_sparc_elf_info_to_howto_ptr (abfd, r_type); + if (relent->howto == NULL) + goto error_return; + } } canon_reloc_count (asect) += relent - relents; diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index c66d286..02a3d37 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -284,7 +284,8 @@ elf_x86_64_rtype_to_howto (bfd *abfd, unsigned r_type) /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = R_X86_64_NONE; + bfd_set_error (bfd_error_bad_value); + return NULL; } i = r_type; } @@ -336,8 +337,8 @@ elf_x86_64_reloc_name_lookup (bfd *abfd, /* Given an x86_64 ELF reloc type, fill in an arelent structure. */ -static void -elf_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, +static bfd_boolean +elf_x86_64_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned r_type; @@ -347,8 +348,10 @@ elf_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, && r_type != (unsigned int) R_X86_64_GNU_VTENTRY) r_type &= ~R_X86_64_converted_reloc_bit; cache_ptr->howto = elf_x86_64_rtype_to_howto (abfd, r_type); - + if (cache_ptr->howto == NULL) + return FALSE; BFD_ASSERT (r_type == cache_ptr->howto->type || cache_ptr->howto->type == R_X86_64_NONE); + return TRUE; } /* Support for core dump NOTE sections. */ @@ -1311,6 +1314,9 @@ elf_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd, from = elf_x86_64_rtype_to_howto (abfd, from_type); to = elf_x86_64_rtype_to_howto (abfd, to_type); + if (from == NULL || to == NULL) + return FALSE; + if (h) name = h->root.root.string; else diff --git a/bfd/elfcode.h b/bfd/elfcode.h index 14c8187..fb02e25 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -1430,6 +1430,7 @@ elf_slurp_reloc_table_from_section (bfd *abfd, i < reloc_count; i++, relent++, native_relocs += entsize) { + bfd_boolean res; Elf_Internal_Rela rela; if (entsize == sizeof (Elf_External_Rela)) @@ -1456,6 +1457,7 @@ elf_slurp_reloc_table_from_section (bfd *abfd, /* xgettext:c-format */ (_("%pB(%pA): relocation %d has invalid symbol index %ld"), abfd, asect, i, (long) ELF_R_SYM (rela.r_info)); + bfd_set_error (bfd_error_bad_value); relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; } else @@ -1472,14 +1474,16 @@ elf_slurp_reloc_table_from_section (bfd *abfd, if ((entsize == sizeof (Elf_External_Rela) && ebd->elf_info_to_howto != NULL) || ebd->elf_info_to_howto_rel == NULL) - (*ebd->elf_info_to_howto) (abfd, relent, &rela); + res = ebd->elf_info_to_howto (abfd, relent, &rela); else - (*ebd->elf_info_to_howto_rel) (abfd, relent, &rela); + res = ebd->elf_info_to_howto_rel (abfd, relent, &rela); + + if (! res || relent->howto == NULL) + goto error_return; } if (allocated != NULL) free (allocated); - return TRUE; error_return: diff --git a/bfd/elfn32-mips.c b/bfd/elfn32-mips.c index 64246fc..076bec1 100644 --- a/bfd/elfn32-mips.c +++ b/bfd/elfn32-mips.c @@ -66,9 +66,9 @@ static bfd_reloc_status_type mips16_gprel_reloc (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup (bfd *, bfd_reloc_code_real_type); -static void mips_info_to_howto_rel +static bfd_boolean mips_info_to_howto_rel (bfd *, arelent *, Elf_Internal_Rela *); -static void mips_info_to_howto_rela +static bfd_boolean mips_info_to_howto_rela (bfd *, arelent *, Elf_Internal_Rela *); static bfd_boolean mips_elf_sym_is_global (bfd *, asymbol *); @@ -3441,7 +3441,7 @@ mips_elf_n32_rtype_to_howto (bfd *abfd, unsigned int r_type, bfd_boolean rela_p) _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); - r_type = R_MIPS_NONE; + return NULL; } if (rela_p) return &elf_mips_howto_table_rela[r_type]; @@ -3453,7 +3453,7 @@ mips_elf_n32_rtype_to_howto (bfd *abfd, unsigned int r_type, bfd_boolean rela_p) /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */ -static void +static bfd_boolean mips_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type; @@ -3461,6 +3461,9 @@ mips_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) r_type = ELF32_R_TYPE (dst->r_info); cache_ptr->howto = mips_elf_n32_rtype_to_howto (abfd, r_type, FALSE); + if (cache_ptr->howto == NULL) + return FALSE; + /* The addend for a GPREL16 or LITERAL relocation comes from the GP value for the object file. We get the addend now, rather than when we do the relocation, because the symbol manipulations done @@ -3468,11 +3471,13 @@ mips_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0 && (gprel16_reloc_p (r_type) || r_type == (unsigned int) R_MIPS_LITERAL)) cache_ptr->addend = elf_gp (abfd); + + return TRUE; } /* Given a MIPS Elf_Internal_Rela, fill in an arelent structure. */ -static void +static bfd_boolean mips_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { @@ -3481,6 +3486,7 @@ mips_info_to_howto_rela (bfd *abfd, r_type = ELF32_R_TYPE (dst->r_info); cache_ptr->howto = mips_elf_n32_rtype_to_howto (abfd, r_type, TRUE); cache_ptr->addend = dst->r_addend; + return cache_ptr->howto != NULL; } /* Determine whether a symbol is global for the purposes of splitting diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index a6d3cce..59027cc 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -2081,7 +2081,7 @@ elfNN_aarch64_howto_from_type (bfd *abfd, unsigned int r_type) return NULL; } -static void +static bfd_boolean elfNN_aarch64_info_to_howto (bfd *abfd, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc) { @@ -2089,6 +2089,14 @@ elfNN_aarch64_info_to_howto (bfd *abfd, arelent *bfd_reloc, r_type = ELFNN_R_TYPE (elf_reloc->r_info); bfd_reloc->howto = elfNN_aarch64_howto_from_type (abfd, r_type); + + if (bfd_reloc->howto == NULL) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); + return FALSE; + } + return TRUE; } static reloc_howto_type * diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c index 84b1af1..e6551df 100644 --- a/bfd/elfnn-ia64.c +++ b/bfd/elfnn-ia64.c @@ -197,13 +197,24 @@ static asection *get_pltoff /* Given a ELF reloc, return the matching HOWTO structure. */ -static void +static bfd_boolean elfNN_ia64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc, Elf_Internal_Rela *elf_reloc) { - bfd_reloc->howto - = ia64_elf_lookup_howto ((unsigned int) ELFNN_R_TYPE (elf_reloc->r_info)); + unsigned int r_type = ELF32_R_TYPE (elf_reloc->r_info); + + bfd_reloc->howto = ia64_elf_lookup_howto (r_type); + if (bfd_reloc->howto == NULL) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + + return TRUE; } #define PLT_HEADER_SIZE (3 * 16) @@ -3857,6 +3868,12 @@ elfNN_ia64_relocate_section (bfd *output_bfd, } howto = ia64_elf_lookup_howto (r_type); + if (howto == NULL) + { + ret_val = FALSE; + continue; + } + r_symndx = ELFNN_R_SYM (rel->r_info); h = NULL; sym = NULL; diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 6403af9..6b2d80c 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -121,12 +121,13 @@ struct riscv_elf_link_hash_table (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ == RISCV_ELF_DATA ? ((struct riscv_elf_link_hash_table *) ((p)->hash)) : NULL) -static void +static bfd_boolean riscv_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { cache_ptr->howto = riscv_elf_rtype_to_howto (abfd, ELFNN_R_TYPE (dst->r_info)); + return cache_ptr->howto != NULL; } static void @@ -467,11 +468,13 @@ riscv_elf_record_got_reference (bfd *abfd, struct bfd_link_info *info, static bfd_boolean bad_static_reloc (bfd *abfd, unsigned r_type, struct elf_link_hash_entry *h) { + reloc_howto_type * r = riscv_elf_rtype_to_howto (abfd, r_type); + (*_bfd_error_handler) (_("%pB: relocation %s against `%s' can not be used when making a shared " "object; recompile with -fPIC"), - abfd, riscv_elf_rtype_to_howto (abfd, r_type)->name, - h != NULL ? h->root.root.string : "a local symbol"); + abfd, r ? r->name : _("<unknown>"), + h != NULL ? h->root.root.string : "a local symbol"); bfd_set_error (bfd_error_bad_value); return FALSE; } @@ -624,9 +627,11 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, may need to keep relocations for symbols satisfied by a dynamic library if we manage to avoid copy relocs for the symbol. */ + reloc_howto_type * r = riscv_elf_rtype_to_howto (abfd, r_type); + if ((bfd_link_pic (info) && (sec->flags & SEC_ALLOC) != 0 - && (! riscv_elf_rtype_to_howto (abfd, r_type)->pc_relative + && ((r != NULL && ! r->pc_relative) || (h != NULL && (! info->symbolic || h->root.type == bfd_link_hash_defweak @@ -696,7 +701,7 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, } p->count += 1; - p->pc_count += riscv_elf_rtype_to_howto (abfd, r_type)->pc_relative; + p->pc_count += r == NULL ? 0 : r->pc_relative; } break; @@ -1727,7 +1732,8 @@ riscv_elf_relocate_section (bfd *output_bfd, reloc_howto_type *howto = riscv_elf_rtype_to_howto (input_bfd, r_type); const char *msg = NULL; - if (r_type == R_RISCV_GNU_VTINHERIT || r_type == R_RISCV_GNU_VTENTRY) + if (howto == NULL + || r_type == R_RISCV_GNU_VTINHERIT || r_type == R_RISCV_GNU_VTENTRY) continue; /* This is a final link. */ @@ -1889,8 +1895,10 @@ riscv_elf_relocate_section (bfd *output_bfd, input_bfd); r_type = ELFNN_R_TYPE (rel->r_info); howto = riscv_elf_rtype_to_howto (input_bfd, r_type); - if (!riscv_record_pcrel_hi_reloc (&pcrel_relocs, pc, - relocation, absolute)) + if (howto == NULL) + r = bfd_reloc_notsupported; + else if (!riscv_record_pcrel_hi_reloc (&pcrel_relocs, pc, + relocation, absolute)) r = bfd_reloc_overflow; break; @@ -1985,9 +1993,11 @@ riscv_elf_relocate_section (bfd *output_bfd, input_bfd); r_type = ELFNN_R_TYPE (rel->r_info); howto = riscv_elf_rtype_to_howto (input_bfd, r_type); - if (!riscv_record_pcrel_hi_reloc (&pcrel_relocs, pc, - relocation + rel->r_addend, - absolute)) + if (howto == NULL) + r = bfd_reloc_notsupported; + else if (!riscv_record_pcrel_hi_reloc (&pcrel_relocs, pc, + relocation + rel->r_addend, + absolute)) r = bfd_reloc_overflow; break; diff --git a/bfd/elfxx-ia64.c b/bfd/elfxx-ia64.c index 97b67e6..8f53272 100644 --- a/bfd/elfxx-ia64.c +++ b/bfd/elfxx-ia64.c @@ -196,12 +196,12 @@ static unsigned char elf_code_to_howto_index[R_IA64_MAX_RELOC_CODE + 1]; reloc_howto_type * ia64_elf_lookup_howto (unsigned int rtype) { - static int inited = 0; + static bfd_boolean inited = FALSE; int i; if (!inited) { - inited = 1; + inited = TRUE; memset (elf_code_to_howto_index, 0xff, sizeof (elf_code_to_howto_index)); for (i = 0; i < NELEMS (ia64_howto_table); ++i) @@ -209,15 +209,15 @@ ia64_elf_lookup_howto (unsigned int rtype) } if (rtype > R_IA64_MAX_RELOC_CODE) - return 0; + return NULL; i = elf_code_to_howto_index[rtype]; if (i >= NELEMS (ia64_howto_table)) - return 0; + return NULL; return ia64_howto_table + i; } -reloc_howto_type* -ia64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, +reloc_howto_type * +ia64_elf_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type bfd_code) { unsigned int rtype; @@ -320,7 +320,12 @@ ia64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, case BFD_RELOC_IA64_DTPREL64LSB: rtype = R_IA64_DTPREL64LSB; break; case BFD_RELOC_IA64_LTOFF_DTPREL22: rtype = R_IA64_LTOFF_DTPREL22; break; - default: return 0; + default: + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: invalid BFD relocation type %d"), + abfd, (int) bfd_code); + bfd_set_error (bfd_error_bad_value); + return NULL; } return ia64_elf_lookup_howto (rtype); } diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c index c75d053..4108aa6 100644 --- a/bfd/elfxx-sparc.c +++ b/bfd/elfxx-sparc.c @@ -311,7 +311,7 @@ static reloc_howto_type sparc_rev32_howto = HOWTO(R_SPARC_REV32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_REV32", FALSE,0,0xffffffff,TRUE); reloc_howto_type * -_bfd_sparc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, +_bfd_sparc_elf_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code) { /* We explicitly handle each relocation type in the switch @@ -585,8 +585,10 @@ _bfd_sparc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, default: break; } - bfd_set_error (bfd_error_bad_value); - return NULL; + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: invalid BFD relocation type %d"), abfd, (int) code); + bfd_set_error (bfd_error_bad_value); + return NULL; } reloc_howto_type * @@ -595,10 +597,7 @@ _bfd_sparc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, { unsigned int i; - for (i = 0; - i < (sizeof (_bfd_sparc_elf_howto_table) - / sizeof (_bfd_sparc_elf_howto_table[0])); - i++) + for (i = 0; i < ARRAY_SIZE (_bfd_sparc_elf_howto_table); i++) if (_bfd_sparc_elf_howto_table[i].name != NULL && strcasecmp (_bfd_sparc_elf_howto_table[i].name, r_name) == 0) return &_bfd_sparc_elf_howto_table[i]; @@ -614,7 +613,8 @@ _bfd_sparc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, } reloc_howto_type * -_bfd_sparc_elf_info_to_howto_ptr (bfd *abfd, unsigned int r_type) +_bfd_sparc_elf_info_to_howto_ptr (bfd *abfd ATTRIBUTE_UNUSED, + unsigned int r_type) { switch (r_type) { @@ -638,7 +638,8 @@ _bfd_sparc_elf_info_to_howto_ptr (bfd *abfd, unsigned int r_type) { _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); - r_type = R_SPARC_NONE; + bfd_set_error (bfd_error_bad_value); + return NULL; } return &_bfd_sparc_elf_howto_table[r_type]; } @@ -649,13 +650,20 @@ _bfd_sparc_elf_info_to_howto_ptr (bfd *abfd, unsigned int r_type) #define SPARC_ELF_R_TYPE(r_info) \ ((r_info) & 0xff) -void +bfd_boolean _bfd_sparc_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type = SPARC_ELF_R_TYPE (dst->r_info); - cache_ptr->howto = _bfd_sparc_elf_info_to_howto_ptr (abfd, r_type); + if ((cache_ptr->howto = _bfd_sparc_elf_info_to_howto_ptr (abfd, r_type)) == NULL) + { + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + return TRUE; } diff --git a/bfd/elfxx-sparc.h b/bfd/elfxx-sparc.h index f465ca7..524b39e 100644 --- a/bfd/elfxx-sparc.h +++ b/bfd/elfxx-sparc.h @@ -97,7 +97,7 @@ extern reloc_howto_type *_bfd_sparc_elf_reloc_type_lookup (bfd *, bfd_reloc_code_real_type); extern reloc_howto_type *_bfd_sparc_elf_reloc_name_lookup (bfd *, const char *); -extern void _bfd_sparc_elf_info_to_howto +extern bfd_boolean _bfd_sparc_elf_info_to_howto (bfd *, arelent *, Elf_Internal_Rela *); extern reloc_howto_type *_bfd_sparc_elf_info_to_howto_ptr (bfd*, unsigned int); diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index 9593e34..ccab02d 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -339,11 +339,11 @@ #endif #ifndef elf_info_to_howto -#define elf_info_to_howto 0 +#define elf_info_to_howto NULL #endif #ifndef elf_info_to_howto_rel -#define elf_info_to_howto_rel 0 +#define elf_info_to_howto_rel NULL #endif #ifndef elf_backend_arch_data diff --git a/bfd/elfxx-tilegx.c b/bfd/elfxx-tilegx.c index 43d8121..2b7bf58 100644 --- a/bfd/elfxx-tilegx.c +++ b/bfd/elfxx-tilegx.c @@ -892,7 +892,7 @@ tilegx_put_word_32 (bfd *abfd, bfd_vma val, void *ptr) } reloc_howto_type * -tilegx_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, +tilegx_reloc_type_lookup (bfd * abfd, bfd_reloc_code_real_type code) { unsigned int i; @@ -908,6 +908,10 @@ tilegx_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, - entry->table[0].type); } + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: invalid BFD relocation type %d"), + abfd, (int) code); + bfd_set_error (bfd_error_bad_value); return NULL; } @@ -928,7 +932,7 @@ tilegx_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, return NULL; } -void +bfd_boolean tilegx_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, Elf_Internal_Rela *dst) @@ -938,11 +942,19 @@ tilegx_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, if (r_type <= (unsigned int) R_TILEGX_IMM8_Y1_TLS_ADD) cache_ptr->howto = &tilegx_elf_howto_table [r_type]; else if (r_type - R_TILEGX_GNU_VTINHERIT - <= (unsigned int) R_TILEGX_GNU_VTENTRY) + <= ((unsigned int) R_TILEGX_GNU_VTENTRY + - (unsigned int) R_TILEGX_GNU_VTINHERIT)) cache_ptr->howto = &tilegx_elf_howto_table2 [r_type - R_TILEGX_GNU_VTINHERIT]; else - abort (); + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + return TRUE; } typedef tilegx_bundle_bits (*tilegx_create_func)(int); diff --git a/bfd/elfxx-tilegx.h b/bfd/elfxx-tilegx.h index 2233116..a5afc54 100644 --- a/bfd/elfxx-tilegx.h +++ b/bfd/elfxx-tilegx.h @@ -76,7 +76,7 @@ tilegx_elf_gc_mark_hook (asection *, extern bfd_vma tilegx_elf_plt_sym_val (bfd_vma, const asection *, const arelent *); -extern void +extern bfd_boolean tilegx_info_to_howto_rela (bfd *, arelent *, Elf_Internal_Rela *); extern int diff --git a/binutils/ChangeLog b/binutils/ChangeLog index a1a5e7c..b7800e1 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,12 @@ +2018-02-27 Nick Clifton <nickc@redhat.com> + + PR 22875 + * objcopy.c (copy_object): Check the error status after marking + symbols used in relocations. + * testsuite/binutils-all/strip-13.s: New test source file. + * testsuite/binutils-all/strip-13.s: New test driver file. + * testsuite/binutils-all/objcopy.exp: Run the new test. + 2018-02-26 Alan Modra <amodra@gmail.com> * testsuite/binutils-all/mips/mips-reginfo-n32.d, diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 8cdf27a..d0a152c 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -3023,9 +3023,18 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch) ignore input sections which have no corresponding output section. */ if (strip_symbols != STRIP_ALL) - bfd_map_over_sections (ibfd, - mark_symbols_used_in_relocations, - isympp); + { + bfd_set_error (bfd_error_no_error); + bfd_map_over_sections (ibfd, + mark_symbols_used_in_relocations, + isympp); + if (bfd_get_error () != bfd_error_no_error) + { + status = 1; + return FALSE; + } + } + osympp = (asymbol **) xmalloc ((symcount + add_symbols + 1) * sizeof (asymbol *)); symcount = filter_symbols (ibfd, obfd, osympp, isympp, symcount); } diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp index f4a7692..f7b811c 100644 --- a/binutils/testsuite/binutils-all/objcopy.exp +++ b/binutils/testsuite/binutils-all/objcopy.exp @@ -1084,6 +1084,8 @@ if [is_elf_format] { run_dump_test "strip-8" run_dump_test "strip-9" run_dump_test "strip-12" + run_dump_test "strip-13" + # This requires STB_GNU_UNIQUE support with OSABI set to GNU. if { [supports_gnu_unique] } { run_dump_test "strip-10" diff --git a/binutils/testsuite/binutils-all/readelf.exp b/binutils/testsuite/binutils-all/readelf.exp index 6fc5070..45a022a 100644 --- a/binutils/testsuite/binutils-all/readelf.exp +++ b/binutils/testsuite/binutils-all/readelf.exp @@ -324,6 +324,8 @@ if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then { unresolved "readelf -S bintest (failed to assemble)" unresolved "readelf -s bintest (failed to assemble)" unresolved "readelf -r bintest (failed to assemble)" + global readelf_size + set readelf_size "" } else { if ![is_remote host] { diff --git a/binutils/testsuite/binutils-all/strip-13.d b/binutils/testsuite/binutils-all/strip-13.d new file mode 100644 index 0000000..a34e1eb --- /dev/null +++ b/binutils/testsuite/binutils-all/strip-13.d @@ -0,0 +1,9 @@ +#PROG: strip +#strip: -g +#error: .* bad value +#not-target: arm-* d10v-* dlx-* h8300-* hppa*-* ip2k-* rx-* xgate-* +# The D10V, DLX and XGATE targets only support REL relocations but this test uses RELA relocations. +# The ARM target does support both types, but defaults to REL. +# The HPPA targets use reloc 241, which is the value this test uses as its "unknown" reloc. +# The H8300-*, IP2K and RX targets do not complain about unrecognised relocs, unless they are actually used +# (which is what should really happen with the other targets...) diff --git a/binutils/testsuite/binutils-all/strip-13.s b/binutils/testsuite/binutils-all/strip-13.s new file mode 100644 index 0000000..5da2426 --- /dev/null +++ b/binutils/testsuite/binutils-all/strip-13.s @@ -0,0 +1,12 @@ + .text +foo: + .dc.l 0x12345678 + + .section .rela.text + .dc.a 0 + .dc.a 0x000000f1 + .dc.a 0x000000f1 + + .dc.a 0 + .dc.a 0 + .dc.a 0 |