This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Do not allow -r to eat comdats.
ClosedPublic

Authored by grimar on May 24 2017, 2:39 AM.

Details

Summary

This is PR33052, "Bug 33052 - -r eats comdats ".

To fix it I stop removing group section from out when -r is given
and fixing SHT_GROUP content when writing it just like we do some
other fixup, e.g. for Rel[a]. (it needs fix for section indices that ar in group).

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.May 24 2017, 2:39 AM
ruiu edited edge metadata.May 24 2017, 11:29 AM

In general, I think we pass through all input sections to an output when the -r option is given. But in this patch you deduplicates comdat groups. Do you need that?

In D33485#763648, @ruiu wrote:

In general, I think we pass through all input sections to an output when the -r option is given. But in this patch you deduplicates comdat groups. Do you need that?

I was need it for relocatable-eh-frame.s

It has next code:

.section .foo,"aG",@progbits,bar,comdat
.cfi_startproc
.cfi_endproc

And uses this file twice with -r:

# RUN: ld.lld -r %t.o %t.o -o %t

Content inside a single object is something like .group (SHT_GROUP) + .foo sections.
Now if we do not do deduplication then 2 .group input sections will be merged into single output .group and
have content like [flag, section index, flag, section index] which is just broken. .foo's will be merged too.
We probably, like Rafael mentioned, can have 2 group sections with same signature and do emit separate sections for .foo's as well,
but deduplication seems much easier solution and itself works as some cheap output optimization.

grimar updated this revision to Diff 100217.May 25 2017, 2:53 AM
  • Addressed review comments.
ruiu added inline comments.May 25 2017, 1:48 PM
ELF/InputFiles.cpp
306 ↗(On Diff #100217)

This needs an explanation.

322 ↗(On Diff #100217)

Format

ELF/InputSection.cpp
302 ↗(On Diff #100217)

Avoid ELFT::Word` in general. You can use read32 instead. You can also remove ELFT from template parameter list if you use Config->Wordsize.

701 ↗(On Diff #100217)

Do not use ELFT::Word.

ELF/InputSection.h
324 ↗(On Diff #100217)

I prefer more specific name -- like copyShtGroup, as Group sounds too generic.

ELF/OutputSections.cpp
129–141 ↗(On Diff #100217)

This is too much details to write in this funciton.

276 ↗(On Diff #100217)

This looks a bit tricky. We should turn off SHF_COMPRESSED when we decompress sections.

grimar updated this revision to Diff 100381.May 26 2017, 3:47 AM
  • Addressed review comments.
ELF/InputFiles.cpp
306 ↗(On Diff #100217)

Done.

322 ↗(On Diff #100217)

It is just formatting in this way :(

ELF/InputSection.cpp
302 ↗(On Diff #100217)

Done. (Not sure why did you mention Config->Wordsize though, all values here are 4 bytes I believe).

701 ↗(On Diff #100217)

Done.

ELF/InputSection.h
324 ↗(On Diff #100217)

Done.

ELF/OutputSections.cpp
129–141 ↗(On Diff #100217)

Done.

276 ↗(On Diff #100217)

May be. This patch just removes SHF_GROUP here.

ruiu added inline comments.May 26 2017, 8:24 AM
ELF/InputFiles.cpp
322 ↗(On Diff #100217)

I think break after } is somewhat irregular. Move break before }.

306–309 ↗(On Diff #100381)

Move it after case SHT_GROUP

ELF/InputSection.cpp
304 ↗(On Diff #100381)

You can remove this temporary variable.

ELF/OutputSections.cpp
122–123 ↗(On Diff #100381)

It took for a while to understand this code. What was confusing is that the first section is not special. It is just that when you pass -r, we create an output section for each input section, so there's always only one section in an output file.

Please add

assert(Config->Relocatable && Sec->Sections.size == 1);

remove First variable and use Sec->Sections[0] directly. This should improve readability.

276 ↗(On Diff #100217)

Please rebase.

grimar updated this revision to Diff 100428.May 26 2017, 10:16 AM
  • Addressed review comments.
ELF/InputFiles.cpp
306–309 ↗(On Diff #100381)

Done.

ELF/InputSection.cpp
304 ↗(On Diff #100381)

Right. Done.

ELF/OutputSections.cpp
122–123 ↗(On Diff #100381)

Done.

ruiu accepted this revision.May 27 2017, 3:07 AM

LGTM

ELF/InputSection.cpp
305 ↗(On Diff #100428)

endianness::native is alarming although it is actually correct. It is better to write

*To++ = From[0];
This revision is now accepted and ready to land.May 27 2017, 3:07 AM
This revision was automatically updated to reflect the committed changes.