[PATCH] ld: Run ld-scripts/fill2 only for BFD64

Alan Modra amodra@gmail.com
Mon Jan 1 00:50:44 GMT 2024


On Sat, Dec 30, 2023 at 06:55:06AM -0800, H.J. Lu wrote:
> FILL ($0001020304050607) in fil2.t has the value read by strtoul (via
> scan_bfd_vma in ldlex.l), and strtoul returns -1 on overflow when BFD64
> isn't defined.  Add is_bfd64 and don't run ld-scripts/fill2 if is_bfd64
> returns 0.
> 
> 	PR ld/31120
> 	* testsuite/config/default.exp (is_bfd64): New.
> 	* testsuite/ld-scripts/fill2.d (notarget): Add ![is_bfd64].

Here is an alternate approach.  I'm inclined to go this way because it
removes another host difference (the size of bfd_vma depends on host
and target), and in any case 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 32-bit bfd_vma rather
than using (bfd_vma) -1.

Does anyone have a reason to not do this?

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

diff --git a/ld/ldlex.l b/ld/ldlex.l
index 101f5271b94..ed68be82e3f 100644
--- a/ld/ldlex.l
+++ b/ld/ldlex.l
@@ -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')


-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list