]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
riscv_parsing_subset_version: Handle "0p0" version strings.
authorJohn Baldwin <jhb@FreeBSD.org>
Wed, 12 Oct 2022 17:58:01 +0000 (10:58 -0700)
committerJohn Baldwin <jhb@FreeBSD.org>
Wed, 12 Oct 2022 20:48:09 +0000 (13:48 -0700)
Use a boolean to determine if a version is present (similar to
what is done in riscv_parse_prefixed_ext) rather than assuming
that both versions set to 0 means no version was present.

This fixes parsing of an attribute string of
"rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_xcheri0p0" which previously failed
with the error:

BFD: x ISA extension `xcheri' must be set with the versions

bfd/elfxx-riscv.c

index cb2cc146c04bf4be7f867f7bb7ee6e148f36154e..95d2ffc10b512f45c1c9cd88be05d398048ffcd2 100644 (file)
@@ -1597,12 +1597,13 @@ riscv_parsing_subset_version (const char *p,
                              int *major_version,
                              int *minor_version)
 {
+  bool found_version = false;
   bool major_p = true;
   int version = 0;
   char np;
 
-  *major_version = 0;
-  *minor_version = 0;
+  *major_version = RISCV_UNKNOWN_VERSION;
+  *minor_version = RISCV_UNKNOWN_VERSION;
   for (; *p; ++p)
     {
       if (*p == 'p')
@@ -1618,21 +1619,23 @@ riscv_parsing_subset_version (const char *p,
          version = 0;
        }
       else if (ISDIGIT (*p))
-       version = (version * 10) + (*p - '0');
+       {
+         found_version = true;
+         version = (version * 10) + (*p - '0');
+       }
       else
        break;
     }
 
-  if (major_p)
-    *major_version = version;
-  else
-    *minor_version = version;
-
-  /* We can not find any version in string.  */
-  if (*major_version == 0 && *minor_version == 0)
+  if (found_version)
     {
-      *major_version = RISCV_UNKNOWN_VERSION;
-      *minor_version = RISCV_UNKNOWN_VERSION;
+      if (major_p)
+       {
+         *major_version = version;
+         minor_version = 0;
+       }
+      else
+       *minor_version = version;
     }
 
   return p;