[PATCH 2/2] gas: Record file name in macro locations

Jan Beulich jbeulich@suse.com
Thu Aug 14 14:39:49 GMT 2025


On 14.08.2025 13:59, Alice Carlotti wrote:
> On Thu, Aug 14, 2025 at 08:19:47AM +0200, Jan Beulich wrote:
>> On 13.08.2025 20:03, Alice Carlotti wrote:
>>> This allows the correct file name to be used when emitting messages for
>>> lines within a macro.  The line numbers were already set and displayed
>>> correctly, which resulted in mismatched file names and line numbers.
>>>
>>> PR 32738
>>>
>>> Ok for master?
>>>
>>>
>>> diff --git a/gas/macro.c b/gas/macro.c
>>> index 20309d4d68f0958839f07a85b83f47d5624750ef..13202d3f58a5e21913e47b2a5be521f92a84086d 100644
>>> --- a/gas/macro.c
>>> +++ b/gas/macro.c
>>> @@ -112,11 +112,13 @@ buffer_and_nest (const char *from, const char *to, sb *ptr,
>>>      unsigned int line;
>>>      char *linefile;
>>>  
>>> -    as_where_top (&line);
>>> -    if (!flag_m68k_mri)
>>> -      linefile = xasprintf ("\t.linefile %u .", line + 1);
>>> +    const char *prefix = flag_m68k_mri ? "" : ".";
>>> +    const char *file = as_where_top (&line);
>>> +
>>> +    if (file)
>>> +      linefile = xasprintf ("\t%slinefile %u \"%s\"", prefix, line + 1, file);
>>>      else
>>> -      linefile = xasprintf ("\tlinefile %u .", line + 1);
>>> +      linefile = xasprintf ("\t%slinefile %u .", prefix, line + 1);
>>>      sb_add_string (ptr, linefile);
>>>      xfree (linefile);
>>
>> While this looks to make sense, ...
>>
>>> --- a/gas/testsuite/gas/elf/line.l
>>> +++ b/gas/testsuite/gas/elf/line.l
>>> @@ -2,17 +2,17 @@
>>>  
>>>  .*: Assembler messages:
>>>  line\.s:[0-9]*18: Warning: \.warning .*
>>> -line\.s:2: Warning: m1/1: 123
>>> +.*line\.s:2: Warning: m1/1: 123
>>
>> ... I can't see why this (and other similar) change(s) are needed. Plain "line.s"
>> without anything ahead of it looks to be what is wanted here.
> 
> The assembler is invoked with a longer file path, not just a file name, and
> this is what as_where, etc. return.  This particular test file explicitly sets
> the location to "line.s" in line 17, which is why the ".*" wasn't previously
> needed. However, the macro is defined before that point, so it now uses the
> full input file path for the location.

Oh, yes, of course.

Jan


More information about the Binutils mailing list