[PATCH] D24750: [GC] Don't crash while processing Discarded sections

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 19 18:21:27 PDT 2016


davide added a comment.

In https://reviews.llvm.org/D24750#547093, @ruiu wrote:

> Sections are discarded mainly because they are comdat sections and deduplicated. Comdat sections are discarded as a group, so I believe there's no reference pointing to discarded sections from outside of the group. That means I think we shouldn't see discarded sections in the mark-sweep collector here. What am I missing?


I'm not very familiar with the algorihtm, so I may miss something (or at least, not as familiar as the person who wrote it :)), but, it's not entirely clear to me what prevents `&InputSection<ELFT>::Discarded` to reach the mark&sweep algorithm.
In `initializeSections()` we set `Sections[I] == &InputSection<ELFT>::Discarded` and never change it. In the `Enqueue` function we might end up enqueuing a DiscardedSection if `ResolvedReloc` refers to it.

To convince myself this was actually possible in the current code, I put the following assertion in `Enqueue`:

  if (InputSection<ELFT> *S = dyn_cast<InputSection<ELFT>>(R.Sec)) {
    if (S == &InputSection<ELFT>::Discarded)
      llvm_unreachable("foo");
    Q.push_back(S);
  }

So, are you saying that a `ResolvedReloc` which points to `&InputSection<ELFT>::Discarded` is not possible? If so, the current code violates this invariant and needs to be fixed.


https://reviews.llvm.org/D24750





More information about the llvm-commits mailing list