This is an archive of the discontinued LLVM Phabricator instance.

[ELF] -r: rewrite SHT_GROUP content if some members are combined or discarded
ClosedPublic

Authored by MaskRay on Jul 19 2020, 12:44 PM.

Details

Summary
  • If two group members are combined, we should leave just one index in the SHT_GROUP content.
  • If a group member is discarded (/DISCARD/ or upcoming -r --gc-sections combination), we should drop its index in the SHT_GROUP content. LLD currently crashes (getOutputSection() is null).

Diff Detail

Event Timeline

MaskRay created this revision.Jul 19 2020, 12:44 PM

GNU ld handles discarded members but does not handle combined members.

MaskRay edited the summary of this revision. (Show Details)Jul 19 2020, 12:46 PM
psmith accepted this revision.Jul 20 2020, 2:58 AM

This looks good to me. Regardless of whether we allow --gc-sections it will be worth getting this right for /DISCARD/. Will be worth waiting to see if there are any further comments from other reviewers.

This revision is now accepted and ready to land.Jul 20 2020, 2:58 AM
grimar added inline comments.Jul 21 2020, 1:44 AM
lld/ELF/OutputSections.cpp
393

I'd suggest

for (uint32_t idx : section->getDataAs<uint32_t>().slice(1))
    if (OutputSection *osec = sections[read32(&idx)]->getOutputSection())
      seen.insert(osec->sectionIndex);

or more explicit, but a bit longer version:

for (uint32_t idx : section->getDataAs<uint32_t>().slice(1))
  if (OutputSection *osec =
          sections[byte_swap(idx, config->endianness)]->getOutputSection())
    seen.insert(osec->sectionIndex);
MaskRay updated this revision to Diff 279541.Jul 21 2020, 8:47 AM
MaskRay marked 2 inline comments as done.

Simplify endianness code with read32

lld/ELF/OutputSections.cpp
393

Thanks.

for (const uint32_t &idx : section->getDataAs<uint32_t>().slice(1))

works.

This revision was automatically updated to reflect the committed changes.