public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Waterman <andrew@sifive.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Maciej W. Rozycki" <macro@orcam.me.uk>,
	Jim Wilson <jim.wilson.gcc@gmail.com>,
	nelson@rivosinc.com,  Nick Clifton <nickc@redhat.com>,
	binutils@sourceware.org,  Palmer Dabbelt <palmer@dabbelt.com>
Subject: Re: [PATCH] gas/RISC-V: adjust assembler for opcode table re-ordering
Date: Thu, 12 Jan 2023 00:40:28 -0800	[thread overview]
Message-ID: <CA++6G0Agz-ersoXK+P8Y1W5f9A96sYXAPoz4rKqx++hnnhJsfA@mail.gmail.com> (raw)
In-Reply-To: <f8ff59ed-b19a-3da5-6801-00ca30791527@suse.com>

On Thu, Jan 12, 2023 at 12:26 AM Jan Beulich <jbeulich@suse.com> wrote:
>
> On 12.01.2023 02:28, Maciej W. Rozycki wrote:
> > On Wed, 11 Jan 2023, Jan Beulich wrote:
> >
> >>>  And it does appear to happen, because correct machine code is produced
> >>> regardless of your hack, except for the spurious symbol produced.  So is
> >>> it not the case that simply the state (interal relocations recorded) is
> >>> not correctly reset on an unsuccessful operand match?  Why does it have to
> >>> be special-cased just for the `a' operand type?
> >>
> >> The parsing of an 'a' type operand involves expression(), a side effect of
> >> which is to insert a symbol table entry for symbols not otherwise
> >> recognized (and note how my_getSmallExpression() addresses the same issue
> >> by filtering out GPR names first [1]). Yes, in a way this is an
> >> "insufficient undoing" issue, just that undoing of that symbol table
> >> insertion would be quite hard and/or fragile (from all I can tell). And
> >> this is where the dual meaning of symbol names comes into play: This looks
> >> to be intentional, and hence we can't make use of md_parse_name() to
> >> suppress the symbol table insertion in the first place for symbols which
> >> (in other contexts) identify registers.
> >
> >  Thank you for looking into it.  Indeed it looks to me like a problem with
> > `expression' (or `expr' really) and the way the RISC-V assembly dialect
> > defines register references (unlike the MIPS one which uses a `$' prefix).
> >
> >  At a glance it seems to me that the correct approach would be to define a
> > "dry run" mode for `expr' and use it in the RISC-V backend to validate an
> > operand in the first invocation without causing any side effects, and then
> > only once all the operands have been processed and an opcode table entry
> > accepted `expr' would be called to finalise the expression.
> >
> >  I realise it's something you may not be willing to commit to, as it's
> > likely a larger task than a random tweak to the RISC-V backend, but I
> > think it's the way we ought to do it rather than piling up workarounds.
>
> I might actually try to do something along those lines, but only once it was
> clarified (by the arch maintainers) that the present behavior of identifiers
> meaning different things depending on context is actually intentional.

I haven't been following this discussion until now, but if I
understand the question correctly, then yes, it is intentional.  Were
we to travel back in time, we would have defined a different assembly
syntax that sidestepped this complexity.  But it is now part of an API
that is in widespread use, so we are stuck with it.

> There not being a prefix to indicate registers isn't unprecedented, after
> all - at least x86 (Intel syntax, or more generally "noprefix" mode), ia64,
> and Arm permit the same. The former two take the identifier as a register
> regardless of which insn this is an operand of (creating another problem
> when you really mean a symbol of that name, with varying approaches to
> dealing with). Arm instead makes sure that different mnemonics are used
> (b vs bx for Arm32, b vs br for Arm64) and hence ambiguities cannot arise.
>
> Jan

  reply	other threads:[~2023-01-12  8:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-06 12:34 Jan Beulich
2023-01-07 23:29 ` Aurelien Jarno
2023-01-09 17:07   ` Jan Beulich
2023-01-09 19:07     ` Palmer Dabbelt
2023-01-09 21:59       ` Maciej W. Rozycki
2023-01-10  9:25         ` Jan Beulich
2023-01-10 22:58           ` Maciej W. Rozycki
2023-01-11  9:28             ` Jan Beulich
2023-01-12  1:28               ` Maciej W. Rozycki
2023-01-12  8:26                 ` Jan Beulich
2023-01-12  8:40                   ` Andrew Waterman [this message]
2023-01-10 12:31     ` Nick Clifton
2023-01-10 20:14       ` Palmer Dabbelt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA++6G0Agz-ersoXK+P8Y1W5f9A96sYXAPoz4rKqx++hnnhJsfA@mail.gmail.com \
    --to=andrew@sifive.com \
    --cc=binutils@sourceware.org \
    --cc=jbeulich@suse.com \
    --cc=jim.wilson.gcc@gmail.com \
    --cc=macro@orcam.me.uk \
    --cc=nelson@rivosinc.com \
    --cc=nickc@redhat.com \
    --cc=palmer@dabbelt.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).