This is an archive of the discontinued LLVM Phabricator instance.

[ELF] --emit-relocs: fix a crash if .rela.dyn is an empty output section
ClosedPublic

Authored by MaskRay on Dec 15 2020, 9:34 PM.

Details

Summary

Fix PR48357: If .rela.dyn appears as an output section description, its type may
be SHT_RELA (due to the empty synthetic .rela.plt) while there is no input
section. The empty .rela.dyn may be retained due to a reference in a linker
script. Don't crash.

Diff Detail

Event Timeline

MaskRay created this revision.Dec 15 2020, 9:34 PM
MaskRay requested review of this revision.Dec 15 2020, 9:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 15 2020, 9:34 PM
MaskRay updated this revision to Diff 312105.Dec 15 2020, 9:40 PM

Improve test

MaskRay retitled this revision from [ELF] --emit-relocs: fix a crash if .rela.dyn is an output section description to [ELF] --emit-relocs: fix a crash if .rela.dyn is an empty output section.Dec 15 2020, 9:42 PM
grimar added inline comments.Dec 16 2020, 12:22 AM
lld/ELF/OutputSections.cpp
406

I wonder if the same crash can happen here with an empty .ARM.exidx?

MaskRay marked an inline comment as done.Dec 16 2020, 12:28 AM
MaskRay added inline comments.
lld/ELF/OutputSections.cpp
406

It can't (I believe flags & SHF_LINK_ORDER ensures there is at least one input section but it is very late for me and I don't think carefully though:( )

There are many arm-exidx-* tests and someone may need to check whether this is missing test coverage.

grimar added inline comments.Dec 16 2020, 1:35 AM
lld/ELF/OutputSections.cpp
406

SHF_LINK_ORDER case seems is fine. We don't keep any special flags for empty output
sections:

// We do not want to keep any special flags for output section
// in case it is empty.
bool isEmpty = (getFirstInputSection(sec) == nullptr);
if (isEmpty)
  sec->flags = flags & ((sec->nonAlloc ? 0 : (uint64_t)SHF_ALLOC) |
                        SHF_WRITE | SHF_EXECINSTR);
grimar accepted this revision.Dec 16 2020, 1:36 AM

LGTM.

This revision is now accepted and ready to land.Dec 16 2020, 1:36 AM
This revision was landed with ongoing or failed builds.Dec 16 2020, 8:59 AM
This revision was automatically updated to reflect the committed changes.
MaskRay marked an inline comment as done.