This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Remove unnessesary checks from GC logic.
AbandonedPublic

Authored by grimar on Jan 26 2017, 1:34 AM.

Details

Reviewers
ruiu
rafael
Summary

We set Live bit in constructor of InputSectionBase currently.
If it is set, then section should not be collected.

Previously GC code contained few excessive checks for that, thrown around in code.
And when I was need in D28612 to prevent GC for .rel[a] sections,
I had to modify that places. Though it is cleaner to remove them at all, because
we already have a Live bit set, what looks to be enough.

That should help to reduce amoount of changes for D28612.

Diff Detail

Event Timeline

grimar created this revision.Jan 26 2017, 1:34 AM
grimar retitled this revision from [ELF] - Remove unnessesary checks. to [ELF] - Remove unnessesary checks from GC logic..
davide requested changes to this revision.Jan 26 2017, 8:14 AM
davide added a subscriber: davide.

Do we have a test to make sure sections containing debug info (marked as !SHF_ALLOC) are not reclaimed? I'm a little bit worried because this broke already in the past.

ELF/MarkLive.cpp
159–161

Why did you change this comment?
We still shouldn't reclaim !SHF_ALLOC sections as they can contain debug infos

This revision now requires changes to proceed.Jan 26 2017, 8:14 AM
grimar added inline comments.Jan 26 2017, 8:19 AM
ELF/MarkLive.cpp
159–161

Because method is called isReserved().
Previously it has logic that kept !SHF_ALLOC, though !SHF_ALLOC sections are not actually reserved.
But anyways now it does not have this logic anymore, there is no point to write this in comment here, it is not possible to support comments like this, when real logic is far away.

davide added inline comments.Jan 26 2017, 8:31 AM
ELF/MarkLive.cpp
159–161

Where we prevent !SHF_ALLOC sections from being reclaimed? The comment should go there, then,

grimar added inline comments.Jan 26 2017, 8:34 AM
ELF/MarkLive.cpp
159–161

We set Live bit for all !SHF_ALLOC sections in InputSectionBase constructor:

: InputSectionData(SectionKind, Name, Data,
                   !Config->GcSections || !(Flags & SHF_ALLOC)),
davide added inline comments.Jan 26 2017, 8:38 AM
ELF/MarkLive.cpp
159–161

Please move the comment there then.

Do we have a test to make sure sections containing debug info (marked as !SHF_ALLOC) are not reclaimed? I'm a little bit worried because this broke already in the past.

Yes, we do.
For example gc-sections-alloc.s has !SHF_ALLOC section that is kept, while allocatable section it refers to is collected.

grimar updated this revision to Diff 85943.Jan 26 2017, 11:29 AM
grimar edited edge metadata.
  • Addressed review comment.
ruiu edited edge metadata.Jan 26 2017, 11:34 AM

I don't know if this is making things better - it seems neutral to me or an unnecessary churn.

In D29170#657896, @ruiu wrote:

I don't know if this is making things better - it seems neutral to me or an unnecessary churn.

In D29170#657896, @ruiu wrote:

I don't know if this is making things better - it seems neutral to me or an unnecessary churn.

Same. I'm actually a bit confused about this refactoring. First we had the logic in a single place and now we moved part of it to InputSection.{cpp,h} (i.e. the assertion became an if).

In D29170#657896, @ruiu wrote:

I don't know if this is making things better - it seems neutral to me or an unnecessary churn.

Interesting. Is not it the same what you mentioned during review of D28612 ?

"So, the right way of doing it is to set Live bit in the ctor if it should never be GC'ed."

Instead of checking the sections flags everywhere patch relies on Live bit now.

Same. I'm actually a bit confused about this refactoring. First we had the logic in a single place and now we moved part of it to InputSection.{cpp,h} (i.e. the assertion became an if).

D28612 adds SHT_RELA and SHT_REL sections that should be involved in GC (because .rela.text depends on .text and we do not want to keep REL[A] sections unconditionally).
REL[A] sections are not SHF_ALLOC, that means I need to set up GC logic for them.

With this patch only I need is to add that to constructor of InputSectionData which sets the Live bit now:

!Config->GcSections || !(Flags & SHF_ALLOC)), //Add here

Patch changes conditions of GC to use Live bit instead of rechecking the sections flags again.

Next part you are talking about is different:

void markLiveAt(uintX_t Offset) {
  if (this->Flags & SHF_ALLOC)
    LiveOffsets.insert(Offset);
}

It is a member of MergeInputSection, and MergeInputSection has multiple same checks in it's methods because its behavior is different for allocatable and nonallocatable
cases. So this part of patch localizes that check and isolates inside MergeInputSection instead of spreading it to GC code.

ruiu added a comment.Jan 27 2017, 11:25 AM

Interesting. Is not it the same what you mentioned during review of D28612 ?

"So, the right way of doing it is to set Live bit in the ctor if it should never be GC'ed."

Instead of checking the sections flags everywhere patch relies on Live bit now.

Well, it is not a good idea to follow someone's advice blindly. You wrote this, so what do you think of this patch? I think that is important. I think this is not something I expected, and I believe there's a better way, but that's not this.

Same. I'm actually a bit confused about this refactoring. First we had the logic in a single place and now we moved part of it to InputSection.{cpp,h} (i.e. the assertion became an if).

D28612 adds SHT_RELA and SHT_REL sections that should be involved in GC (because .rela.text depends on .text and we do not want to keep REL[A] sections unconditionally).
REL[A] sections are not SHF_ALLOC, that means I need to set up GC logic for them.

With this patch only I need is to add that to constructor of InputSectionData which sets the Live bit now:

!Config->GcSections || !(Flags & SHF_ALLOC)), //Add here

Patch changes conditions of GC to use Live bit instead of rechecking the sections flags again.

Next part you are talking about is different:

void markLiveAt(uintX_t Offset) {
  if (this->Flags & SHF_ALLOC)
    LiveOffsets.insert(Offset);
}

It is a member of MergeInputSection, and MergeInputSection has multiple same checks in it's methods because its behavior is different for allocatable and nonallocatable
cases. So this part of patch localizes that check and isolates inside MergeInputSection instead of spreading it to GC code.

In D29170#659009, @ruiu wrote:

Interesting. Is not it the same what you mentioned during review of D28612 ?

"So, the right way of doing it is to set Live bit in the ctor if it should never be GC'ed."

Instead of checking the sections flags everywhere patch relies on Live bit now.

Well, it is not a good idea to follow someone's advice blindly. You wrote this, so what do you think of this patch? I think that is important. I think this is not something I expected, and I believe there's a better way, but that's not this.

I did not follow your advice blindly, I tried that and found that it really reduces amount of changes I need to do for gc-support for emit relocs to single place.
Only because of that and after that I wrote that "it looks a good idea" and honestly I think this patch is very good, at least it IMO definetely makes code much better than it was before.
If it is not what you expected, then I looks I understood you wrong, but it does not change the situation and my opinion about that patch. May be your way you have in mind is better,
I do not know yet as I do not know what you expected :)

What is wrong with this patch ?

Rafael suggested to split D28612 to not support --gc-sections from start. I'll start from that then, though for GC case I believe we need some solution still, this or some another patch.

davide removed a reviewer: davide.Feb 12 2017, 12:31 PM
grimar abandoned this revision.Mar 30 2017, 1:29 AM