This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Add test for relocations with section group
AbandonedPublic

Authored by phosek on Feb 13 2017, 5:45 PM.

Details

Summary

This test is currently triggering a segfault in lld, as reported in:
http://bugs.llvm.org/show_bug.cgi?id=31952

Diff Detail

Repository
rL LLVM

Event Timeline

phosek created this revision.Feb 13 2017, 5:45 PM
ruiu accepted this revision.Feb 13 2017, 5:53 PM

LGTM

Feel free to roll back r294469 and submit this.

This revision is now accepted and ready to land.Feb 13 2017, 5:53 PM

Changing the code in InputFiles.cpp to avoid discarding SHT_GROUP sections in case when we're producing relocatable output fixes the crash. I'd be happy to upload that patch but I'm not 100% sure it's the best possible solution? Alternatively I can revert r294469 like you suggested and let @grimar look into it.

ruiu added a comment.Feb 13 2017, 6:23 PM

I do not really understand the issue yet, so I don't know how to fix this, but the basic rule is that if a change introduced a crash bug, it should be reverted and then re-submitted with a fix.

ruiu added a comment.Feb 13 2017, 6:56 PM

George,

Can you please take a look at this test and fix the issue? Petr tried to revert your change, but since other changes have been made on top of it, it couldn't be reverted cleanly, so we decided to not revert to avoid risk of regression. The crash bug is not super important but needs fixing. Thanks!

grimar edited edge metadata.Feb 14 2017, 2:35 AM
In D29920#675826, @ruiu wrote:

I do not really understand the issue yet, so I don't know how to fix this, but the basic rule is that if a change introduced a crash bug, it should be reverted and then re-submitted with a fix.

That probably would be bad idea to revert it. That is the case when change revealed bug, but not introduced.
Bug is next just in case:

  1. We have 2 object with SHT_GROUP sections foo. So that means "only one of the duplicate groups will be retained by the link-editor, and the members of the remaining groups will be discarded.".
  2. r294469 made the next change. During copyRelocations, it changed calculated offset for relocation from
P->r_offset = RelocatedSection->getOffset(Rel.r_offset);

to

P->r_offset = RelocatedSection->OutSec->Addr + RelocatedSection->getOffset(Rel.r_offset);
  1. And here is a problem RelocatedSection in the place of crash is InputSection<ELFT>::Discarded, because it is the member of one of duplicate groups which was discarded earlier by LLD in ObjectFile<ELFT>::initializeSections().

That way OurSec is null. Previous logic called getOffset of discarded section and did not crash. I believe that also was incorrect. Probably we should place asserts to check that methods of discarded sections are not called.

In D29920#675850, @ruiu wrote:

George,

Can you please take a look at this test and fix the issue? Petr tried to revert your change, but since other changes have been made on top of it, it couldn't be reverted cleanly, so we decided to not revert to avoid risk of regression. The crash bug is not super important but needs fixing. Thanks!

Fix is D29929. Looks caused by GNU as bug.

phosek abandoned this revision.Feb 14 2017, 12:39 PM

This change was merged as part of D29929.