diff options
author | Alan Modra <amodra@gmail.com> | 2019-12-20 12:14:19 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2019-12-20 13:36:06 +1030 |
commit | 15d2859fddcb769e59b906f9443c85afdd5d7380 (patch) | |
tree | 3d1aa7d06813d4fd6ada5c0fc6152c3e1176e420 | |
parent | 000fe1a756e707624d387eeacbaa959a01f0d040 (diff) | |
download | gdb-15d2859fddcb769e59b906f9443c85afdd5d7380.zip gdb-15d2859fddcb769e59b906f9443c85afdd5d7380.tar.gz gdb-15d2859fddcb769e59b906f9443c85afdd5d7380.tar.bz2 |
ubsan: hppa: left shift of negative value
bfd/
* libhppa.h (hppa_field_adjust, bfd_hppa_insn2fmt): Delete forward
declaration. Move ATTRIBUTE_UNUSED to definition.
(sign_extend, low_sign_extend, sign_unext, low_sign_unext),
(re_assemble_3, re_assemble_12, re_assemble_14, re_assemble_16),
(re_assemble_17, re_assemble_21, re_assemble_22): Likewise. Make
args and return value unsigned. Use unsigned variables.
(hppa_rebuild_insn): Similarly.
opcodes/
* hppa-dis.c (extract_16, extract_21, print_insn_hppa): Use
unsigned variables.
-rw-r--r-- | bfd/ChangeLog | 10 | ||||
-rw-r--r-- | bfd/libhppa.h | 85 | ||||
-rw-r--r-- | opcodes/ChangeLog | 5 | ||||
-rw-r--r-- | opcodes/hppa-dis.c | 16 |
4 files changed, 56 insertions, 60 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 61d1991..14aebd9 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,15 @@ 2019-12-20 Alan Modra <amodra@gmail.com> + * libhppa.h (hppa_field_adjust, bfd_hppa_insn2fmt): Delete forward + declaration. Move ATTRIBUTE_UNUSED to definition. + (sign_extend, low_sign_extend, sign_unext, low_sign_unext), + (re_assemble_3, re_assemble_12, re_assemble_14, re_assemble_16), + (re_assemble_17, re_assemble_21, re_assemble_22): Likewise. Make + args and return value unsigned. Use unsigned variables. + (hppa_rebuild_insn): Similarly. + +2019-12-20 Alan Modra <amodra@gmail.com> + * format.c (bfd_check_format_matches): Free matching_vector when not returning matching target strings. diff --git a/bfd/libhppa.h b/bfd/libhppa.h index 632f524..339831c 100644 --- a/bfd/libhppa.h +++ b/bfd/libhppa.h @@ -155,39 +155,20 @@ enum hppa_reloc_expr_type_alt /* Some functions to manipulate PA instructions. */ -/* Declare the functions with the unused attribute to avoid warnings. */ -static inline int sign_extend (int, int) ATTRIBUTE_UNUSED; -static inline int low_sign_extend (int, int) ATTRIBUTE_UNUSED; -static inline int sign_unext (int, int) ATTRIBUTE_UNUSED; -static inline int low_sign_unext (int, int) ATTRIBUTE_UNUSED; -static inline int re_assemble_3 (int) ATTRIBUTE_UNUSED; -static inline int re_assemble_12 (int) ATTRIBUTE_UNUSED; -static inline int re_assemble_14 (int) ATTRIBUTE_UNUSED; -static inline int re_assemble_16 (int) ATTRIBUTE_UNUSED; -static inline int re_assemble_17 (int) ATTRIBUTE_UNUSED; -static inline int re_assemble_21 (int) ATTRIBUTE_UNUSED; -static inline int re_assemble_22 (int) ATTRIBUTE_UNUSED; -static inline bfd_signed_vma hppa_field_adjust - (bfd_vma, bfd_signed_vma, enum hppa_reloc_field_selector_type_alt) - ATTRIBUTE_UNUSED; -static inline int bfd_hppa_insn2fmt (bfd *, int) ATTRIBUTE_UNUSED; -static inline int hppa_rebuild_insn (int, int, int) ATTRIBUTE_UNUSED; - - /* The *sign_extend functions are used to assemble various bitfields taken from an instruction and return the resulting immediate value. */ -static inline int -sign_extend (int x, int len) +static inline unsigned ATTRIBUTE_UNUSED +sign_extend (unsigned x, unsigned len) { - int signbit = (1 << (len - 1)); - int mask = (signbit << 1) - 1; + unsigned signbit = (1 << (len - 1)); + unsigned mask = (signbit << 1) - 1; return ((x & mask) ^ signbit) - signbit; } -static inline int -low_sign_extend (int x, int len) +static inline unsigned ATTRIBUTE_UNUSED +low_sign_extend (unsigned x, unsigned len) { return (x >> 1) - ((x & 1) << (len - 1)); } @@ -197,21 +178,21 @@ low_sign_extend (int x, int len) insertion into an opcode. pa-risc uses all sorts of weird bitfields in the instruction to hold the value. */ -static inline int -sign_unext (int x, int len) +static inline unsigned ATTRIBUTE_UNUSED +sign_unext (unsigned x, unsigned len) { - int len_ones; + unsigned len_ones; len_ones = (1 << len) - 1; return x & len_ones; } -static inline int -low_sign_unext (int x, int len) +static inline unsigned ATTRIBUTE_UNUSED +low_sign_unext (unsigned x, unsigned len) { - int temp; - int sign; + unsigned temp; + unsigned sign; sign = (x >> (len-1)) & 1; @@ -220,32 +201,32 @@ low_sign_unext (int x, int len) return (temp << 1) | sign; } -static inline int -re_assemble_3 (int as3) +static inline unsigned ATTRIBUTE_UNUSED +re_assemble_3 (unsigned as3) { return (( (as3 & 4) << (13-2)) | ((as3 & 3) << (13+1))); } -static inline int -re_assemble_12 (int as12) +static inline unsigned ATTRIBUTE_UNUSED +re_assemble_12 (unsigned as12) { return (( (as12 & 0x800) >> 11) | ((as12 & 0x400) >> (10 - 2)) | ((as12 & 0x3ff) << (1 + 2))); } -static inline int -re_assemble_14 (int as14) +static inline unsigned ATTRIBUTE_UNUSED +re_assemble_14 (unsigned as14) { return (( (as14 & 0x1fff) << 1) | ((as14 & 0x2000) >> 13)); } -static inline int -re_assemble_16 (int as16) +static inline unsigned ATTRIBUTE_UNUSED +re_assemble_16 (unsigned as16) { - int s, t; + unsigned s, t; /* Unusual 16-bit encoding, for wide mode only. */ t = (as16 << 1) & 0xffff; @@ -253,8 +234,8 @@ re_assemble_16 (int as16) return (t ^ s ^ (s >> 1)) | (s >> 15); } -static inline int -re_assemble_17 (int as17) +static inline unsigned ATTRIBUTE_UNUSED +re_assemble_17 (unsigned as17) { return (( (as17 & 0x10000) >> 16) | ((as17 & 0x0f800) << (16 - 11)) @@ -262,8 +243,8 @@ re_assemble_17 (int as17) | ((as17 & 0x003ff) << (1 + 2))); } -static inline int -re_assemble_21 (int as21) +static inline unsigned ATTRIBUTE_UNUSED +re_assemble_21 (unsigned as21) { return (( (as21 & 0x100000) >> 20) | ((as21 & 0x0ffe00) >> 8) @@ -272,8 +253,8 @@ re_assemble_21 (int as21) | ((as21 & 0x000003) << 12)); } -static inline int -re_assemble_22 (int as22) +static inline unsigned ATTRIBUTE_UNUSED +re_assemble_22 (unsigned as22) { return (( (as22 & 0x200000) >> 21) | ((as22 & 0x1f0000) << (21 - 16)) @@ -293,7 +274,7 @@ re_assemble_22 (int as22) This function returns sign extended values in all cases. */ -static inline bfd_signed_vma +static inline bfd_signed_vma ATTRIBUTE_UNUSED hppa_field_adjust (bfd_vma sym_val, bfd_signed_vma addend, enum hppa_reloc_field_selector_type_alt r_field) @@ -459,8 +440,8 @@ enum hppa_opcode_type /* Given a machine instruction, return its format. */ -static inline int -bfd_hppa_insn2fmt (bfd *abfd, int insn) +static inline unsigned ATTRIBUTE_UNUSED +bfd_hppa_insn2fmt (bfd *abfd, unsigned insn) { enum hppa_opcode_type op = (enum hppa_opcode_type) get_opcode (insn); @@ -541,8 +522,8 @@ bfd_hppa_insn2fmt (bfd *abfd, int insn) /* Insert VALUE into INSN using R_FORMAT to determine exactly what bits to change. */ -static inline int -hppa_rebuild_insn (int insn, int value, int r_format) +static inline unsigned ATTRIBUTE_UNUSED +hppa_rebuild_insn (unsigned insn, unsigned value, int r_format) { switch (r_format) { diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index 36667ae..e0d2fab 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,5 +1,10 @@ 2019-12-20 Alan Modra <amodra@gmail.com> + * hppa-dis.c (extract_16, extract_21, print_insn_hppa): Use + unsigned variables. + +2019-12-20 Alan Modra <amodra@gmail.com> + * m68hc11-dis.c (read_memory): Delete forward decls. (print_indexed_operand, print_insn): Likewise. (print_indexed_operand): Formatting. Don't rely on short being diff --git a/opcodes/hppa-dis.c b/opcodes/hppa-dis.c index 1d85d78..9844332 100644 --- a/opcodes/hppa-dis.c +++ b/opcodes/hppa-dis.c @@ -289,7 +289,7 @@ extract_14 (unsigned word) static int extract_16 (unsigned word) { - int m15, m0, m1; + unsigned m15, m0, m1; m0 = GET_BIT (word, 16); m1 = GET_BIT (word, 17); @@ -304,7 +304,7 @@ extract_16 (unsigned word) static int extract_21 (unsigned word) { - int val; + unsigned val; word &= MASK_21; word <<= 11; @@ -1098,9 +1098,9 @@ print_insn_hppa (bfd_vma memaddr, disassemble_info *info) case '#': { - int sign = GET_FIELD (insn, 31, 31); - int imm10 = GET_FIELD (insn, 18, 27); - int disp; + unsigned sign = GET_FIELD (insn, 31, 31); + unsigned imm10 = GET_FIELD (insn, 18, 27); + unsigned disp; if (sign) disp = (-1U << 10) | imm10; @@ -1114,9 +1114,9 @@ print_insn_hppa (bfd_vma memaddr, disassemble_info *info) case 'K': case 'd': { - int sign = GET_FIELD (insn, 31, 31); - int imm11 = GET_FIELD (insn, 18, 28); - int disp; + unsigned sign = GET_FIELD (insn, 31, 31); + unsigned imm11 = GET_FIELD (insn, 18, 28); + unsigned disp; if (sign) disp = (-1U << 11) | imm11; |