public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Kito Cheng <kito.cheng@gmail.com>
To: Nelson Chu <nelson.chu@sifive.com>, Andrew Waterman <andrew@sifive.com>
Cc: Tsukasa OI <research_trasio@irq.a4lg.com>,
	Binutils <binutils@sourceware.org>
Subject: Re: [PATCH 2/3] RISC-V: Stricter underscore handling for ISA
Date: Fri, 25 Feb 2022 17:37:19 +0800	[thread overview]
Message-ID: <CA+yXCZAG5LvuO_VqhbfoPFJLKXRFW6D48R0ggUJ26aAfuXKddg@mail.gmail.com> (raw)
In-Reply-To: <CAJYME4ETqXrvs532vxfBgdTug8Yn0S6Tc8f_ahS+pSUWfH8UYA@mail.gmail.com>

Just for reference:

For RISC-V GCC, you can use any number of underscores as you can, so
-march=rv64i___m____a_____c_ is valid input for GCC.
For RISC-V LLVM, you can use only one underscore and have trailing
underscore, e.g. -march=rv64i_mac_

On Fri, Feb 25, 2022 at 5:23 PM Nelson Chu <nelson.chu@sifive.com> wrote:
>
> On Wed, Feb 23, 2022 at 9:49 AM Tsukasa OI via Binutils
> <binutils@sourceware.org> wrote:
> >
> > Double underscores and trailing underscore in an ISA string are invalid.
>
> The ISA spec does say that "Extensions with the Z prefix must be
> separated from other multi-letter extensions by an underscore".  But I
> am not sure if we need the stricter underscore checking for now.  The
> discussion [1] said that we can set the ISA string in any order, so I
> think the checks will be more and more user friendly.  I know that
> these are two different questions, and I don't have a strong opinion.
> Maybe see if anyone else has any suggestions.
>
> Thanks
> Nelson
>
> [1] https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/14
>
> > bfd/ChangeLog:
> >
> >         * elfxx-riscv.c (riscv_parse_std_ext): Make handling for
> >         underscores in ISA string more strict.
> >         (riscv_parse_prefixed_ext): Likewise.
> > ---
> >  bfd/elfxx-riscv.c | 25 ++++++++++++++++++++++++-
> >  1 file changed, 24 insertions(+), 1 deletion(-)
> >
> > diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
> > index 329dcaed304..ee4b442ba89 100644
> > --- a/bfd/elfxx-riscv.c
> > +++ b/bfd/elfxx-riscv.c
> > @@ -1650,6 +1650,8 @@ riscv_parse_std_ext (riscv_parse_subset_t *rps,
> >                      const char *arch,
> >                      const char *p)
> >  {
> > +  unsigned char underscores = 0;
> > +
> >    /* First letter must start with i, e or g.  */
> >    if (*p != 'e' && *p != 'i' && *p != 'g')
> >      {
> > @@ -1669,8 +1671,15 @@ riscv_parse_std_ext (riscv_parse_subset_t *rps,
> >        if (*p == '_')
> >         {
> >           p++;
> > +         if (++underscores == 2)
> > +           {
> > +             rps->error_handler
> > +               (_("%s: double underscores"), arch);
> > +             return NULL;
> > +           }
> >           continue;
> >         }
> > +      underscores = 0;
> >
> >        bool implicit = false;
> >        int major = RISCV_UNKNOWN_VERSION;
> > @@ -1709,7 +1718,7 @@ riscv_parse_std_ext (riscv_parse_subset_t *rps,
> >        riscv_parse_add_subset (rps, subset, major, minor, implicit);
> >      }
> >
> > -  return p;
> > +  return p - underscores;
> >  }
> >
> >  /* Parsing function for prefixed extensions.
> > @@ -1731,14 +1740,22 @@ riscv_parse_prefixed_ext (riscv_parse_subset_t *rps,
> >    int minor_version;
> >    const char *last_name;
> >    enum riscv_prefix_ext_class class;
> > +  unsigned char underscores = 0;
> >
> >    while (*p)
> >      {
> >        if (*p == '_')
> >         {
> >           p++;
> > +         if (++underscores == 2)
> > +           {
> > +             rps->error_handler
> > +               (_("%s: double underscores"), arch);
> > +             return NULL;
> > +           }
> >           continue;
> >         }
> > +      underscores = 0;
> >
> >        class = riscv_get_prefix_class (p);
> >        if (class == RV_ISA_CLASS_UNKNOWN)
> > @@ -1843,6 +1860,12 @@ riscv_parse_prefixed_ext (riscv_parse_subset_t *rps,
> >         }
> >      }
> >
> > +  if (underscores)
> > +    {
> > +      rps->error_handler
> > +       (_("%s: trailing underscore"), arch);
> > +      return NULL;
> > +    }
> >    return p;
> >  }
> >
> > --
> > 2.32.0
> >

  reply	other threads:[~2022-02-25  9:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-23  1:47 [PATCH 0/3] RISC-V: Make ISA parser stricter (with code clarity improvement) Tsukasa OI
2022-02-23  1:47 ` [PATCH 1/3] RISC-V: Remove a loop in the ISA parser Tsukasa OI
2022-02-25  9:10   ` Nelson Chu
2022-02-23  1:47 ` [PATCH 2/3] RISC-V: Stricter underscore handling for ISA Tsukasa OI
2022-02-25  9:22   ` Nelson Chu
2022-02-25  9:37     ` Kito Cheng [this message]
2022-02-25 11:26       ` Andrew Waterman
2022-02-23  1:47 ` [PATCH 3/3] RISC-V: Tests for ISA string handling (underscore) Tsukasa OI

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+yXCZAG5LvuO_VqhbfoPFJLKXRFW6D48R0ggUJ26aAfuXKddg@mail.gmail.com \
    --to=kito.cheng@gmail.com \
    --cc=andrew@sifive.com \
    --cc=binutils@sourceware.org \
    --cc=nelson.chu@sifive.com \
    --cc=research_trasio@irq.a4lg.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).