]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: recognize #APP at start-of-physical-line only
authorJan Beulich <jbeulich@suse.com>
Mon, 5 Aug 2024 14:28:43 +0000 (16:28 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 5 Aug 2024 14:28:43 +0000 (16:28 +0200)
It's not valid to recognize it after mere line separators (often
semicolon) or after labels, let alone after tc_unrecognized_line()
perhaps having parsed off parts of a line. It shouldn't even be
preceded by whitespace, aiui.

However, keep ignoring line comments as before, for backwards
compatibility.

gas/read.c

index adb4759a96bfd2f545cd86bc91903f1845c72e76..c6fb3dc5a1d4fa3031aa0e6b059f59814169be8e 100644 (file)
@@ -900,7 +900,7 @@ read_a_source_file (const char *name)
 #endif
       while (input_line_pointer < buffer_limit)
        {
-         bool was_new_line;
+         char was_new_line;
          /* We have more of this buffer to parse.  */
 
          /* We now have input_line_pointer->1st char of next line.
@@ -953,6 +953,59 @@ read_a_source_file (const char *name)
                listing_newline (NULL);
            }
 #endif
+
+         next_char = *input_line_pointer;
+         if (was_new_line == 1 && next_char
+             && strchr (line_comment_chars, next_char))
+           {
+             /* Its a comment.  Check for APP followed by NO_APP.  */
+             sb sbuf;
+             char *ends;
+             size_t len;
+
+             s = input_line_pointer + 1;
+             if (!startswith (s, "APP\n"))
+               {
+                 /* We ignore it.  Note: Not ignore_rest_of_line ()!  */
+                 while (s <= buffer_limit)
+                   if (is_end_of_line (*s++))
+                     break;
+                 input_line_pointer = s;
+                 continue;
+               }
+             bump_line_counters ();
+             s += 4;
+
+             ends = strstr (s, "#NO_APP\n");
+             len = ends ? ends - s : buffer_limit - s;
+
+             sb_build (&sbuf, len + 100);
+             sb_add_buffer (&sbuf, s, len);
+             if (!ends)
+               {
+                 /* The end of the #APP wasn't in this buffer.  We
+                    keep reading in buffers until we find the #NO_APP
+                    that goes with this #APP  There is one.  The specs
+                    guarantee it...  */
+                 do
+                   {
+                     buffer_limit = input_scrub_next_buffer (&buffer);
+                     if (!buffer_limit)
+                       break;
+                     ends = strstr (buffer, "#NO_APP\n");
+                     len = ends ? ends - buffer : buffer_limit - buffer;
+                     sb_add_buffer (&sbuf, buffer, len);
+                   }
+                 while (!ends);
+               }
+
+             input_line_pointer = ends ? ends + 8 : NULL;
+             input_scrub_include_sb (&sbuf, input_line_pointer, expanding_none);
+             sb_kill (&sbuf);
+             buffer_limit = input_scrub_next_buffer (&input_line_pointer);
+             continue;
+           }
+
          if (was_new_line)
            {
              line_label = NULL;
@@ -1316,51 +1369,12 @@ read_a_source_file (const char *name)
            }
 
          if (next_char && strchr (line_comment_chars, next_char))
-           {                   /* Its a comment.  Better say APP or NO_APP.  */
-             sb sbuf;
-             char *ends;
-             size_t len;
-
-             s = input_line_pointer;
-             if (!startswith (s, "APP\n"))
-               {
-                 /* We ignore it.  Note: Not ignore_rest_of_line ()!  */
-                 while (s <= buffer_limit)
-                   if (is_end_of_line (*s++))
-                     break;
-                 input_line_pointer = s;
-                 continue;
-               }
-             bump_line_counters ();
-             s += 4;
-
-             ends = strstr (s, "#NO_APP\n");
-             len = ends ? ends - s : buffer_limit - s;
-
-             sb_build (&sbuf, len + 100);
-             sb_add_buffer (&sbuf, s, len);
-             if (!ends)
-               {
-                 /* The end of the #APP wasn't in this buffer.  We
-                    keep reading in buffers until we find the #NO_APP
-                    that goes with this #APP  There is one.  The specs
-                    guarantee it...  */
-                 do
-                   {
-                     buffer_limit = input_scrub_next_buffer (&buffer);
-                     if (!buffer_limit)
-                       break;
-                     ends = strstr (buffer, "#NO_APP\n");
-                     len = ends ? ends - buffer : buffer_limit - buffer;
-                     sb_add_buffer (&sbuf, buffer, len);
-                   }
-                 while (!ends);
-               }
-
-             input_line_pointer = ends ? ends + 8 : NULL;
-             input_scrub_include_sb (&sbuf, input_line_pointer, expanding_none);
-             sb_kill (&sbuf);
-             buffer_limit = input_scrub_next_buffer (&input_line_pointer);
+           {
+             /* Its a comment, ignore it.  Note: Not ignore_rest_of_line ()!  */
+             while (s <= buffer_limit)
+               if (is_end_of_line (*s++))
+                 break;
+             input_line_pointer = s;
              continue;
            }