PR31120, ld-scripts/fill2 fails when bfd_vma is 32 bits
authorAlan Modra <amodra@gmail.com>
Sun, 31 Dec 2023 03:39:10 +0000 (14:09 +1030)
committerAlan Modra <amodra@gmail.com>
Fri, 5 Jan 2024 02:30:11 +0000 (13:00 +1030)
The ld lexer converts strings to integers without overflow checking,
so I don't think there is any problem in truncating an integer that
exceeds the size of a bfd_vma rather than using (bfd_vma) -1.

PR 31120
* ldlex.l: Don't use bfd_scan_vma for integer conversion, use
strtoull.

ld/ldlex.l

index 5a771b4..e113c90 100644 (file)
@@ -133,7 +133,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
                                comment (); }
 
 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
-                               yylval.integer = bfd_scan_vma (yytext + 1, 0, 16);
+                               yylval.integer = strtoull (yytext + 1, 0, 16);
                                yylval.bigint.str = NULL;
                                return INT;
                        }
@@ -158,8 +158,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
                                    default:
                                     ibase = 10;
                                   }
-                                  yylval.integer = bfd_scan_vma (yytext, 0,
-                                                                 ibase);
+                                  yylval.integer = strtoull (yytext, 0, ibase);
                                   yylval.bigint.str = NULL;
                                   return INT;
                                 }
@@ -172,7 +171,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
                                      ++s;
                                      ibase = 16;
                                    }
-                                 yylval.integer = bfd_scan_vma (s, 0, ibase);
+                                 yylval.integer = strtoull (s, 0, ibase);
                                  yylval.bigint.str = NULL;
                                  if (yytext[yyleng - 1] == 'M'
                                      || yytext[yyleng - 1] == 'm')