One of the change we made in the past was:
" // STT_SECTION symbols can be
// associated with SHT_REL[A]/SHT_SYMTAB/SHT_STRTAB sections. // In this case it is fine for section to be null here as we // do not allocate sections of these types."
This patch makes the check for null section stricter, so it is only allowed for STT_SECTION symbols now.
I did it because testcase that contains local unnamed symbol crashes without that check in:
template <class ELFT>
static bool shouldKeepInSymtab(InputSectionBase<ELFT> *Sec, StringRef SymName,
const SymbolBody &B) {
...
return !(Sec->getSectionHdr()->sh_flags & SHF_MERGE); // HERE, because Sec is null
}
This code seems a bit too dense. I'd relax it like this.
if (Index >= Sections.size()) fatal(getFilename(this) + ": invalid section index: " + Twine(Index)); InputSectionBase<ELFT> *S = Sections[Index]; // We found that GNU assembler 2.17.50 [FreeBSD] 2007-07-03 // could generate broken objects. STT_SECTION symbols can be // associated with SHT_REL[A]/SHT_SYMTAB/SHT_STRTAB sections. // In this case it is fine for section to be null here as we // do not allocate sections of these types. if (!S) { if (Sym.getType() == STT_SECTION) return; fatal(getFilename(this) + ": invalid section index: " + Twine(Index)); } if (S == &InputSectionBase<ELFT>::Discarded) return S; return S->Repl;