aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlice Carlotti <alice.carlotti@arm.com>2025-08-07 16:58:20 +0100
committerAlice Carlotti <alice.carlotti@arm.com>2025-08-18 14:37:10 +0100
commit40acf2f9ae60f8f7d1f8a20ea0086e755253007d (patch)
treef8d44bd5950f4e0cec1f4e0b0c081695335b0977
parent5e83077d552ed6f81dbc092eb3ccf827a43de42c (diff)
downloadbinutils-40acf2f9ae60f8f7d1f8a20ea0086e755253007d.zip
binutils-40acf2f9ae60f8f7d1f8a20ea0086e755253007d.tar.gz
binutils-40acf2f9ae60f8f7d1f8a20ea0086e755253007d.tar.bz2
gas: Improve file name in messages header
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.
-rw-r--r--gas/as.h1
-rw-r--r--gas/messages.c27
-rw-r--r--gas/read.c2
-rw-r--r--gas/testsuite/gas/elf/elf.exp2
-rw-r--r--gas/testsuite/gas/elf/line2.inc6
-rw-r--r--gas/testsuite/gas/elf/line2.l5
-rw-r--r--gas/testsuite/gas/elf/line2.s3
7 files changed, 33 insertions, 13 deletions
diff --git a/gas/as.h b/gas/as.h
index 8f2facb..b743ba9 100644
--- 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);
diff --git a/gas/messages.c b/gas/messages.c
index 859ac17..1808090 100644
--- a/gas/messages.c
+++ b/gas/messages.c
@@ -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)
diff --git a/gas/read.c b/gas/read.c
index ca76af7..2e7a4ac 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -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);
diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp
index 1988788..8a9357f 100644
--- a/gas/testsuite/gas/elf/elf.exp
+++ b/gas/testsuite/gas/elf/elf.exp
@@ -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
index 0000000..89bf417
--- /dev/null
+++ b/gas/testsuite/gas/elf/line2.inc
@@ -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
index 0000000..d98b74b
--- /dev/null
+++ b/gas/testsuite/gas/elf/line2.l
@@ -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
index 0000000..40867c1
--- /dev/null
+++ b/gas/testsuite/gas/elf/line2.s
@@ -0,0 +1,3 @@
+ .include "line2.inc"
+
+ mac