]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: sanitize FB- and dollar-label uses
authorJan Beulich <jbeulich@suse.com>
Thu, 28 Mar 2024 10:53:59 +0000 (11:53 +0100)
committerJan Beulich <jbeulich@suse.com>
Thu, 28 Mar 2024 10:53:59 +0000 (11:53 +0100)
I don't view it as sensible to be more lax when it comes to references
to (uses of) such labels compared to their definition: The latter has
been limited to decimal numerics, while the former permitted any radix.
Beyond that leading zeroes on such labels aren't helpful either. Imo
labels and their use sites would better match literally, to avoid
confusion.

As it turns out, one z80 testcase actually had such an odd use of labels
where definition and use don't match in spelling. That testcase is being
adjusted accordingly.

While there also adjust a comment on a local variable in
integer_constant().

gas/NEWS
gas/expr.c
gas/read.c
gas/testsuite/gas/z80/sdcc.s

index 92b02de00cd5a0cc02a271cb856013e06a6ccf6f..f48edd4b8c3024572a6acece0454b14fd2d69f2d 100644 (file)
--- a/gas/NEWS
+++ b/gas/NEWS
@@ -1,5 +1,9 @@
 -*- text -*-
 
+* References to FB and dollar labels, when supported, are no longer permitted
+  in a radix other than 10.  (Note that definitions of such labels were already
+  thus restricted, except that leading zeroes were permitted.)
+
 * Remove support for RISC-V privileged spec 1.9.1, but linker can still
   recognize it in case of linking old objects.
 
index 3a01b88e31042d145afbbfd94221cc8e58884a97..79db30f873e7e6aeec97f2bd69cefb7c8c3f70be 100644 (file)
@@ -284,7 +284,7 @@ integer_constant (int radix, expressionS *expressionP)
   char *name;          /* Points to name of symbol.  */
   symbolS *symbolP;    /* Points to symbol.  */
 
-  int small;                   /* True if fits in 32 bits.  */
+  bool small;          /* True if fits in 32 bits (64 bits with BFD64).  */
 
   /* May be bignum, or may fit in 32 bits.  */
   /* Most numbers fit into 32 bits, and we want this case to be fast.
@@ -549,10 +549,12 @@ integer_constant (int radix, expressionS *expressionP)
 #ifndef tc_allow_L_suffix
 #define tc_allow_L_suffix 1
 #endif
+  bool l_seen = !tc_allow_L_suffix;
   /* PR 20732: Look for, and ignore, a L or LL suffix to the number.  */
   if (tc_allow_L_suffix && (c == 'L' || c == 'l'))
     {
       c = * input_line_pointer++;
+      l_seen = true;
       if (c == 'L' || c == 'l')
        c = *input_line_pointer++;
       if (!u_seen && (c == 'U' || c == 'u'))
@@ -561,13 +563,14 @@ integer_constant (int radix, expressionS *expressionP)
 
   if (small)
     {
-      /* Here with number, in correct radix. c is the next char.
-        Note that unlike un*x, we allow "011f" "0x9f" to both mean
-        the same as the (conventional) "9f".
-        This is simply easier than checking for strict canonical
-        form.  Syntax sux!  */
-
-      if (LOCAL_LABELS_FB && c == 'b')
+      /* Here with number, in correct radix. c is the next char.  */
+      bool maybe_label = suffix == NULL
+                        && (!tc_allow_U_suffix || !u_seen)
+                        && (!tc_allow_L_suffix || !l_seen)
+                        && (radix == 10 ||
+                            (radix == 8 && input_line_pointer == start + 1));
+
+      if (LOCAL_LABELS_FB && c == 'b' && maybe_label)
        {
          /* Backward ref to local label.
             Because it is backward, expect it to be defined.  */
@@ -593,7 +596,7 @@ integer_constant (int radix, expressionS *expressionP)
 
          expressionP->X_add_number = 0;
        }                       /* case 'b' */
-      else if (LOCAL_LABELS_FB && c == 'f')
+      else if (LOCAL_LABELS_FB && c == 'f' && maybe_label)
        {
          /* Forward reference.  Expect symbol to be undefined or
             unknown.  undefined: seen it before.  unknown: never seen
@@ -609,7 +612,7 @@ integer_constant (int radix, expressionS *expressionP)
          expressionP->X_add_symbol = symbolP;
          expressionP->X_add_number = 0;
        }                       /* case 'f' */
-      else if (LOCAL_LABELS_DOLLAR && c == '$')
+      else if (LOCAL_LABELS_DOLLAR && c == '$' && maybe_label)
        {
          /* If the dollar label is *currently* defined, then this is just
             another reference to it.  If it is not *currently* defined,
index 8c1e399b63f8cbfc6ef128d6e13cc69f9e92a485..61a3f172674b0a71dca7ab9eb4cf6ccbc0582929 100644 (file)
@@ -1269,6 +1269,10 @@ read_a_source_file (const char *name)
              while (ISDIGIT (*input_line_pointer))
                {
                  const long digit = *input_line_pointer - '0';
+
+                 /* Don't accept labels which look like octal numbers.  */
+                 if (temp == 0)
+                   break;
                  if (temp > (INT_MAX - digit) / 10)
                    {
                      as_bad (_("local label too large near %s"), backup);
index 5fe9288c220ac842e2201848c27659fcc2ac290a..98994276ced372bddc31580300ee6a5ede2a99f7 100644 (file)
@@ -13,7 +13,7 @@ valueadr = 0x1234
 _start::
 ;comment
        ld      hl, #4+0
-00000$:
+0$:
        adc     a, a
        adc     a, b
        adc     a, c
@@ -29,7 +29,7 @@ _start::
        adc     a, (hl)
        adc     a, 5 (ix)
        adc     a, -2 (iy)
-00100$:
+100$:
        add     a, a
        add     a, b
        add     a, c
@@ -45,7 +45,7 @@ _start::
        add     a, (hl)
        add     a, 5 (ix)
        add     a, -2 (iy)
-00200$:
+200$:
        and     a, a
        and     a, b
        and     a, c
@@ -61,7 +61,7 @@ _start::
        and     a, (hl)
        and     a, 5 (ix)
        and     a, -2 (iy)
-00300$:
+300$:
        cp      a, a
        cp      a, b
        cp      a, c
@@ -77,7 +77,7 @@ _start::
        cp      a, (hl)
        cp      a, 5 (ix)
        cp      a, -2 (iy)
-00400$:
+400$:
        or      a, a
        or      a, b
        or      a, c
@@ -93,7 +93,7 @@ _start::
        or      a, (hl)
        or      a, 5 (ix)
        or      a, -2 (iy)
-00500$:
+500$:
        sbc     a, a
        sbc     a, b
        sbc     a, c
@@ -109,7 +109,7 @@ _start::
        sbc     a, (hl)
        sbc     a, 5 (ix)
        sbc     a, -2 (iy)
-00600$:
+600$:
        sub     a, a
        sub     a, b
        sub     a, c
@@ -125,7 +125,7 @@ _start::
        sub     a, (hl)
        sub     a, 5 (ix)
        sub     a, -2 (iy)
-00700$:
+700$:
        xor     a, a
        xor     a, b
        xor     a, c
@@ -152,10 +152,10 @@ _start::
 _func:
        ld      hl,0
        ld      (hl),#<function
-00100$:
+100$:
        inc     hl
        ld      (hl),#>function
-00600$:
+600$:
        jr      100$
 _finish::
        ld      a, 2 (iy)