This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Another fix for "LLD crashes with --emit-relocs when trying to proccess .eh_frame"
ClosedPublic

Authored by grimar on Mar 20 2018, 4:48 AM.

Details

Summary

This fixes PR36367 which is about segfault when --emit-relocs is
used together with .eh_frame sections which happens because
of reordering of regular and .rel[a] sections.

Path changes loop that iterates over input sections to create
relocation target sections first.

Diff Detail

Event Timeline

grimar created this revision.Mar 20 2018, 4:48 AM
grimar updated this revision to Diff 139105.Mar 20 2018, 4:50 AM
grimar retitled this revision from [ELF] - Another for "LLD crashes with --emit-relocs when trying to proccess .eh_frame" to [ELF] - Another fix for "LLD crashes with --emit-relocs when trying to proccess .eh_frame".
  • Simplify test case.
espindola added inline comments.Mar 20 2018, 12:43 PM
ELF/LinkerScript.cpp
664

It turns out that we can do this with just one loop.

The requirement that we have is that relocated sections are added before the corresponding section. We can implement that with

+ if ((IS->Type == SHT_REL || IS->Type == SHT_RELA) && !isa<SyntheticSection>(IS))
+ if (auto *Rel = cast<InputSection>(IS)->getRelocatedSection())
+ if (auto *RelIS = dyn_cast_or_null<InputSectionBase>(Rel->Parent))
+ Add(RelIS);
+ Add(IS);

grimar updated this revision to Diff 139268.Mar 21 2018, 3:07 AM
  • Addressed review comment.
ELF/LinkerScript.cpp
664

Such approach is much more test case friendly, thanks.

We use/can use (IS->Type == SHT_REL || IS->Type == SHT_RELA) && !isa<SyntheticSection>(IS)
condition so many times in code that I even think about some kind of helper for that.

This revision is now accepted and ready to land.Mar 22 2018, 3:13 PM
grimar edited the summary of this revision. (Show Details)Mar 23 2018, 2:20 AM
This revision was automatically updated to reflect the committed changes.