public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Tsukasa OI <research_trasio@irq.a4lg.com>
To: Tsukasa OI <research_trasio@irq.a4lg.com>
Cc: binutils@sourceware.org
Subject: [PATCH 0/3] RISC-V: Make ISA parser stricter (with code clarity improvement)
Date: Wed, 23 Feb 2022 10:47:21 +0900	[thread overview]
Message-ID: <cover.1645580829.git.research_trasio@irq.a4lg.com> (raw)

[note: my copyright assignment is already complete on 2022-01-19]

Current GNU Toolchain accepts invalid RISC-V ISA string containing
invalid underscores (double underscores or trailing underscore).  This
patchset will reject those.

It's not sure that prohibiting those invalid patterns helps users from
accident but would be better than nothing.

As a part of this patchset, PATCH 1/3 removes unnecessary loop in the
ISA string parser (riscv_parse_subset function).  It is a requirement to
reject invalid trailing underscore after a multi-letter extension but it
also improves clarity of the code, regardless of whether invalid
underscores are rejected.



Removal of Unnecessary Loop (PATCH 1/3):

riscv_parse_prefixed_ext function (formerly,
riscv_parse_sv_or_non_std_ext function) used to parse multi-letter
extension with SINGLE type of prefix ('Z', 'S', likewise...).  At the
time when this function is created, iterating over prefix type was
absolutely necessary.

However, commit e601909a3287bf541c6a7d82214bb387d2c76d82 ("RISC-V:
Support to parse the multi-letter prefix in the architecture string.")
by Nelson Chu changed the situation.  Updated riscv_parse_prefixed_ext
function now parses all prefix types in a single call and no longer
requires a loop (in fact, this function is called only once and "while"
loop in riscv_parse_subset function does not actually "loop").

I added trailing underscore-checking code (in PATCH 2/3) at the end of
riscv_parse_prefixed_ext function.  That means, my PATCH 2/3 assumes
that riscv_parse_prefixed_ext is called only once.

PATCH 1/3 ensures that riscv_parse_prefixed_ext is called only once and
that improves the clarity, even without other patches.



Invalid Double Underscores (Rejected in PATCH 2/3):

multi-multi extensions (e.g. Zicsr and Zifencei) must be separated by
AN underscore.  Quoting ISA Manual (version 20191213),

27.6 "Additional Standard Extension Names":
> Extensions with the “Z” prefix must be separated from other multi-
> letter extensions by AN underscore, e.g., “RV32IMACZicsr_Zifencei”.

27.7 "Supervisor-level Instruction-Set Extensions":
> Supervisor-level extensions must be separated from other multi-letter
> extensions by AN underscore.

27.10 "Non-Standard Extension Names":
> They must be separated from other multi-letter extensions by AN
> underscore.

Although multiple underscores are not explicitly prohibited to separate
single-multi or single-single extension pairs, it's not natural to
assume that multiple underscores are allowed here as "AN underscore" is
required to avoid “P” extension ambiguity.

27.5 "Underscores":
> Because the “P” extension for Packed SIMD can be confused for the
> decimal point in a version number, it must be preceded by AN
> underscore if it follows a number.



Invalid Trailing Underscore (Rejected in PATCH 2/3):

This is not allowed in any way because all underscores are intended to
be used to separate ISA extensions.



Tests (PATCH 3/3):

New tests contain invalid ISA strings.




Tsukasa OI (3):
  RISC-V: Remove a loop in the ISA parser
  RISC-V: Stricter underscore handling for ISA
  RISC-V: Tests for ISA string handling (underscore)

 bfd/elfxx-riscv.c                             | 36 ++++++++++++++-----
 .../riscv/march-fail-underscore-double-01.d   |  3 ++
 .../riscv/march-fail-underscore-double-02.d   |  3 ++
 .../riscv/march-fail-underscore-double-03.d   |  3 ++
 .../riscv/march-fail-underscore-double-04.d   |  3 ++
 .../riscv/march-fail-underscore-double-05.d   |  3 ++
 .../riscv/march-fail-underscore-double-06.d   |  3 ++
 .../riscv/march-fail-underscore-double-07.d   |  3 ++
 .../riscv/march-fail-underscore-double-08.d   |  3 ++
 .../gas/riscv/march-fail-underscore-double.l  |  2 ++
 .../riscv/march-fail-underscore-trailing-01.d |  3 ++
 .../riscv/march-fail-underscore-trailing-02.d |  3 ++
 .../riscv/march-fail-underscore-trailing-03.d |  3 ++
 .../riscv/march-fail-underscore-trailing-04.d |  3 ++
 .../riscv/march-fail-underscore-trailing.l    |  2 ++
 15 files changed, 68 insertions(+), 8 deletions(-)
 create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-01.d
 create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-02.d
 create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-03.d
 create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-04.d
 create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-05.d
 create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-06.d
 create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-07.d
 create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double-08.d
 create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-double.l
 create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-trailing-01.d
 create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-trailing-02.d
 create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-trailing-03.d
 create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-trailing-04.d
 create mode 100644 gas/testsuite/gas/riscv/march-fail-underscore-trailing.l


base-commit: 3a3e333f65483b864bf2624392f8aa4a88c7a498
-- 
2.32.0


             reply	other threads:[~2022-02-23  1:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-23  1:47 Tsukasa OI [this message]
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
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=cover.1645580829.git.research_trasio@irq.a4lg.com \
    --to=research_trasio@irq.a4lg.com \
    --cc=binutils@sourceware.org \
    /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).