[PATCH 1/2] gas: Improve file name in messages header
Alice Carlotti
alice.carlotti@arm.com
Thu Aug 14 12:14:22 GMT 2025
On Thu, Aug 14, 2025 at 08:07:37AM +0200, Jan Beulich wrote:
> On 13.08.2025 20:02, Alice Carlotti wrote:
> > 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.
> >
> > Ok for master?
>
> A few small concerns:
>
> > --- 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
> > +message_name (const char *name)
>
> I consider the function name too generic for its purpose. Seeing that ...
>
> > @@ -81,14 +88,8 @@ identify (const char *file)
>
> ... this is the only user, maybe identify_name()?
I actually had identify_name at first, but I thought that was confusing because
that name suggests a meaning of "find out and return the name". However, I'm
happy to change it back if you'd prefer (or to take any other suggestions).
>
> > return;
> > identified++;
> >
> > - if (!file)
> > - {
> > - unsigned int x;
> > - file = as_where (&x);
> > - }
> > -
> > - if (file)
> > - fprintf (stderr, "%s: ", file);
> > + if (ident_name)
>
> read_a_source_file() is called with "", not NULL, when there's no file name
> input argument.
Good point. I think `if (*ident_name)` or `if (ident_name[0])` would work.
>
> > --- a/gas/read.c
> > +++ b/gas/read.c
> > @@ -897,6 +897,7 @@ read_a_source_file (const char *name)
> >
> > buffer = input_scrub_new_file (name);
> >
> > + message_name (name);
>
> Shouldn't this move ahead of input_scrub_new_file()?
I think that would be more obviously correct - I originally put it next to
listing_file() because it's doing the same thing as that function.
>
> Also, what if there's no diagnostic at all for the first file, but there is
> one for a later input? It may be intentional to then show that file's name,
> but that's not given. An option might be to not show a file name at all in
> identify().
It might be more consistent if the ident were reprinted for every top level
file, or if no file name were printed when there are multiple inputs. However,
I think the behaviour in this patch is already strictly better than the
existing behaviour, so I decided to stick with a simpler incremental change.
Alice
>
> Jan
More information about the Binutils
mailing list