This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Change how we deal with unused synthetic sections.
AbandonedPublic

Authored by grimar on Oct 6 2017, 2:18 AM.

Details

Reviewers
ruiu
rafael
Summary

It turns out our code that handles unused synthetic sections is
a bit overcomplicated.
I think we set output section Live bit too early and do things in
removeUnusedSyntheticSections that we can skip.

I suggest to set Live bit of output section early only if it is
known that it is live. Then we can update this flag after we get
final information about synthetic section status (empty/non-empty).
For input sections that are empty we could just disable them,
setting their Live flag to false.

Approach I am suggesting is implemented in this patch.

Diff Detail

Event Timeline

grimar created this revision.Oct 6 2017, 2:18 AM
davide added a subscriber: davide.Oct 6 2017, 10:39 PM

I'm not sure how I feel about this.
It's true that reduces the number of lines to implement part of this feature.
OTOH, it scatters details that were in a single place into multiple (three, to be precise).
In some sense,it makes following this code harder to read.

grimar added a comment.Oct 7 2017, 6:47 AM

I'm not sure how I feel about this.
It's true that reduces the number of lines to implement part of this feature.
OTOH, it scatters details that were in a single place into multiple (three, to be precise).
In some sense,it makes following this code harder to read.

I understand your concerns.

It was suggested in D38393 thread to design something
different than removeUnusedSynteticSections.
Also there was also discussion about behavior of this function in D37520 thread.

Designing something different anyways requires touching code outside of this method it seems.
We normally rely on Live flag when trying to control whether input or output section be in output.
In this patch I am just trying to be consistent with the rest LLD code.

I have no better ideas how to rework it at this moment. Initially I posted D37520
to fix silly issue we have currently. We could probably just land it for now.

ruiu edited edge metadata.Oct 9 2017, 5:55 PM

I think Live bit is abused in the output sections. That flag was introduced for gc, and originally only input sections have the flag. After that, a new class was introduced as a parent of both input sections and output sections, and at some point, we started using Live bit for output sections to indicate whether we want to emit it or not. But as far as I know, it was not discussed if that is a good approach.

I feel like we should stop using Live bit for output sections. Input sections need that flag because they are gc'ed, but for output sections, we shouldn't create useless output sections in the first place. I feel like the current output sections have too many states and that makes writing code harder.

grimar abandoned this revision.Oct 10 2017, 1:07 AM