[PATCH] D90458: [yaml2obj][WIP] - ProgramHeaders: introduce FirstSec/LastSec instead of Sections list.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 2 02:13:19 PST 2020


grimar added a comment.

In D90458#2367707 <https://reviews.llvm.org/D90458#2367707>, @jhenderson wrote:

> As long as this approach still allows creating program headers with the exact same contents as before (i.e. it's as flexible as possible), then it makes sense to me too. Happy for you to proceed.

It indeed will be at least on the same level of flexibility.

FTR, partially I was inspired by the following possible situation. Currently we allocate a space for nobits sections in a segment when there are
fills or non-nobits sections after them:

  static bool shouldAllocateFileSpace(ArrayRef<ELFYAML::ProgramHeader> Phdrs,
                                      const ELFYAML::NoBitsSection &S) {
    for (const ELFYAML::ProgramHeader &PH : Phdrs) {
      auto It = llvm::find_if(
          PH.Chunks, [&](ELFYAML::Chunk *C) { return C->Name == S.Name; });
      if (std::any_of(It, PH.Chunks.end(), [](ELFYAML::Chunk *C) {
            return (isa<ELFYAML::Fill>(C) ||
                    cast<ELFYAML::Section>(C)->Type != ELF::SHT_NOBITS);
          }))
        return true;
    }
    return false;
  }

If we have a segment with sections:
`<regular1>, <nobits1>, <regular2>, <nobits2>`

Then we might have a segment description that specifies only <regular1> and <nobits2>:

  Sections:
    - Section: <regular1>
    - Section: <nobits2>

and it will be different from the case where we explicitly specify all of sections,
because in the case above I believe we will not allocate a space for the <nobits1> section with the current code.

That is why I tried to implement a requirement about that all sections must explicitly present in the segment description at first.

With the solution that this patch suggests it should be impossible to trigger the possible bug/misbehavior I've described.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90458/new/

https://reviews.llvm.org/D90458



More information about the llvm-commits mailing list