gas: abort in new_logical_line_flags

Alan Modra amodra@gmail.com
Tue Feb 17 10:22:17 GMT 2026


On Tue, Feb 17, 2026 at 08:18:59AM +0100, Jan Beulich wrote:
> On 17.02.2026 00:33, Alan Modra wrote:
> > .linefile 0.
> > 
> > hits the "case 1 << 3" abort in new_logical_line_flags with line_number
> > of -1.
> > 
> > Similar to commit b60f6a628897, this fixes the abort by extending the
> > meaning of .linefile in user code to restore the physical line for
> > ".linefile 0 .".
> > 
> > 	* input-scrub.c (new_logical_line_flags <case 1<<3>): Don't
> > 	abort on negative line number, instead restore physical line
> > 	for ".linefile 0".
> > 
> > diff --git a/gas/input-scrub.c b/gas/input-scrub.c
> > index afb80ef2ce0..2b90632040b 100644
> > --- a/gas/input-scrub.c
> > +++ b/gas/input-scrub.c
> > @@ -495,7 +495,12 @@ new_logical_line_flags (const char *fname, /* DON'T destroy it!  We point to it!
> >        /* FIXME: we could check that include nesting is correct.  */
> >        break;
> >      case 1 << 3:
> > -      if (line_number < 0 || fname != NULL)
> > +      /* s_linefile conditionally decrements the line depending on
> > +	 whether '\n' is seen.  */
> 
> Hmm, should we perhaps suppress the decrement there when linenum is 0?

I thought about doing that, but decided not to due to the code path
with the decrement being used when a file is given, and the comment
about gcc emitting # 0 "<built-in>".

> Or
> even reject such a use as nonsensical? What buffer_and_nest() inserts is
> a positive number in all (correct) cases. "Correct" because line + 1 can
> of course wrap, yet I'd again deem such a use bogus. (Really numbers up
> from INT_MAX are problematic, as get_linefile_number() takes a pointer to
> plain int.) And .linefile isn't intended for use in user code anyway, so
> we're pretty free to reject forms we wouldn't generate ourselves.

Yes, I probably wouldn't have bothered except for your commit
b60f6a628897 where you fixed a similar abort by making ".lininfo <n> ."
somewhat useful for users.  So there was a bit of a challenge to do
the same for ".lineinfo 0 ."

> 
> > +      if (line_number < 0
> > +	  || (line_number == 0 && input_line_pointer[-1] != '\n'))
> > +	line_number = physical_input_line;
> > +      if (fname != NULL)
> >  	abort ();
> >        if (next_saved_file == NULL)
> >  	fname = physical_input_file;
> > 

-- 
Alan Modra


More information about the Binutils mailing list