[PATCH 2/3] RISC-V: Stricter underscore handling for ISA
Tsukasa OI
research_trasio@irq.a4lg.com
Wed Feb 23 01:47:23 GMT 2022
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
More information about the Binutils
mailing list