aarch64: Check for register aliases before mnemonics
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 30 Nov 2021 17:50:24 +0000 (17:50 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Tue, 30 Nov 2021 17:50:24 +0000 (17:50 +0000)
commit2dd3146b4ffcb8528a6e093741ba31636afdf8ae
treea2543c17fb985705cd980f6cb61b53f41300ff96
parent90fe61ced1c9aa4afb263326e336330d15603fbf
aarch64: Check for register aliases before mnemonics

Previously we would not accept:

A .req B

if A happened to be the name of an instruction.  Adding new
instructions could therefore invalidate existing register aliases.

I noticed this with a test that used "zero" as a register alias
for "xzr", where "zero" is now also the name of an SME instruction.
I don't have any evidence that "real" code is doing this, but it
seems at least plausible.

This patch switches things so that we check for register aliases
first.  It might slow down parsing slightly, but the difference
is unlikely to be noticeable.

Things like:

b .req + 0

still work, since create_register_alias checks for " .req ",
and with the input scrubber, we'll only keep whitespace after
.req if it's followed by another name.  If there's some valid
expression that I haven't thought about that is scrubbed to
" .req ", users could avoid the ambiguity by wrapping .req
in parentheses.

The new test for invalid aliases already passed.  I just wanted
something to exercise the !dot condition.

I can't find a way of exercising the (existing) p == base condition,
but I'm not brave enough to say that it can never happen.  If it does
happen, get_mnemonic_name would return an empty string.

gas/
* config/tc-aarch64.c (opcode_lookup): Move mnemonic extraction
code to...
(md_assemble): ...here.  Check for register aliases first.
* testsuite/gas/aarch64/register_aliases.d,
testsuite/gas/aarch64/register_aliases.s: Test for a register
alias called "zero".
* testsuite/gas/aarch64/register_aliases_invalid.d,
testsuite/gas/aarch64/register_aliases_invalid.l,
testsuite/gas/aarch64/register_aliases_invalid.s: New test.
gas/config/tc-aarch64.c
gas/testsuite/gas/aarch64/register_aliases.d
gas/testsuite/gas/aarch64/register_aliases.s
gas/testsuite/gas/aarch64/register_aliases_invalid.d [new file with mode: 0644]
gas/testsuite/gas/aarch64/register_aliases_invalid.l [new file with mode: 0644]
gas/testsuite/gas/aarch64/register_aliases_invalid.s [new file with mode: 0644]