[PATCH] D25231: [ELF] - Make checks in ObjectFile<ELFT>::getSection() stricter.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 4 09:52:16 PDT 2016


ruiu added inline comments.


> InputFiles.cpp:370
>      return nullptr;
> -  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

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;

https://reviews.llvm.org/D25231





More information about the llvm-commits mailing list