[PATCH 2/3] RISC-V: Stricter underscore handling for ISA
Andrew Waterman
andrew@sifive.com
Fri Feb 25 11:26:04 GMT 2022
Although the spec isn't written as a formal grammar, my interpretation
of the text is that excess underscores are acceptable. The basis for
my claim is that "underscores [...] may be used [...] to improve
readability", implying they can sometimes be inserted where they
aren't required.
Sounds like GCC agrees with my thinking.
I don't have an opinion on the trailing underscore.
On Fri, Feb 25, 2022 at 1:37 AM Kito Cheng <kito.cheng@gmail.com> wrote:
>
> 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
> > >
More information about the Binutils
mailing list