[PATCH] D38724: [ELF] - Do not collect SHT_REL[A] sections unconditionally when --gc-sections and --emit-relocs used together.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 06:15:11 PDT 2017


grimar added inline comments.


================
Comment at: ELF/MarkLive.cpp:219-221
+    // Not all sections are subject of garbage collection.
+    if (!canBeCollected(Sec))
       return;
----------------
ruiu wrote:
> grimar wrote:
> > ruiu wrote:
> > > Why do you have to check this? All non-collectible sections have already been marked alive, so you don't need to check for the same condition again in this function.
> > It is needed for REL[A] sections which are collectible. Initial condition exits
> > early for non-alloc sections, but REL[A] sections are not-alloc, but collectible,
> > so I want to let them go through.
> > Updated comment.
> I do not understand. All non-gc'able objects have already marked alive when the control flow reaches here. Why don't you use Sec->Live instead?
Let me use following theses to explain:
1) I can't use `Sec->Live`. See it is already used at line 230. But we can not use it for early return before we do `markLiveAt` 
    for MergeInputSections.
2) `markLiveAt` would assert if called for non-alloc section.
3) I could remove whole my/original code check and all tests would pass with this patch.
4) But I can't do that because it could be a reason of fail. I added testcase to demonstrate that LLD asserts when I am trying to KEEP non-alloc mergeable section from linker script.

So this check used as a guard that does not allow non-alloc sections to pass to prevent asserting in `markLiveAt`.

5) REL[A] sections are **non-alloc** sections that are not marked live yet at this place. And I want them pass this check.


https://reviews.llvm.org/D38724





More information about the llvm-commits mailing list