]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: Improve file name in messages header
authorAlice Carlotti <alice.carlotti@arm.com>
Thu, 7 Aug 2025 15:58:20 +0000 (16:58 +0100)
committerAlice Carlotti <alice.carlotti@arm.com>
Mon, 18 Aug 2025 13:37:10 +0000 (14:37 +0100)
Message output from gas is prefixed with a line of the form:

path/file.s: Assembler messages:

Don't use the file name from the first message for this header.
Instead, use the source file name specified in the command line.

gas/as.h
gas/messages.c
gas/read.c
gas/testsuite/gas/elf/elf.exp
gas/testsuite/gas/elf/line2.inc [new file with mode: 0644]
gas/testsuite/gas/elf/line2.l [new file with mode: 0644]
gas/testsuite/gas/elf/line2.s [new file with mode: 0644]

index 8f2facbaa191961f4de2b7e492c3f8ec5eecc0d5..b743ba95cc71dfd85aa70c12cb9dd99d0e16beb9 100644 (file)
--- a/gas/as.h
+++ b/gas/as.h
@@ -500,6 +500,7 @@ PRINTF_WHERE_LIKE (as_bad_where);
 PRINTF_WHERE_LIKE (as_warn_where);
 PRINTF_INDENT_LIKE (as_info_where);
 
+void   set_identify_name (const char *);
 void   as_abort (const char *, int, const char *) ATTRIBUTE_NORETURN;
 void   signal_init (void);
 int    had_errors (void);
index 859ac17f379dad9732666e091871ef2876c65e67..18080906adee2c46ae2b9a14903ec0be90a45839 100644 (file)
@@ -27,7 +27,6 @@
 extern const char *strsignal (int);
 #endif
 
-static void identify (const char *);
 static void as_show_where (void);
 static void as_warn_internal (const char *, unsigned int, char *);
 static void as_bad_internal (const char *, unsigned int, char *);
@@ -72,8 +71,16 @@ static void signal_crash (int) ATTRIBUTE_NORETURN;
    as_abort () is used for logic failure (assert or abort, signal).
 */
 
+static const char *ident_name;
+
+void
+set_identify_name (const char *name)
+{
+  ident_name = name;
+}
+
 static void
-identify (const char *file)
+identify (void)
 {
   static int identified;
 
@@ -81,14 +88,8 @@ identify (const char *file)
     return;
   identified++;
 
-  if (!file)
-    {
-      unsigned int x;
-      file = as_where (&x);
-    }
-
-  if (file)
-    fprintf (stderr, "%s: ", file);
+  if (ident_name && *ident_name)
+    fprintf (stderr, "%s: ", ident_name);
   fprintf (stderr, _("Assembler messages:\n"));
 }
 
@@ -121,7 +122,7 @@ as_show_where (void)
   unsigned int line;
 
   file = as_where_top (&line);
-  identify (file);
+  identify ();
   if (file)
     {
       if (line != 0)
@@ -185,7 +186,7 @@ as_warn_internal (const char *file, unsigned int line, char *buffer)
       context = true;
     }
 
-  identify (file);
+  identify ();
   if (file)
     {
       if (line != 0)
@@ -259,7 +260,7 @@ as_bad_internal (const char *file, unsigned int line, char *buffer)
       context = true;
     }
 
-  identify (file);
+  identify ();
   if (file)
     {
       if (line != 0)
index ca76af7d339ab59bd163366bf0984d3405d7ee07..2e7a4accabd20ba5b79d60067b0e06bd642af546 100644 (file)
@@ -895,6 +895,8 @@ read_a_source_file (const char *name)
   found_comment = 0;
 #endif
 
+  set_identify_name (name);
+
   buffer = input_scrub_new_file (name);
 
   listing_file (name);
index 1988788fbcd86f63a7923c03089a0379ebce964e..8a9357f3cced6c5e03dca9465755be2a048bdadd 100644 (file)
@@ -340,6 +340,8 @@ if { [is_elf_format] } then {
        run_list_test line
     }
 
+    run_list_test "line2" -I${srcdir}/$subdir
+
     run_dump_test "pr25917"
     run_dump_test "bss"
     # Some targets treat .bss similar to .lcomm.
diff --git a/gas/testsuite/gas/elf/line2.inc b/gas/testsuite/gas/elf/line2.inc
new file mode 100644 (file)
index 0000000..89bf417
--- /dev/null
@@ -0,0 +1,6 @@
+       .macro mac
+       .warning "inside macro"
+       .nop
+       .endm
+
+       mac
diff --git a/gas/testsuite/gas/elf/line2.l b/gas/testsuite/gas/elf/line2.l
new file mode 100644 (file)
index 0000000..d98b74b
--- /dev/null
@@ -0,0 +1,5 @@
+.*line2\.s: Assembler messages:
+.*line2\.inc:2: Warning: inside macro
+.*line2\.inc:6:  Info: macro invoked from here
+.*:2: Warning: inside macro
+.*line2\.s:3:  Info: macro invoked from here
diff --git a/gas/testsuite/gas/elf/line2.s b/gas/testsuite/gas/elf/line2.s
new file mode 100644 (file)
index 0000000..40867c1
--- /dev/null
@@ -0,0 +1,3 @@
+       .include "line2.inc"
+
+       mac