This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Do not ICF two sections with different output sections when there is a linker script
AbandonedPublic

Authored by MaskRay on Aug 25 2019, 9:53 AM.

Details

Reviewers
espindola
Summary

This complements D47241 for the non-linker-script (getOutputSectionName) case.

This implements the unfold approach as briefed at https://reviews.llvm.org/D54422#1302994

// Do not ICF fold input sections between output sections. If the output
// sections of sec and the InputSection it gets folded into are different,
// unfold it. sec->repl may have increased alignment or be have moved to the
// main partition, but that does not matter.

--print-icf-sections is not handled.

Event Timeline

MaskRay created this revision.Aug 25 2019, 9:53 AM
MaskRay abandoned this revision.Aug 25 2019, 9:54 AM

D66717 should be better

MaskRay updated this revision to Diff 217070.EditedAug 25 2019, 8:06 PM

For the test case linkerscript/icf-different-output-sections.s added in D66717

% ld.lld a.o -T a.x --icf=all --print-icf-sections       
## need more code to make the log messages correct
selected section a.o:(.rodata.foo0)
  removing identical section a.o:(.rodata.foo1)
  removing identical section a.o:(.rodata.bar0) # this will be unfolded
  removing identical section a.o:(.rodata.bar1) # this will be unfolded
selected section a.o:(.text.foo0)
  removing identical section a.o:(.text.foo1)
  removing identical section a.o:(.text.bar0) # this will be unfolded
  removing identical section a.o:(.text.bar1) # this will be unfolded

             VMA              LMA     Size Align Out     In      Symbol
               0                0        1     1 .rodata.foo
               0                0        1     1         a.o:(.rodata.foo0)
               1                1        2     1 .rodata.bar
               1                1        1     1         a.o:(.rodata.bar0)
               2                2        1     1         a.o:(.rodata.bar1) # this was folded into .rodata.foo0, then unfolded, but it can be folded into .rodata.bar0 again
               3                3        1     1 .text.foo
               3                3        1     1         a.o:(.text.foo0)
               4                4        2     1 .text.bar
               4                4        1     1         a.o:(.text.bar0)
               5                5        1     1         a.o:(.text.bar1) # ditto
grimar added a subscriber: grimar.EditedAug 26 2019, 2:02 AM

D66717 should be better

I still need to look at D66717 closer, but I agree, I think this one is not a right approach probably.

Making sections dead and folding them, but then ressurrecting and unfolding looks
tricky: I do not think we have any other place where we set Live bit to
a dead input section (though we can do it for output section in adjustSectionsBeforeSorting).
Doing this seems breaks this part of LLD design and my impression is that we should avoid doing it.

MaskRay abandoned this revision.Sep 2 2019, 4:28 AM