This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Simplify reporting of garbage collected sections.
ClosedPublic

Authored by grimar on Oct 18 2017, 8:26 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Oct 18 2017, 8:26 AM
ruiu edited edge metadata.Oct 18 2017, 12:18 PM

I think I like the direction of this patch.

ELF/LinkerScript.cpp
286 ↗(On Diff #119490)

Question: is it possible that a section is assigned to some output section but is not live? It sounds like a bad state to me.

grimar added inline comments.Oct 19 2017, 5:19 AM
ELF/LinkerScript.cpp
286 ↗(On Diff #119490)

Yes, it is possible for following case:
/DISCARD/ : {*(.text*)}
Here we set Assigned flag for .text. It is probably OK it seems ?

(I would probably try to completely get rid of 'Assigned' flag, I think we should be able to do that).

ruiu added inline comments.Oct 24 2017, 9:28 PM
ELF/LinkerScript.cpp
286 ↗(On Diff #119490)

No, I don't think that is OK. /DISCARD/ is a keyword and not a real section. Sections discarded by /DISCARD/ should be not Assigned and not Live.

grimar added inline comments.Oct 25 2017, 3:38 AM
ELF/LinkerScript.cpp
286 ↗(On Diff #119490)

I think that is fine because specification explicitly mentions that input sections are assigned:

The special output section name ‘/DISCARD/’ may be used to discard input sections. Any
input sections which are assigned to an output section named ‘/DISCARD/’ are not included
in the output file.

(https://sourceware.org/binutils/docs-2.16/ld/Output-Section-Discarding.html)

Anyways I believe nice way to solve this would be to remove Assigned flag,
what should be possible and should be done in different patch.

ruiu added inline comments.Oct 25 2017, 3:04 PM
ELF/LinkerScript.cpp
286 ↗(On Diff #119490)

I don't think that is fine, please read my commit message for r316622. Can you rebase this patch?

grimar updated this revision to Diff 120396.Oct 26 2017, 4:46 AM
  • Rebased.
ELF/LinkerScript.cpp
286 ↗(On Diff #119490)

Rebased, but we still need to check both conditions here:

  1. We need to check that section is not dead, I think it is obvious.
  2. We still need to check that it is not assigned. We could avoid that in theory and check Sec->Parent instead of Sec->Assigned, but it will not work so simple, because we can have script like: SECTIONS {.foo : { *(.foo) *(.foo) } } (input-sec-dup.s) and do not want to add .foo twice. We could assign Sec->Parent to some dummy non-zero value probably and get rid of Assigned, but that is story for another patch.
ruiu accepted this revision.Oct 26 2017, 2:06 PM

LGTM

ELF/MarkLive.cpp
293 ↗(On Diff #120396)

collected -> garbage-collected

This revision is now accepted and ready to land.Oct 26 2017, 2:06 PM
This revision was automatically updated to reflect the committed changes.