Commit Graph

3420 Commits

Author SHA1 Message Date
Alan Modra
f81e7e2db6 ubsan: aarch64: left shift of negative value
* aarch64-dis.c (sign_extend): Return uint64_t.  Rewrite without
	conditional.
	(aarch64_ext_imm): Avoid signed overflow.
2019-12-16 17:35:13 +10:30
Alan Modra
488d02fe77 ubsan: microblaze: left shift cannot be represented in type 'int'
* microblaze-dis.c (read_insn_microblaze): Avoid signed overflow.
2019-12-16 17:35:13 +10:30
Alan Modra
8a92faab92 ubsan: nios2: left shift cannot be represented in type 'int'
* nios2-dis.c (nios2_print_insn_arg): Avoid signed overflow
2019-12-16 17:35:13 +10:30
Alan Modra
e6ced26afd ubsan: xstormy16: left shift of negative value
cpu/
	* xstormy16.cpu (f-rel12a): Avoid signed overflow.
opcodes/
	* xstormy16-ibld.c: Regenerate.
2019-12-16 17:35:13 +10:30
Alan Modra
84e098cdea asan: score: global-buffer-overflow
I'm flying blind here, not having an s+core s3 insn set reference,
but this seems reasonably obvious from what is done by the assembler.
s3_do16_rpop does some mixing of imm and reg values to place in the
rpop reg field, but I'm not going to try to fix the disassembly
there.

	* score-dis.c (print_insn_score16): Move rpush/rpop imm field
	value adjustment so that it doesn't affect reg field too.
2019-12-16 17:34:29 +10:30
Alan Modra
36bd8ea7f0 ubsan: crx: left shift cannot be represented in type 'int'
The ubsan complaint is fixed by the SBM change, with similar possible
complaints fixed by the EXTRACT change.  The rest is just cleanup.

include/
	* opcode/crx.h (inst <match>): Make unsigned int.
opcodes/
	* crx-dis.c (EXTRACT, SBM): Avoid signed overflow.
	(get_number_of_operands, getargtype, getbits, getregname),
	(getcopregname, getprocregname, gettrapstring, getcinvstring),
	(getregliststring, get_word_at_PC, get_words_at_PC, build_mask),
	(powerof2, match_opcode, make_instruction, print_arguments),
	(print_arg): Delete forward declarations, moving static to..
	(getregname, getcopregname, getregliststring): ..these definitions.
	(build_mask): Return unsigned int mask.
	(match_opcode): Use unsigned int vars.
2019-12-16 17:33:53 +10:30
Alan Modra
cedfc77485 ubsan: bfin: left shift of negative value
* bfin-dis.c (fmtconst, fmtconst_val): Avoid signed overflow.
2019-12-16 17:33:53 +10:30
Alan Modra
4bdb25fe69 ubsan: nds32: left shift cannot be represented in type 'int'
Note that using 1u in N32_BIT makes all of N32_BIT, __MASK, __MF, __GF
and __SEXT evaluate as unsigned int (the latter three when when their
v arg is int or smaller).  This would be a problem if assigning the
result to a bfd_vma, long, or other type wider than an int since the
__SEXT result would be zero extended to the wider type.  Fortunately
nds32 target code doesn't use wider types unnecessarily.

include/
	* opcode/nds32.h (N32_BIT): Define using 1u.
	(__SEXT): Use __MASK and N32_BIT.
	(N32_IMMS): Remove duplicate mask.
opcodes/
	* nds32-dis.c (print_insn16, print_insn32): Remove forward decls.
	(struct objdump_disasm_info): Delete.
	(nds32_parse_audio_ext, nds32_parse_opcode): Cast result of
	N32_IMMS to unsigned before shifting left.
2019-12-16 17:33:53 +10:30
Alan Modra
cf950fd4dd ubsan: moxie: left shift of negative value
Commit 8c9b417187 didn't remove a glaring left shift of a number
that had just been sign extended.

	* moxie-dis.c (INST2OFFSET): Don't left shift a signed value.
	(print_insn_moxie): Remove unnecessary cast.
2019-12-16 17:28:52 +10:30
Alan Modra
967354c3b9 csky: tidy csky_chars_to_number
* csky-dis.c (csky_chars_to_number): Remove abort and unnecessary
	mask.
2019-12-12 16:46:45 +10:30
Alan Modra
1d61b03226 Remove more shifts for sign/zero extension
cpu/
	* epiphany.cpu (f-sdisp11): Don't sign extend with shifts.
	* lm32.cpu (f-branch, f-vall): Likewise.
	* m32.cpu (f-lab-8-16): Likewise.
opcodes/
	* arc-dis.c (BITS): Don't truncate high bits with shifts.
	* nios2-dis.c (nios2_print_insn_arg): Don't sign extend with shifts.
	* tic54x-dis.c (print_instruction): Likewise.
	* tilegx-opc.c (parse_insn_tilegx): Likewise.
	* tilepro-opc.c (parse_insn_tilepro): Likewise.
	* visium-dis.c (disassem_class0): Likewise.
	* pdp11-dis.c (sign_extend): Likewise.
	(SIGN_BITS): Delete.
	* epiphany-ibld.c: Regenerate.
	* lm32-ibld.c: Regenerate.
	* m32c-ibld.c: Regenerate.
2019-12-11 21:14:19 +10:30
Alan Modra
5afa80e9a8 Re: ubsan: ns32k: left shift cannot be represented in type
* ns32k-dis.c (sign_extend): Correct last patch.
2019-12-11 13:33:26 +10:30
Alan Modra
5c05618a0a ubsan: vax: left shift cannot be represented in type 'int'
* vax-dis.c (NEXTLONG): Avoid signed overflow.
2019-12-11 11:42:09 +10:30
Alan Modra
2a81ccbbbf ubsan: v850: left shift cannot be represented in type 'long'
* v850-dis.c (get_operand_value): Use unsigned arithmetic.  Don't
	sign extend using shifts.
2019-12-11 11:41:52 +10:30
Alan Modra
b84f6152ee ubsan: tic6x: shift left of int
* tic6x-dis.c (tic6x_extract_32): Avoid signed overflow.
2019-12-11 11:41:27 +10:30
Alan Modra
66152f1668 ubsan: tic4x: segv and signed shifts
* tic4x-dis.c (tic4x_print_register): Formatting.  Don't segfault
	on NULL registertable entry.
	(tic4x_hash_opcode): Use unsigned arithmetic.
2019-12-11 11:41:09 +10:30
Alan Modra
205c426a9b ubsan: s12z: left shift cannot be represented in type 'int'
* s12z-opc.c (z_decode_signed_value): Avoid signed overflow.
2019-12-11 11:40:51 +10:30
Alan Modra
fb4cb4e26d ubsan: ns32k: left shift cannot be represented in type 'int'
* ns32k-dis.c (bit_extract): Use unsigned arithmetic.
	(bit_extract_simple, sign_extend): Likewise.
2019-12-11 11:40:33 +10:30
Alan Modra
96f1f60460 ubsan: nios2: left shift cannot be represented in type 'int'
* nios2-dis.c (nios2_print_insn_arg): Use 1u << 31.
2019-12-11 11:40:17 +10:30
Alan Modra
8c9b417187 ubsan: moxie: left shift of negative value
* moxie-dis.c (INST2OFFSET): Don't sign extend using shifts.
2019-12-11 11:40:00 +10:30
Alan Modra
334175b693 ubsan: m68k: left shift cannot be represented in type 'int'
* m68k-dis.c (COERCE32): Cast value first.
	(NEXTLONG, NEXTULONG): Avoid signed overflow.
2019-12-11 11:39:42 +10:30
Alan Modra
f8a87c78e6 ubsan: h8300: left shift cannot be represented in type 'int'
This is
  *cst = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
data is unsigned char which promotes to int.

	* h8300-dis.c (extract_immediate): Avoid signed overflow.
	(bfd_h8_disassemble): Likewise.
2019-12-11 11:39:25 +10:30
Alan Modra
159653d8c0 ussan: d30v: index out of bounds
* d30v-dis.c (print_insn): Make opind unsigned.  Don't access
	past end of operands array.
2019-12-11 11:39:07 +10:30
Alan Modra
d93bba9e0d ubsan: csky: left shift cannot be represented in type 'int'
In the following buf is an unsigned char array, so elements are
promoted to int before arithmetic operations.

  if (dis_info.info->endian == BFD_ENDIAN_BIG)
    while (n--)
      val |= buf[n] << (n*8);
  else
    for (i = 0; i < n; i++)
      val |= buf[i] << (i*8);

	* csky-dis.c (csky_chars_to_number): Rewrite.  Avoid signed
	overflow when collecting bytes of a number.
2019-12-11 11:38:45 +10:30
Alan Modra
c202f69e51 ubsan: cris: signed integer overflow
This was the following in print_with_operands
case 4:
  number
    = buffer[2] + buffer[3] * 256 + buffer[4] * 65536
    + buffer[5] * 0x1000000;
and buffer[5] * 0x1000000 can indeed overflow.  So to fix this we need
to use unsigned arithmetic where overflow semantics are specified.
But number is a long, and the expression is int which will be sign
extended to long.  If we make the expression unsigned it will be zero
extended.  So make number an int32_t and rearrange a little for some
of the places that need fixing.

	* cris-dis.c (print_with_operands): Avoid signed integer
	overflow when collecting bytes of a 32-bit integer.
2019-12-11 11:38:24 +10:30
Alan Modra
0ef562a4b5 ubsan: cr16: left shift cannot be represented in type 'int'
This was:
  unsigned long mask = SBM (instruction->match_bits);
with
  #define SBM(offs)  ((((1 << (32 - offs)) -1) << (offs)))

Well, there are a couple of problems.  Firstly, the expression uses
int values (1 rather than 1u or 1ul) resulting in the ubsan error, and
secondly, a zero offs will result in a 32-bit shift which is undefined
if ints are only 32 bits.

	* cr16-dis.c (EXTRACT, SBM): Rewrite.
	(cr16_match_opcode): Delete duplicate bcond test.
2019-12-11 11:38:04 +10:30
Alan Modra
2fd2b153a3 ubsan: bfin: shift exponent is too large
This was the following in fmtconst_val, x is unsigned int.
    x = SIGNEXTEND (x, constant_formats[cf].nbits);
Problem is, the SIGNEXTEND macro assumed its arg was a long and sign
extended by shifting left then shifting right, and didn't cast the
arg.  So don't do the silly shift thing.  It's not guaranteed to work
anyway according to the C standard.  ">>" might do a logical shift
even if its args are signed.

	* bfin-dis.c (HOST_LONG_WORD_SIZE, XFIELD): Delete.
	(SIGNBIT): New.
	(MASKBITS, SIGNEXTEND): Rewrite.
	(fmtconst): Don't use ? expression now that SIGNEXTEND uses
	unsigned arithmetic, instead assign result of SIGNEXTEND back
	to x.
	(fmtconst_val): Use 1u in shift expression.
2019-12-11 11:37:44 +10:30
Alan Modra
a11db3e9f3 ubsan: arc: shift exponent 32 is too large for 32-bit type 'int'
When operand->bits is 32, the following results in UB.
value = (insn >> operand->shift) & ((1 << operand->bits) - 1);

	* arc-dis.c (find_format_from_table): Use ull constant when
	shifting by up to 32.
2019-12-11 11:37:25 +10:30
Alan Modra
9d48687b41 aarch64 disassembler infinite loop
Assembling this to an object and trying to disassemble results in
objdump -d looping forever.

 .inst 0x45205120

	PR 25270
	* aarch64-dis.c (aarch64_decode_variant_using_iclass): Return
	false when field is zero for sve_size_tsz_bhs.
2019-12-11 11:36:59 +10:30
Alan Modra
b8e61daa1a ubsan: epiphany: left shift of negative value
Two places in epiphany_cgen_extract_operand, "value" is a long.
        value = ((((value) << (1))) + (pc));

cpu/
	* epiphany.cpu (f-simm8, f-simm24): Use multiply rather than
	shift left to avoid UB on left shift of negative values.
opcodes/
	* epiphany-ibld.c: Regenerate.
2019-12-11 11:34:33 +10:30
Alan Modra
20135676fc PR24960, Memory leak from disassembler
PR 24960
include/
	* dis-asm.h (disassemble_free_target): Declare.
opcodes/
	* disassemble.c (disassemble_free_target): New function.
binutils/
	* objdump.c (disassemble_data): Call disassemble_free_target.
2019-12-10 09:07:29 +10:30
Alan Modra
103ebbc35c Use disassemble_info.private_data in place of insn_sets
No cgen target uses private_data.  This patch removes a
disassemble_info field that is only used by cgen, and instead uses
private_data.  It also removes a macro that is no longer used.

include/
	* dis-asm.h (struct disassemble_info): Delete insn_sets.
	(INIT_DISASSEMBLE_INFO_NO_ARCH): Don't define.
opcodes/
	* cgen-dis.in (print_insn_@arch@): Replace insn_sets with private_data.
	* disassemble.c (disassemble_init_for_target): Likewise.
	* bpf-dis.c: Regenerate.
	* epiphany-dis.c: Regenerate.
	* fr30-dis.c: Regenerate.
	* frv-dis.c: Regenerate.
	* ip2k-dis.c: Regenerate.
	* iq2000-dis.c: Regenerate.
	* lm32-dis.c: Regenerate.
	* m32c-dis.c: Regenerate.
	* m32r-dis.c: Regenerate.
	* mep-dis.c: Regenerate.
	* mt-dis.c: Regenerate.
	* or1k-dis.c: Regenerate.
	* xc16x-dis.c: Regenerate.
	* xstormy16-dis.c: Regenerate.
2019-12-10 09:04:15 +10:30
Alan Modra
6f0e075230 Remove backup ppc struct dis_private.
ppc-dis.c used a global struct whenever malloc failed to provide the
eight bytes of memory necessary for struct dis_private.  Which is
quite ridiculous.  If that malloc failed there is zero chance some
other malloc won't fail too.

	* ppc-dis.c (private): Delete variable.
	(get_powerpc_dialect): Don't segfault on NULL info->private_data.
	(powerpc_init_dialect): Don't use global private.
2019-12-10 09:02:05 +10:30
Alan Modra
e7c22a69ac s12z-opc.c formatting fixes
Wrap overlong lines, whitespace fixes, and for function definitions
start a line with the name of the function.

	* s12z-opc.c: Formatting.
2019-12-10 09:00:04 +10:30
Alan Modra
0a6aef6b66 S12Z disassembler memory leak
* s12z-opc.c (exg_sex_discrim): Don't leak memory on invalid
	registers.
2019-12-08 22:03:53 +10:30
Jan Beulich
2dc4b12fcd Arm64: simplify Crypto arch extension handling
This, at the assembler level, is just a "brace" feature covering both
AES and SHA2. Hence there's no need for it to have a separate feature
flag, freeing up a bit for future re-use. Along these lines there are
also a number of dead definitions/variables in the opcode table file.
2019-12-05 08:44:22 +01:00
Alan Modra
378fd43640 PR25249, Memory leak in microblaze-dis.c
PR 25249
	* microblaze-dis.c (NUM_STRBUFS, STRBUF_SIZE): Define.
	(struct string_buf): New.
	(strbuf): New function.
	(get_field): Use strbuf rather than strdup of local temp.
	(get_field_imm, get_field_imm5, get_field_imm5_mbar): Likewise.
	(get_field_rfsl, get_field_imm15): Likewise.
	(get_field_rd, get_field_r1, get_field_r2): Update macros.
	(get_field_special): Likewise.  Don't strcpy spr.  Formatting.
	(print_insn_microblaze): Formatting.  Init and pass string_buf to
	get_field functions.
2019-12-05 14:58:15 +10:30
Jan Beulich
0ba59a2940 x86-64: accept 64-bit LFS/LGS/LSS forms with suffix or operand size specifier
Since we accept these without suffix / operand size specifier, we should
also do so with one. (The fact that we unilaterally accept these, other
than far branches, rather than limiting them to Intel64 mode, will be
taken care of later on.)

Also take the opportunity and make sure "lfs <reg>, tbyte ptr <mem>"
et al get rejected outside of 64-bit mode. This became broken by
dc2be329b9 ("i386: Only check suffix in instruction mnemonic").
Furthermore cover lgdt et al in the Intel syntax handling as well, which
continued to work after said commit just by coincidence.
2019-12-04 10:45:17 +01:00
Jan Beulich
77ad80922b x86/Intel: extend MOVDIRI testing
Test also memory operands with operand size specifier, which was broken
prior to dc2be329b9 ("i386: Only check suffix in instruction
mnemonic"), due to the template not permitting any suffixes. Note that
this uncovered a disassembler issue, which is being fixed here as well.
2019-12-04 10:41:43 +01:00
Jan Beulich
3036c89919 x86: drop some stray/bogus DefaultSize
Insns permitting only GPR operands (and hence implicit sizing when
there's no suffix) don't ever have their DefaultSize attribute
inspected, so it shouldn't be there in the first place.

Additionally XBEGIN is like JMP, not CALL, and hence shouldn't be
converted to 32-bit operand size in .code16gcc mode. While the same is
true for SYSRET, it permitting more than one suffix makes it FLDENV-
like, and hence rather than dropping the attribute, for now add it to
the exclusion list to avoid it getting an operand size prefix emitted
in .code16gcc mode. (This will be dealt with later, perhaps together
with FLDENV and friends.)
2019-12-04 10:40:02 +01:00
Mihail Ionescu
8b301fbb61 Arm: Change CRC from fpu feature to archititectural extension
This patch changes the CRC extension to use the core feature bits instead
of the coproc/fpu feature bits.
CRC is not an fpu feature and it causes issues with the new fpu reset
patch (f439988037). CRC can be set using
the '.arch_extension' directive, which sets bits in the coproc bitfield. When
a '.fpu' directive is encountered, the CRC feature bit gets removed and
there is no way to set it back using '.fpu'.
With this patch, CRC will be marked in the feature core bits, which prevents
it from getting removed when setting/changing the fpu options.

gas/ChangeLog:

	* config/tc-arm.c (arm_ext_crc): New.
	(crc_ext_armv8): Remove.
	(insns): Rename crc_ext_armv8 to arm_ext_crc.
	(arm_cpus): Replace CRC_EXT_ARMV8 with ARM_EXT2_CRC.
	(armv8a_ext_table, armv8r_ext_table,
	arm_option_extension_value_table): Redefine the crc
	extension in terms of ARM_EXT2_CRC.
	* gas/testsuite/gas/arm/crc-ext.s: New.
	* gas/testsuite/gas/arm/crc-ext.d: New.

include/ChangeLog:

	* opcode/arm.h (ARM_EXT2_CRC): New extension feature
	to replace CRC_EXT_ARMV8.
	(CRC_EXT_ARMV8): Remove and mark bit as unused.
	(ARM_ARCH_V8A_CRC, ARM_ARCH_V8_1A, ARM_ARCH_V8_2A,
	ARM_ARCH_V8_3A, ARM_ARCH_V8_4A, ARM_ARCH_V8_5A,
	ARM_ARCH_V8_6A): Redefine using ARM_EXT2_CRC instead of
	CRC_EXT_ARMV8.

opcodes/ChangeLog:

	* opcodes/arm-dis.c (arm_opcodes, thumb32_opcodes):
	Change the coproc CRC conditions to use the extension
	feature set, second word, base on ARM_EXT2_CRC.
2019-11-22 13:47:26 +00:00
Jan Beulich
6aa385b96f x86: drop redundant SYSCALL/SYSRET templates
The Cpu64 forms are no different in their attributes except for the CPU
flags; there's no need to key these off of anything other than
CpuSYSCALL even for the 64-bit forms. Dropping these improves the
diagnostic on SYSRETQ used in 32-bit code from "unsupported instruction
`sysret'" to "invalid instruction suffix for `sysret'".
2019-11-14 08:48:22 +01:00
Jan Beulich
0cfa3eb352 x86: fold individual Jump* attributes into a single Jump one
..., taking just 3 bits instead of 5. No two of them are used together.
2019-11-14 08:47:44 +01:00
Jan Beulich
6f2f06bea8 x86: make JumpAbsolute an insn attribute
... instead of an operand one: There's only ever one operand here
anyway.
2019-11-14 08:47:03 +01:00
Jan Beulich
601e856422 x86: make AnySize an insn attribute
... instead of an operand one. Which operand it applies to can be
determined from other operand properties, but as it turns out the only
place it is actually used at doesn't even need further qualification.
2019-11-14 08:46:19 +01:00
Jim Wilson
7722d40a9c RISC-V: Support the INSN_CLASS.*F.* classes for .insn directive.
We have to enable the f extension through -march or ELF attribute if we use the
FPR in .insn directive.  The behavior is same as the riscv_opcodes.

	2019-11-12  Nelson Chu  <nelson.chu@sifive.com>
	opcodes/
	* riscv-opc.c (riscv_insn_types): Replace the INSN_CLASS_I with
	INSN_CLASS_F and the INSN_CLASS_C with INSN_CLASS_F_AND_C if we
	use the floating point register (FPR).

	gas/
	* testsuite/gas/riscv/insn.d: Add the f extension to -march option.

Change-Id: I4f59d04c82673ef84c56ecd2659ad8ce164dd626
2019-11-12 16:13:00 -08:00
Mihail Ionescu
ce760a7620 [binutils][arm] Update the decoding of MVE VMOV, VMVN
This patch updates the decoding of the VMOV and VMVN instructions which depend on cmode.
Previously VMOV and VMVN with cmode 1101 were not allowed.
The cmode changes also required updating of the MVE conflict checking.
Now instructions with opcodes 0xef800d50 and 0xef800e70 correctly get decoded as VMOV
and VMVN, respectively.

2019-11-12  Mihail Ionescu  <mihail.ionescu@arm.com>

	* opcodes/arm-dis.c (mve_opcodes): Enable VMOV imm to vec with
	cmode 1101.
	(is_mve_encoding_conflict): Update cmode conflict checks for
	MVE_VMVN_IMM.

2019-11-12  Mihail Ionescu  <mihail.ionescu@arm.com>

	* gas/config/tc-arm.c (do_neon_mvn): Allow mve_ext cmode=0xd.
	* testsuite/gas/arm/mve-vmov-vmvn-vorr-vbic.s: New test.
	* testsuite/gas/arm/mve-vmov-vmvn-vorr-vbic.d: Likewise.
2019-11-12 14:01:04 +00:00
Jan Beulich
51c8edf68b x86: fold EsSeg into IsString
EsSeg (a per-operand bit) is used with IsString (a per-insn attribute)
only. Extend the attribute to 2 bits, thus allowing to encode
- not a string insn,
- string insn with neither operand requiring use of %es:,
- string insn with 1st operand requiring use of %es:,
- string insn with 2nd operand requiring use of %es:,
which covers all possible cases, allowing to drop EsSeg.

The (transient) need to comment out the OTUnused #define did uncover an
oversight in the earlier OTMax -> OTNum conversion, which is being taken
care of here.
2019-11-12 09:09:31 +01:00
Jan Beulich
474da251bf x86: eliminate ImmExt abuse
Drop the remaining instances left in place by commit c3949f432f ("x86:
limit ImmExt abuse), now that we have a way to specify specific GPRs.

Take the opportunity and also introduce proper 16-bit forms of
applicable SVME insns as well as 1-operand forms of CLZERO.
2019-11-12 09:08:32 +01:00
Jan Beulich
75e5731b8f x86: introduce operand type "instance"
Special register "class" instances can't be combined with one another
(neither in templates nor in register entries), and hence it is not a
good use of resources (memory as well as execution time) to represent
them as individual bits of a bit field.

Furthermore the generalization becoming possible will allow
improvements to the handling of insns accepting only individual
registers as their operands.
2019-11-12 09:07:34 +01:00