We've recently become aware of a divergence between
the interpretation of SHT_SYMTAB_SHNDX in the Solaris
and GNU toolchain that I'd like to see fixed.
The gABI can be interpreted as saying that a given object
can only have a single SHT_SYMTAB_SHNDX section:
http://www.sco.com/developers/gabi/latest/ch4.sheader.html
SHT_SYMTAB_SHNDX
This section is associated with a section of
type SHT_SYMTAB and is required if any of the
section header indexes referenced by that symbol
table contain the escape value SHN_XINDEX.
and we see that binutils/BFD enforce that, as witnessed
by this bug that the illumos guys filed a while back:
https://sourceware.org/bugzilla/show_bug.cgi?id=15835
Meanwhile, the Solaris Linker and Libraries Manual, which
is where we have our version of the gABI information, says:
SHT_SYMTAB_SHNDX
Identifies a section containing extended section
indexes, that are associated with a symbol table.
If any section header indexes referenced by a symbol
table, contain the escape value SHN_XINDEX, an
associated SHT_SYMTAB_SHNDX is required.
Note the change from "SHT_SYMTAB" to the generic "symbol table",
which accommodates SHT_DYNSYM, and the Solaris specific
SHT_SUNW_LDYNSYM, along with any other symbol tables that may
be invented in the future.
We were part of the gABI definition, and our historical records
show that we started with the same words as in the gABI, but it
seems that at some point, probably while implementing the extended
section stuff, we modified that, and in an object with more than
SHN_LORESERVE sections, we will produce an SHT_SYMTAB_SHNDX for
all symbol tables, and not just .symtab. I think this makes sense:
- Because the SHNDX section elements are paired
1:1, each symbol table requires its own.
- The intent to support multiple SHNDX is clear in
the fact that the sh_link field is used to make
the association explicit.
- It is standard and common for a given executable
or shared object to have both a .symtab, and a
.dynsym, and if you want their st_shndx fields to
be accurate, each needs an SHNDX.
Hence, the need, and possibility, for multiple SHNDX sections.
Although what we did seems reasonable, I'm unable to explain
why we never fed that information back to the wider community.
I think we just dropped that ball, something that I'd like to
rectify now.
Overall, I think that multiple SHNDX should be allowed, but not
required, at the option of the link-editor, and that BFD ought
to support that. Clarifying the gABI on this point seems like
the right place to start that discussion. I asked Cary about the
GNU linkers off list, and he confirms that they can in fact
generate multiple SHNDX:
> As far as the gABI is concerned, I think it's mostly that we only
> anticipated a need for huge section tables in relocatable object
> files. The upper bound became an issue only after we added COMDAT
> sections to handle C++, and after linking, I think it would be
> exceedingly unlikely to need so many sections in an executable file or
> a shared object.
>
> Nevertheless, gold will create a .dynsym_shndx section if necessary,
> alongside the .symtab_shndx section, both with type SHT_SYMTAB_SHNDX,
> and we use the sh_link field to point to the associated SHT_SYMTAB
> section. I doubt we've ever exercised this feature, though.
FWIW, both of his points (only really used in relocatable objects,
not something that gets commonly exercised) match our experiences.
Are there any objections to changing the gABI wording on this
feature to match those from the Solaris documentation, and make it
clear that multiple SHT_SYMTAB_SHNDX sections are allowed?
- Ali