This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Do not segfault when using -r and section groups.
ClosedPublic

Authored by grimar on Feb 14 2017, 2:32 AM.

Details

Summary

If we had SHT_GROUP sections, then when -r was used we might crash.
This is PR31952.

Issue happened because we emited relocation section though its target was discared
because was a member of duplicated group.
More details about how issue was revealed available in commens at D29920 page.

Fix was not to create SHT_REL[A] sections for -r when target was discarded.

Testcase based on one from @phosek (D29920).
Interesting that I was not able to create the test without yaml2obj.
But I think I could do that using GNU as.

If we have code below:

.section .text,"axG",@progbits,foo,comdat
.quad bar

Then output using GNU as is.

as test.s -o test.as
readelf -a test.as
COMDAT group section [    1] `.group' [foo] contains 1 sections:
   [Index]    Name
   [    5]   .text

But llvm-as puts .rela section to the group either:

llvm-mc -filetype=obj -triple=x86_64-pc-linux test.s -o test.o
readelf -a test.o
COMDAT group section [    3] `.group' [foo] contains 2 sections:
   [Index]    Name
   [    4]   .text
   [    5]   .rela.text

So GNU as does not put rela section to the group. That why issue happens I believe.
So looks objects created by llvm-as are not affected by issue. Because .rela.text from output above
is discarded as member of duplicated group earlier, when we hande SHT_GROUP in initializeSections().

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Feb 14 2017, 2:32 AM

Thanks for looking into this! Just to confirm your suspicion, this bug was found while using lld to link object files produced by G++ and GNU as.

This revision was automatically updated to reflect the committed changes.