Andrew Burgess 069057bf0f bfd/riscv: tighten matching rules in riscv_scan
The following GDB behaviour was observed:

  (gdb) x/1i 0x0001014a
     0x1014a <main+8>:	jal	0x10132 <foo>
  (gdb) show architecture
  The target architecture is set automatically (currently riscv:rv32)
  (gdb) set architecture riscv:rv32
  The target architecture is assumed to be riscv:rv32
  (gdb) x/1i 0x0001014a
     0x1014a <main+8>:	0x37e5
  (gdb)

Notice that initially we can disassemble the instruction (it's a
compressed jal instruction), but after setting the architecture we can
no longer disassemble the instruction.

This is particularly puzzling as GDB initially thought the
architecture was 'riscv:rv32', but when we force the architecture to
be that, the disassembly stops working.

This issue was introduced with this commit:

  commit c35d018b1a5ec604e49a807402c4205530b25ca8
  Date:   Mon Jan 27 15:19:30 2020 -0800

      RISC-V: Fix gdbserver problem with handling arch strings.

In this commit we try to make riscv_scan handle cases where we see
architecture strings like 'riscv:rv32imc' (for example).  Normally
this wouldn't match as bfd_default_scan requires an exact match, so we
extended riscv_scan to ignore trailing characters.

Unfortunately the default riscv arch is called 'riscv', is 64-bit,
and has its mach type set to 0, which I think is intended to pair with
code is riscv-dis.c:riscv_disassemble_insn that tries to guess if we
are 32 or 64 bit.

What happens then is that 'riscv:rv32' is first tested against 'riscv'
using bfd_default_scan, this doesn't match, we then compare this to
'riscv', but allowing trailing characters to be ignored, this matches,
and our 'riscv:rv32' matches against the default (64-bit)
architecture.

The solution I propose is to prevent the default architecture from
taking part in this "ignore trailing characters" extra match case,
only the more specific 'riscv:rv32' and 'riscv:rv64' get this extra
matching.

bfd/ChangeLog:

	* cpu-riscv.c (riscv_scan): Don't allow shorter matches using the
	default architecture.
2020-06-24 19:15:07 +01:00
..
2020-06-16 15:57:59 +09:30
2020-03-02 23:49:03 +10:30
2020-06-04 12:34:17 -07:00
2020-02-19 13:12:00 +10:30
2020-05-23 16:56:38 +09:30
2020-03-02 19:30:48 +10:30
2020-05-19 12:35:03 +09:30
2019-01-01 21:25:40 +10:30
2020-01-01 18:12:08 +10:30
2020-03-03 00:12:44 +10:30
2020-02-26 10:37:25 +10:30
2020-03-02 19:30:48 +10:30
2020-03-02 11:36:19 +10:30
2020-06-16 15:57:59 +09:30
2020-03-20 03:55:30 -07:00
2020-02-19 17:46:10 +00:00
2020-02-19 13:12:00 +10:30
2020-06-23 05:07:45 -07:00
2020-06-23 05:07:45 -07:00
2020-06-23 05:07:45 -07:00
2020-02-19 13:12:00 +10:30
2020-06-23 05:07:45 -07:00
2020-06-23 05:07:45 -07:00
2020-06-23 05:07:45 -07:00
2020-01-22 17:14:08 +10:30
2020-02-19 13:14:05 +10:30
2020-06-23 05:07:45 -07:00
2020-02-19 13:12:00 +10:30
2020-02-26 10:37:25 +10:30
2020-06-03 17:59:44 +09:30
2020-05-19 12:35:03 +09:30
2020-06-23 05:07:45 -07:00
2020-06-23 05:07:45 -07:00
2020-06-23 05:07:45 -07:00
2020-02-19 13:12:00 +10:30
2020-03-02 23:49:03 +10:30
2020-03-03 00:12:44 +10:30
2020-02-26 10:37:25 +10:30
2020-03-26 20:02:42 +10:30
2020-03-02 23:49:03 +10:30
2020-03-02 23:49:03 +10:30
2020-03-02 19:30:48 +10:30
2020-03-02 19:30:48 +10:30
2020-03-02 19:30:48 +10:30
2020-03-02 19:30:48 +10:30
2020-03-02 19:30:48 +10:30
2020-06-16 15:57:59 +09:30
2020-06-16 15:57:59 +09:30
2020-03-02 23:49:03 +10:30
2020-05-21 23:39:36 +09:30
2020-03-02 23:49:03 +10:30
2020-04-27 17:41:39 +01:00
2020-03-20 03:55:30 -07:00
2020-03-02 19:30:48 +10:30
2020-03-02 23:49:03 +10:30
2020-03-03 00:12:44 +10:30
2020-04-18 10:24:17 +09:30
2020-01-17 12:34:03 -06:00
2020-06-16 15:57:59 +09:30
2020-03-31 15:04:21 +10:30
2020-06-24 00:00:07 +00:00
2020-01-14 11:02:28 +10:30
2020-03-09 10:10:36 +10:30
2020-03-02 19:30:48 +10:30
2020-03-02 19:30:48 +10:30

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

BFD is an object file library.  It permits applications to use the
same routines to process object files regardless of their format.

BFD is used by the GNU debugger, assembler, linker, and the binary
utilities.

The documentation on using BFD is scanty and may be occasionally
incorrect.  Pointers to documentation problems, or an entirely
rewritten manual, would be appreciated.

There is some BFD internals documentation in doc/bfdint.texi which may
help programmers who want to modify BFD.

BFD is normally built as part of another package.  See the build
instructions for that package, probably in a README file in the
appropriate directory.

BFD supports the following configure options:

  --target=TARGET
	The default target for which to build the library.  TARGET is
	a configuration target triplet, such as sparc-sun-solaris.
  --enable-targets=TARGET,TARGET,TARGET...
	Additional targets the library should support.  To include
	support for all known targets, use --enable-targets=all.
  --enable-64-bit-bfd
	Include support for 64 bit targets.  This is automatically
	turned on if you explicitly request a 64 bit target, but not
	for --enable-targets=all.  This requires a compiler with a 64
	bit integer type, such as gcc.
  --enable-shared
	Build BFD as a shared library.
  --with-mmap
	Use mmap when accessing files.  This is faster on some hosts,
	but slower on others.  It may not work on all hosts.

Report bugs with BFD to bug-binutils@gnu.org.

Patches are encouraged.  When sending patches, always send the output
of diff -u or diff -c from the original file to the new file.  Do not
send default diff output.  Do not make the diff from the new file to
the original file.  Remember that any patch must not break other
systems.  Remember that BFD must support cross compilation from any
host to any target, so patches which use ``#ifdef HOST'' are not
acceptable.  Please also read the ``Reporting Bugs'' section of the
gcc manual.

Bug reports without patches will be remembered, but they may never get
fixed until somebody volunteers to fix them.

Copyright (C) 2012-2020 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.