non-conformant ELF symbol table on MIPS?

Alan Modra amodra@gmail.com
Fri Jul 28 23:58:33 GMT 2023


On Fri, Jul 28, 2023 at 10:11:50AM -0700, Ian Lance Taylor via Binutils wrote:
> On Thu, Jul 27, 2023 at 11:16 PM Jan Beulich <jbeulich@suse.com> wrote:
> >
> > On 27.07.2023 21:04, Ian Lance Taylor wrote:
> > > On Thu, Jul 27, 2023 at 7:28 AM Jan Beulich via Binutils
> > > <binutils@sourceware.org> wrote:
> > >>
> > >> extending the gas elf/common3.s testcase (in the context of trying to fix
> > >> PR gas/30688) to
> > >>
> > >>         .comm foobar,30,4
> > >>         .comm buf1, 5-1, 8
> > >>         .comm buf2, 4, 9-1
> > >>         .lcomm lbuf, 9-1
> > >>
> > >> I notice a violation of the ELF spec on most (all?) MIPS targets I would
> > >> routinely test for common code changes: "lbuf" is emitted last in the
> > >> symbol table. The spec is quite clear: "In each symbol table, all
> > >> symbols with STB_LOCAL binding precede the weak and global symbols." I
> > >> guess I want/need to xfail that test for mips*-*-* for the time being,
> > >> but it would be nice if you could shed some light on this behavior.
> > >
> > > This is historical behavior that dates back to the SGI Irix operating
> > > system.  Search for elf_bad_symtab in the BFD sources.  Here is the
> > > commend from elf-bfd.h:
> > >
> > >   /* Irix 5 often screws up the symbol table, sorting local symbols
> > >      after global symbols.  This flag is set if the symbol table in
> > >      this BFD appears to be screwed up.  If it is, we ignore the
> > >      sh_info field in the symbol table header, and always read all the
> > >      symbols.  */
> > >   unsigned int bad_symtab : 1;
> > >
> > > I believe we currently set elf_bad_symtab true by default for most MIPS targets.
> >
> > That explains consuming behavior. But gas is a producer, and from what
> > you say and quote I can't see why gas also needs to produce non-
> > conforming symbol tables.
> 
> It was required for the linker, because otherwise the SGI IRIX dynamic
> linker would not work correctly.
> 
> I don't recall whether it was required for gas.  That may have been an
> accidental carry-over.  Or it may have been required for the IRIX
> static linker to work, I don't remember.

I think it is probably required.  It's not just the sorting within
symbol tables but also the meaning of sh_info.  For mips irix5 a
symbol table sh_info is the section symbol count, not the local symbol
count.  I say "probably" because I guess it might be possible to have
SHT_SYMTAB and SHT_DYNSYM differ, but that seems even more weird.

> Doing it for the plain mips-elf target is probably not the best choice today.

I agree.

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list