diff options
author | Alan Modra <amodra@gmail.com> | 2019-12-18 18:33:14 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2019-12-18 18:38:13 +1030 |
commit | 2365f8d70c50afbfd6be69a4076ea6e78fb5485d (patch) | |
tree | fbb92f4ec54f3a4fb3efdff76ca0a248f6faf121 /bfd/elf32-ppc.c | |
parent | 2480b6fa946bb2d2dc993b1c4a83a8e1258a75e8 (diff) | |
download | gdb-2365f8d70c50afbfd6be69a4076ea6e78fb5485d.zip gdb-2365f8d70c50afbfd6be69a4076ea6e78fb5485d.tar.gz gdb-2365f8d70c50afbfd6be69a4076ea6e78fb5485d.tar.bz2 |
Yet more signed overflow fixes
* elf-bfd.h (ELF_LOCAL_SYMBOL_HASH): Avoid signed overflow.
* elf32-hppa.c (final_link_relocate): Likewise.
* elf32-ppc.c (_bfd_elf_ppc_at_tls_transform): Likewise.
(_bfd_elf_ppc_at_tprel_transform, is_insn_ds_form): Likewise.
(is_insn_dq_form, ppc_elf_relocate_section): Likewise.
* elf64-ppc.c (ok_lo_toc_insn, ppc64_elf_edit_toc): Likewise.
(ppc64_elf_relocate_section): Likewise.
* elfxx-mips.c (mips_elf_perform_relocation): Likewise.
* netbsd.h (N_SET_FLAGS): Likewise.
Diffstat (limited to 'bfd/elf32-ppc.c')
-rw-r--r-- | bfd/elf32-ppc.c | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index 162367a..71c35ad 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -6843,7 +6843,7 @@ _bfd_elf_ppc_at_tls_transform (unsigned int insn, unsigned int reg) { unsigned int rtra; - if ((insn & (0x3f << 26)) != 31 << 26) + if ((insn & (0x3fu << 26)) != 31 << 26) return 0; if (reg == 0 || ((insn >> 11) & 0x1f) == reg) @@ -6861,13 +6861,13 @@ _bfd_elf_ppc_at_tls_transform (unsigned int insn, unsigned int reg) || ((insn & (0x1f << 6)) >= 16 << 6 && (insn & (0x1f << 6)) < 24 << 6))) /* load and store indexed -> dform. */ - insn = (32 | ((insn >> 6) & 0x1f)) << 26; + insn = (32u | ((insn >> 6) & 0x1f)) << 26; else if ((insn & (((0x1a << 5) | 0x1f) << 1)) == 21 << 1) /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ - insn = ((58 | ((insn >> 6) & 4)) << 26) | ((insn >> 6) & 1); + insn = ((58u | ((insn >> 6) & 4)) << 26) | ((insn >> 6) & 1); else if ((insn & (((0x1f << 5) | 0x1f) << 1)) == 341 << 1) /* lwax -> lwa. */ - insn = (58 << 26) | 2; + insn = (58u << 26) | 2; else return 0; insn |= rtra; @@ -6882,36 +6882,36 @@ unsigned int _bfd_elf_ppc_at_tprel_transform (unsigned int insn, unsigned int reg) { if ((insn & (0x1f << 16)) == reg << 16 - && ((insn & (0x3f << 26)) == 14u << 26 /* addi */ - || (insn & (0x3f << 26)) == 15u << 26 /* addis */ - || (insn & (0x3f << 26)) == 32u << 26 /* lwz */ - || (insn & (0x3f << 26)) == 34u << 26 /* lbz */ - || (insn & (0x3f << 26)) == 36u << 26 /* stw */ - || (insn & (0x3f << 26)) == 38u << 26 /* stb */ - || (insn & (0x3f << 26)) == 40u << 26 /* lhz */ - || (insn & (0x3f << 26)) == 42u << 26 /* lha */ - || (insn & (0x3f << 26)) == 44u << 26 /* sth */ - || (insn & (0x3f << 26)) == 46u << 26 /* lmw */ - || (insn & (0x3f << 26)) == 47u << 26 /* stmw */ - || (insn & (0x3f << 26)) == 48u << 26 /* lfs */ - || (insn & (0x3f << 26)) == 50u << 26 /* lfd */ - || (insn & (0x3f << 26)) == 52u << 26 /* stfs */ - || (insn & (0x3f << 26)) == 54u << 26 /* stfd */ - || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */ + && ((insn & (0x3fu << 26)) == 14u << 26 /* addi */ + || (insn & (0x3fu << 26)) == 15u << 26 /* addis */ + || (insn & (0x3fu << 26)) == 32u << 26 /* lwz */ + || (insn & (0x3fu << 26)) == 34u << 26 /* lbz */ + || (insn & (0x3fu << 26)) == 36u << 26 /* stw */ + || (insn & (0x3fu << 26)) == 38u << 26 /* stb */ + || (insn & (0x3fu << 26)) == 40u << 26 /* lhz */ + || (insn & (0x3fu << 26)) == 42u << 26 /* lha */ + || (insn & (0x3fu << 26)) == 44u << 26 /* sth */ + || (insn & (0x3fu << 26)) == 46u << 26 /* lmw */ + || (insn & (0x3fu << 26)) == 47u << 26 /* stmw */ + || (insn & (0x3fu << 26)) == 48u << 26 /* lfs */ + || (insn & (0x3fu << 26)) == 50u << 26 /* lfd */ + || (insn & (0x3fu << 26)) == 52u << 26 /* stfs */ + || (insn & (0x3fu << 26)) == 54u << 26 /* stfd */ + || ((insn & (0x3fu << 26)) == 58u << 26 /* lwa,ld,lmd */ && (insn & 3) != 1) - || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */ + || ((insn & (0x3fu << 26)) == 62u << 26 /* std, stmd */ && ((insn & 3) == 0 || (insn & 3) == 3)))) { insn &= ~(0x1f << 16); } else if ((insn & (0x1f << 21)) == reg << 21 - && ((insn & (0x3e << 26)) == 24u << 26 /* ori, oris */ - || (insn & (0x3e << 26)) == 26u << 26 /* xori,xoris */ - || (insn & (0x3e << 26)) == 28u << 26 /* andi,andis */)) + && ((insn & (0x3eu << 26)) == 24u << 26 /* ori, oris */ + || (insn & (0x3eu << 26)) == 26u << 26 /* xori,xoris */ + || (insn & (0x3eu << 26)) == 28u << 26 /* andi,andis */)) { insn &= ~(0x1f << 21); insn |= (insn & (0x1f << 16)) << 5; - if ((insn & (0x3e << 26)) == 26 << 26 /* xori,xoris */) + if ((insn & (0x3eu << 26)) == 26u << 26 /* xori,xoris */) insn -= 2 >> 26; /* convert to ori,oris */ } else @@ -6922,17 +6922,17 @@ _bfd_elf_ppc_at_tprel_transform (unsigned int insn, unsigned int reg) static bfd_boolean is_insn_ds_form (unsigned int insn) { - return ((insn & (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */ - || (insn & (0x3f << 26)) == 62u << 26 /* std,stdu,stq */ - || (insn & (0x3f << 26)) == 57u << 26 /* lfdp */ - || (insn & (0x3f << 26)) == 61u << 26 /* stfdp */); + return ((insn & (0x3fu << 26)) == 58u << 26 /* ld,ldu,lwa */ + || (insn & (0x3fu << 26)) == 62u << 26 /* std,stdu,stq */ + || (insn & (0x3fu << 26)) == 57u << 26 /* lfdp */ + || (insn & (0x3fu << 26)) == 61u << 26 /* stfdp */); } static bfd_boolean is_insn_dq_form (unsigned int insn) { - return ((insn & (0x3f << 26)) == 56u << 26 /* lq */ - || ((insn & (0x3f << 26)) == (61u << 26) /* lxv, stxv */ + return ((insn & (0x3fu << 26)) == 56u << 26 /* lq */ + || ((insn & (0x3fu << 26)) == (61u << 26) /* lxv, stxv */ && (insn & 3) == 1)); } @@ -7245,7 +7245,7 @@ ppc_elf_relocate_section (bfd *output_bfd, { /* IE */ insn1 &= (0x1f << 21) | (0x1f << 16); - insn1 |= 32 << 26; /* lwz */ + insn1 |= 32u << 26; /* lwz */ if (offset != (bfd_vma) -1) { rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE); @@ -7414,7 +7414,7 @@ ppc_elf_relocate_section (bfd *output_bfd, insn = bfd_get_32 (input_bfd, contents + rel->r_offset - d_offset); - if ((insn & (0x3f << 26)) == 15u << 26 + if ((insn & (0x3fu << 26)) == 15u << 26 && (insn & (0x1f << 16)) != 0) { if (!bfd_link_pic (info)) @@ -7450,7 +7450,7 @@ ppc_elf_relocate_section (bfd *output_bfd, { insn = bfd_get_32 (input_bfd, contents + rel->r_offset - d_offset); - if ((insn & (0x3f << 26)) == (15u << 26) + if ((insn & (0x3fu << 26)) == (15u << 26) && (insn & (0x1f << 16)) == 0 /* lis */) { bfd_byte *p; @@ -7513,23 +7513,23 @@ ppc_elf_relocate_section (bfd *output_bfd, { insn = bfd_get_32 (input_bfd, contents + rel->r_offset - d_offset); - if ((insn & (0x3f << 26)) == 14u << 26 /* addi */ - || (insn & (0x3f << 26)) == 32u << 26 /* lwz */ - || (insn & (0x3f << 26)) == 34u << 26 /* lbz */ - || (insn & (0x3f << 26)) == 36u << 26 /* stw */ - || (insn & (0x3f << 26)) == 38u << 26 /* stb */ - || (insn & (0x3f << 26)) == 40u << 26 /* lhz */ - || (insn & (0x3f << 26)) == 42u << 26 /* lha */ - || (insn & (0x3f << 26)) == 44u << 26 /* sth */ - || (insn & (0x3f << 26)) == 46u << 26 /* lmw */ - || (insn & (0x3f << 26)) == 47u << 26 /* stmw */ - || (insn & (0x3f << 26)) == 48u << 26 /* lfs */ - || (insn & (0x3f << 26)) == 50u << 26 /* lfd */ - || (insn & (0x3f << 26)) == 52u << 26 /* stfs */ - || (insn & (0x3f << 26)) == 54u << 26 /* stfd */ - || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */ + if ((insn & (0x3fu << 26)) == 14u << 26 /* addi */ + || (insn & (0x3fu << 26)) == 32u << 26 /* lwz */ + || (insn & (0x3fu << 26)) == 34u << 26 /* lbz */ + || (insn & (0x3fu << 26)) == 36u << 26 /* stw */ + || (insn & (0x3fu << 26)) == 38u << 26 /* stb */ + || (insn & (0x3fu << 26)) == 40u << 26 /* lhz */ + || (insn & (0x3fu << 26)) == 42u << 26 /* lha */ + || (insn & (0x3fu << 26)) == 44u << 26 /* sth */ + || (insn & (0x3fu << 26)) == 46u << 26 /* lmw */ + || (insn & (0x3fu << 26)) == 47u << 26 /* stmw */ + || (insn & (0x3fu << 26)) == 48u << 26 /* lfs */ + || (insn & (0x3fu << 26)) == 50u << 26 /* lfd */ + || (insn & (0x3fu << 26)) == 52u << 26 /* stfs */ + || (insn & (0x3fu << 26)) == 54u << 26 /* stfd */ + || ((insn & (0x3fu << 26)) == 58u << 26 /* lwa,ld,lmd */ && (insn & 3) != 1) - || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */ + || ((insn & (0x3fu << 26)) == 62u << 26 /* std, stmd */ && ((insn & 3) == 0 || (insn & 3) == 3))) { /* Arrange to apply the reloc addend, if any. */ @@ -7639,7 +7639,7 @@ ppc_elf_relocate_section (bfd *output_bfd, { bfd_byte *p = contents + (rel->r_offset & ~3); unsigned int insn = bfd_get_32 (input_bfd, p); - if ((insn & ((0x3f << 26) | 0x1f << 16)) + if ((insn & ((0x3fu << 26) | 0x1f << 16)) != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */) /* xgettext:c-format */ info->callbacks->minfo @@ -8993,11 +8993,11 @@ ppc_elf_relocate_section (bfd *output_bfd, unsigned int insn; insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3)); - if ((insn & (0x3f << 26)) == 10u << 26 /* cmpli */) + if ((insn & (0x3fu << 26)) == 10u << 26 /* cmpli */) complain = complain_overflow_bitfield; - else if ((insn & (0x3f << 26)) == 28u << 26 /* andi */ - || (insn & (0x3f << 26)) == 24u << 26 /* ori */ - || (insn & (0x3f << 26)) == 26u << 26 /* xori */) + else if ((insn & (0x3fu << 26)) == 28u << 26 /* andi */ + || (insn & (0x3fu << 26)) == 24u << 26 /* ori */ + || (insn & (0x3fu << 26)) == 26u << 26 /* xori */) complain = complain_overflow_unsigned; } if (howto->complain_on_overflow != complain) @@ -9221,10 +9221,10 @@ ppc_elf_relocate_section (bfd *output_bfd, . new_page: new_page: . */ insn = bfd_get_32 (input_bfd, contents + offset); - if ((insn & (0x3f << 26)) == (18u << 26) /* b,bl,ba,bla */ - || ((insn & (0x3f << 26)) == (16u << 26) /* bc,bcl,bca,bcla*/ + if ((insn & (0x3fu << 26)) == (18u << 26) /* b,bl,ba,bla */ + || ((insn & (0x3fu << 26)) == (16u << 26) /* bc,bcl,bca,bcla*/ && (insn & (0x14 << 21)) == (0x14 << 21)) /* with BO=0x14 */ - || ((insn & (0x3f << 26)) == (19u << 26) + || ((insn & (0x3fu << 26)) == (19u << 26) && (insn & (0x3ff << 1)) == (16u << 1) /* bclr,bclrl */ && (insn & (0x14 << 21)) == (0x14 << 21)))/* with BO=0x14 */ continue; @@ -9308,7 +9308,7 @@ ppc_elf_relocate_section (bfd *output_bfd, else rel = NULL; - if ((insn & (0x3f << 26)) == (16u << 26) /* bc */ + if ((insn & (0x3fu << 26)) == (16u << 26) /* bc */ && (insn & 2) == 0 /* relative */) { bfd_vma delta = ((insn & 0xfffc) ^ 0x8000) - 0x8000; |