[PATCH 3 11/16] MIPS: Fix line info in compressed MIPS function

Maciej W. Rozycki macro@orcam.me.uk
Thu Nov 5 09:47:16 GMT 2026


On Wed, 4 Nov 2026, Maciej W. Rozycki wrote:

> > diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
> > index d38c43d171c..ee9b9fdf292 100644
> > --- a/bfd/elfxx-mips.c
> > +++ b/bfd/elfxx-mips.c
> > @@ -13603,6 +13603,7 @@ _bfd_mips_elf_find_nearest_line (bfd *abfd, asymbol **symbols,
> >  				 unsigned int *discriminator_ptr)
> >  {
> >    asection *msec;
> > +  bool found = false;
> >  
> >    if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
> >  				     filename_ptr, functionname_ptr,
> > @@ -13693,9 +13694,21 @@ _bfd_mips_elf_find_nearest_line (bfd *abfd, asymbol **symbols,
> >  
> >    /* Fall back on the generic ELF find_nearest_line routine.  */
> >  
> > -  return _bfd_elf_find_nearest_line (abfd, symbols, section, offset,
> > -				     filename_ptr, functionname_ptr,
> > -				     line_ptr, discriminator_ptr);
> > +  found = _bfd_elf_find_nearest_line (abfd, symbols, section, offset,
> > +				       filename_ptr, functionname_ptr,
> > +				       line_ptr, discriminator_ptr);
> > +
> > +  /* The bfd_find_nearest_line_discriminator may not be able to find filename
> > +     and line if pc points to start of a MIPS compressed function.  This is
> > +     because ISA bit is set in the line number entries.  For example, if start
> > +     of a function is 0x80200750 then line number entries start from 0x80200751
> > +     (31st bit is set).  Set ISA bit of the pc and search again.  
> > +  if (found && *filename_ptr == NULL && *line_ptr == 0 && (offset & 1) == 0)
> > +    found = _bfd_elf_find_nearest_line (abfd, symbols, section,
> > +					offset | 1,
> > +					filename_ptr, functionname_ptr,
> > +					line_ptr, discriminator_ptr);  */
> > +  return found;
> 
>  So this sets the ISA bit and retries once all the handlers have failed.  
> This would be conceptually analogous to GDB commit 3e29f34a4eef ("MIPS: 
> Keep the ISA bit in compressed code addresses"), which makes sense to me.

 I've experimented with this code a little and it's obvious that the retry 
cannot work, because the call to `_bfd_dwarf2_find_nearest_line_with_alt' 
from `_bfd_elf_find_nearest_line_with_alt' fallback succeeds even if there 
has been no line match (return code 2).

 We do need to do what `mips_adjust_dwarf2_addr' does in the GDB change 
referred, that is set the ISA bit before trying to match line information 
for compressed functions.  The snippet below, replacing the piece of code 
quoted, does what's expected as per the change description.

 Of course it needs a suitable comment, possibly derived from one quoted 
above with the original change, plus the remaining issues pointed out have 
to be addressed.  Please get it sorted in v4.

  Maciej

diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 4e8ffa5bc25..097a7d7afdc 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -13339,7 +13339,16 @@ _bfd_mips_elf_find_nearest_line (bfd *abfd, asymbol **symbols,
 				 unsigned int *line_ptr,
 				 unsigned int *discriminator_ptr)
 {
+  elf_symbol_type *elfsym;
   asection *msec;
+  asymbol *fun;
+
+  fun = _bfd_elf_find_function (abfd, symbols, section, offset, NULL, NULL);
+  elfsym = (elf_symbol_type *) fun;
+  if (elfsym != NULL
+      && ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_FUNC
+      && ELF_ST_IS_COMPRESSED (elfsym->internal_elf_sym.st_other))
+    offset |= 1;
 
   if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
 				     filename_ptr, functionname_ptr,


More information about the Binutils mailing list