[binutils-gdb] gas: macros nested too deep error

Alan Modra amodra@sourceware.org
Tue Feb 17 00:47:41 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fc2fcd4f5be3f88a6ba44eab0ca541f55089bef5

commit fc2fcd4f5be3f88a6ba44eab0ca541f55089bef5
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Feb 17 09:59:13 2026 +1030

    gas: macros nested too deep error
    
    .macro r;r;.endm;r
    
    Currently reports:
    nest.s: Assembler messages:
    nest.s:2: Fatal error: macros nested too deeply
    nest.s:2:  Info: macro invoked from here
    nest.s:2:   Info: macro invoked from here
    ...
    nest.s:2:<much indenting> Info: macro invoked from here
    nest.s:1:<much indenting>  Info: macro invoked from here
    
    This patch corrects the line number reported, and downgrades the error
    from as_fatal to as_bad.
    
            * input-scrub.c (input_scrub_include_sb): Report "macros
            nested too deeply" using as_bad.
            * macro.c (buffer_and_nest): Only bump line number in .lineinfo
            if we have a '\n'.

Diff:
---
 gas/input-scrub.c | 5 ++++-
 gas/macro.c       | 6 ++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/gas/input-scrub.c b/gas/input-scrub.c
index 2ccc2ce9c8e..afb80ef2ce0 100644
--- a/gas/input-scrub.c
+++ b/gas/input-scrub.c
@@ -298,7 +298,10 @@ input_scrub_include_sb (sb *from, char *position, enum expansion expansion)
   if (expansion != expanding_app)
     {
       if (macro_nest > max_macro_nest)
-	as_fatal (_("macros nested too deeply"));
+	{
+	  as_bad (_("macros nested too deeply"));
+	  return;
+	}
       ++macro_nest;
     }
 
diff --git a/gas/macro.c b/gas/macro.c
index 6f204d94ce4..76989259feb 100644
--- a/gas/macro.c
+++ b/gas/macro.c
@@ -104,10 +104,12 @@ buffer_and_nest (const char *from, const char *to, sb *ptr,
     const char *prefix = flag_m68k_mri ? "" : ".";
     const char *file = as_where_top (&line);
 
+    if (*input_line_pointer == '\n')
+      line++;
     if (file)
-      linefile = xasprintf ("\t%slinefile %u \"%s\"", prefix, line + 1, file);
+      linefile = xasprintf ("\t%slinefile %u \"%s\"", prefix, line, file);
     else
-      linefile = xasprintf ("\t%slinefile %u .", prefix, line + 1);
+      linefile = xasprintf ("\t%slinefile %u .", prefix, line);
     sb_add_string (ptr, linefile);
     xfree (linefile);
   }


More information about the Binutils-cvs mailing list