From: Tsukasa OI <research_trasio@irq.a4lg.com>
To: Tsukasa OI <research_trasio@irq.a4lg.com>
Cc: binutils@sourceware.org
Subject: [PATCH 2/3] RISC-V: Stricter underscore handling for ISA
Date: Wed, 23 Feb 2022 10:47:23 +0900 [thread overview]
Message-ID: <f563c516bede472849f805202b4ee8c04a626d00.1645580829.git.research_trasio@irq.a4lg.com> (raw)
In-Reply-To: <cover.1645580829.git.research_trasio@irq.a4lg.com>
Double underscores and trailing underscore in an ISA string are invalid.
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
next prev parent 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 [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 ` Tsukasa OI [this message]
2022-02-25 9:22 ` [PATCH 2/3] RISC-V: Stricter underscore handling for ISA 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=f563c516bede472849f805202b4ee8c04a626d00.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).